SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 20/02/2007, 05:31 PM   #31
yom
High-roller
 
Join Date: Jul 2006
Posts: 2,002
Reputation: 6
Default Re: Useful Snippets

Delvour's pawn version :

pawn Code:
public OnGameModeInit()
{
  SetTimer("SendBotMessage",500,1);
  return 1;
}

new BOT_NAME[] = "Delvour";
new ANSWERS_A[][] = {"Yes.","No.","Maybe.","Fuck you!","Who knows...","I don't know.","Whatever.."};
new ANSWERS_B[][] = {"That's not a question.","You don't ask me anything.","I answer to questions."};
new ANSWERS_C[][] = {"I'm busy atm.","Yes?","What?","Zzzz..","Leave me alone!","Do not annoy me."};
new WaitAnswer;
new botmsg[256];

public OnPlayerText(playerid, text[])
{
  new idx = 0;
  botmsg = strsep(text,idx);

  if (!strcmp(botmsg,BOT_NAME,true) && !WaitAnswer)
  {
    botmsg = strsep(text,idx);
    if (text[strlen(text)-1] == '?' && strlen(text) > strlen(BOT_NAME)+4)
    {
      format(botmsg,sizeof(botmsg),"%s",ANSWERS_A[random(sizeof(ANSWERS_A))]);
    }
    else if (text[strlen(text)-1] != '?' && strlen(text) > strlen(BOT_NAME))
    {
      format(botmsg,sizeof(botmsg),"%s",ANSWERS_B[random(sizeof(ANSWERS_B))]);
    }
    else
    {
      format(botmsg,sizeof(botmsg),"%s",ANSWERS_C[random(sizeof(ANSWERS_C))]);
    }
    format(botmsg,sizeof(botmsg),"%s: %s",BOT_NAME,botmsg);
    WaitAnswer = 1;
    return 1;
  }
  return 1;
}

public SendBotMessage()
{
  if (WaitAnswer)
  {
    SendClientMessageToAll(0xFF0000AA,botmsg);
    WaitAnswer = 0;
  }
}

The timer is needed, else it send the message before what you type in the chat

You need 'strsep' and you can find it HERE

Have fun...

ok y_less, corrected.
yom is offline   Reply With Quote
Old 06/03/2007, 11:47 AM   #32
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 78
Reputation: 0
Default Re: Useful Snippets

Blinking Radar Player Icons

This is just a simple script but can be very useful for "highlighting" a player, for instance with a bounty of more than 500,000

Global Variables:

pawn Code:
new bool:blinking[MAX_PLAYERS][2];

In OnGameModeInit

pawn Code:
SetTimer("BlipControl",1000,true);

New Function:

pawn Code:
ToggleBlipBlinking(playerid,bool:toggle) blinking[playerid][0] = toggle;

The Timer function:

pawn Code:
public BlipControl(){
    for(new i=0;i<MAX_PLAYERS;i++){
        if(blinking[i][0] == true){
            if(IsPlayerConnected(i)){
                if(blinking[i][1] == true){
                    ToggleBlipVisibility(i,false);
                    blinking[i][1] = false;
                }
                else{
                    ToggleBlipVisibility(i,true);
                    blinking[i][1] = true;
                }
            }
            else blinking[i][0] = false;
        }
    }
}

Thanks to Simon for his ToggleBlipVisibility function

Speedometer

I made this small speedometer example because people were always bugging me to release the source of one thats easy to put in a gamemode and thats free to use in any script so here it is:

Defines:
pawn Code:
#define MPS             0
#define KMPH            1
#define MPH             2
#define KNOTS           3

#define SPEED           KMPH

Global Variable:
pawn Code:
new Float:ppos[MAX_PLAYERS][3];

In OnGameModeInit
pawn Code:
SetTimer("Speed",1000,true);

And the timer:
pawn Code:
public Speed(){
    for(new i=0;i<MAX_PLAYERS;i++){
        if(IsPlayerConnected(i)){
            new Float:x,Float:y,Float:z;
            GetPlayerPos(i,x,y,z);
            new Float:dis = floatsqroot(floatpower(floatabs(floatsub(ppos[i][0],x)),2)+
            floatpower(floatabs(ppos[i][1],y)),2)+floatpower(floatabs(floatsub(ppos[i][2],z)),2));
            new tmpstr[256];
pawn Code:
#if SPEED == MPS
            format(tmpstr,sizeof(tmpstr),"~n~~n~~n~~n~                  %d~r~MPS",floatround(dis));
            #endif
            #if SPEED == KMPH
            format(tmpstr,sizeof(tmpstr),"~n~~n~~n~~n~                  %d ~r~KMPH",floatround(((dis/1000.0)*60.0)*60.0);
            #endif
            #if SPEED == MPH
            format(tmpstr,sizeof(tmpstr),"~n~~n~~n~~n~                  %d ~r~MPH",floatround(((dis/1000.0)*60.0)*60.0)*(5.0/8.0));
            #endif
            #if SPEED == KNOTS
            format(tmpstr,sizeof(tmpstr),"~n~~n~~n~~n~                  %d ~r~KNOTS",floatround((((dis/1000.0)*60.0)*60.0)/1.85));
            #endif
            if(IsPlayerInAnyVehicle(i)) GameTextForPlayer(i,tmpstr,2000,4);
            ppos[i][0] = x;
            ppos[i][1] = y;
            ppos[i][2] = z;
        }
    }
}
Sacky is offline   Reply With Quote
Old 25/03/2007, 08:49 PM   #33
Pixels^
Gangsta
 
Join Date: Dec 2006
Posts: 845
Reputation: 22
Default Re: Useful Snippets

Just a small code to check if a player has a weapon or not or how many. You will need to replace all your GivePlayerWeapon with GivePlayerWeapon2.
Edit:This snippet will only be useful in 0.1. 0.2 already has a GetPlayerWeapon function.
pawn Code:
stock GivePlayerWeapon2(playerid,weapon,ammo)
{
   Weapon[playerid]++;
   return GivePlayerWeapon(playerid,weapon,ammo);
}
pawn Code:
if(Weapon[playerid]) // if he has a weapon
{
}
else // he doesn't
{
}
pawn Code:
if(Weapon[playerid] >= 2) // 2 or more weapons
{
}
else // less then 2 weapons
{
}
Pixels^ is offline   Reply With Quote
Old 25/03/2007, 11:26 PM   #34
Nitroglycerine
Little Clucker
 
Join Date: Sep 2006
Posts: 40
Reputation: 0
Default Re: Useful Snippets

Quote:
Originally Posted by Pixels^
Just a small code to check if a player has a weapon or not or how many. You will need to replace all your GivePlayerWeapon with GivePlayerWeapon2.
Edit:This snippet will only be useful in 0.1. 0.2 already has a GetPlayerWeapon function.
pawn Code:
stock GivePlayerWeapon2(playerid,weapon,ammo)
{
   Weapon[playerid]++;
   return GivePlayerWeapon(playerid,weapon,ammo);
}
pawn Code:
if(Weapon[playerid]) // if he has a weapon
{
}
else // he doesn't
{
}
pawn Code:
if(Weapon[playerid] >= 2) // 2 or more weapons
{
}
else // less then 2 weapons
{
}
This code only works for the weapons you give to a player through your script, not for the weapons a player might pickup or buy at ammunations.
Nitroglycerine is offline   Reply With Quote
Old 26/03/2007, 01:55 AM   #35
Pixels^
Gangsta
 
Join Date: Dec 2006
Posts: 845
Reputation: 22
Default Re: Useful Snippets

I know that, thats why its a small code.
Pixels^ is offline   Reply With Quote
Old 09/04/2007, 04:03 AM   #36
yom
High-roller
 
Join Date: Jul 2006
Posts: 2,002
Reputation: 6
Default Re: Useful Snippets

A small but effective countdown, by me :


First some variables needed :
pawn Code:
new countdown_seconds,
  countdown_string[40];


Under OnGameModeInit :
pawn Code:
SetTimer("countdown_timer",1000,true);


The dcmd command :
pawn Code:
dcmd_countdown(playerid, param[])
{
  new seconds = strval(param);
   
  if (countdown_seconds)
    SendClientMessage(playerid,0xFF0000FF,"A countdown is already started.");

  else if (seconds < 3 || seconds > 300)
    SendClientMessage(playerid,0xFF0000FF,"You must enter a duration between 3 and 300.");

  else
  {
    format(countdown_string,40,"You started a countdown of %d seconds.",seconds);
    SendClientMessage(playerid,0x00FF00FF,countdown_string);
    countdown_seconds = seconds+1;
  }
   
  return 1;
}


The timer:
pawn Code:
public countdown_timer()
{
  if (countdown_seconds)
  {
    format(countdown_string,6,"~w~%d",countdown_seconds-1);
    GameTextForAll(countdown_string,1100,4);
    SoundForAll(1056);

    countdown_seconds --;

    if (!countdown_seconds)
    {
      GameTextForAll("~r~go !",2000,4);
      SoundForAll(1057);
    }
  }
}


The function i used to play sounds:
pawn Code:
SoundForAll(sound)
{
  for (new i = 0, j = GetMaxPlayers(); i < j; i ++)
    if (IsPlayerConnected(i))
      PlayerPlaySound(i,sound,0.0,0.0,0.0);
}


Thanks for pointing that boylett , i added a min and max limit and changed the order of errors messages.
yom is offline   Reply With Quote
Old 09/04/2007, 08:41 AM   #37
boylett
Gangsta
 
Join Date: Jul 2006
Posts: 652
Reputation: 0
Default Re: Useful Snippets

yom, if I entered /countdown -1, the count down would never stop.

replace
pawn Code:
if (!seconds)
with
pawn Code:
if (seconds < 1)

you can also replace
pawn Code:
if (!countdown_seconds)
with
pawn Code:
if (countdown_seconds < 1)
to keep things even safer.
boylett is offline   Reply With Quote
Old 09/04/2007, 12:20 PM   #38
boylett
Gangsta
 
Join Date: Jul 2006
Posts: 652
Reputation: 0
Default Re: Useful Snippets

Does pawn have a limit on how low it can go?
boylett is offline   Reply With Quote
Old 11/04/2007, 02:57 PM   #39
boylett
Gangsta
 
Join Date: Jul 2006
Posts: 652
Reputation: 0
Default Re: Useful Snippets

Why would you want one without? dcmd is alot faster and easier to read.
boylett is offline   Reply With Quote
Old 11/04/2007, 08:44 PM   #40
-Sneaky-
High-roller
 
Join Date: Jul 2006
Posts: 1,011
Reputation: 24
Default Re: Useful Snippets

Admin roof

Ok i made a admin roof example for the people who want it:

http://pastebin.ca/435115

The admin roof is in san fierro, just change all coords to get it somewhere else

- Sneaky
-Sneaky- is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
READ Usefull Links to snippets and other -Sneaky- Help Archive 5 02/05/2009 12:22 PM


All times are GMT. The time now is 12:29 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.