Useful Snippets
#41

Automatic 1337 speak:

Global Declarations:

pawn Код:
new bool:leet[MAX_PLAYERS];
OnPlayerConnect:

pawn Код:
public OnPlayerConnect(playerid){
    leet[playerid] = false;
}
OnPlayerText:

pawn Код:
public OnPlayerText(playerid,text[]){
    if(leet[playerid]) format(text,MAX_STRING,"%s",StrToHacker(text));
    return 1;
}
OnPlayerCommandText:

pawn Код:
public OnPlayerCommandText(playerid,cmdtext[]){
    dcmd(leet,4,cmdtext);
    return 0;
}
DCMD leet command:

pawn Код:
dcmd_leet(playerid,params[]){
    if(!strlen(params)){
        SendClientMessage(playerid,COLOR_WHITE,"USAGE: /leet [on/off]");
        return 1;
    }
    if(strcmp(params,"on",true) == 0){
        SendClientMessage(playerid,COLOR_RED,"13375P34K Turned On");
        leet[playerid] = true;
        return 1;
    }
    if(strcmp(params,"off",true) == 0){
        SendClientMessage(playerid,COLOR_RED,"13375P34K Turned Off");
        leet[playerid] = false;
        return 1;
    }
    SendClientMessage(playerid,COLOR_WHITE,"USAGE: /leet [on/off]");
    return 1;
}
Requires:

StrToHacker

Can be found in the Useful Functions thread

Credit to Ramjet for the idea
Reply
#42

mhm. I Tested it. it works very well... :P
Reply
#43

Sacky you don't need strtok for this command, compare params
Reply
#44

Corrected, thanks for noticing
Reply
#45

A way to get a player's disconnect reason. May not be advanced, but it's useful.
pawn Код:
new kicked[MAX_PLAYERS];
pawn Код:
#define ban 2
#define kick 1
stock Kick2(playerid)
{
   kicked[playerid] = 1;
   return Kick(playerid);
}
pawn Код:
stock Ban2(playerid)
{
   kicked[playerid] = 2;
   return Ban(playerid);
}
A simple way to test it.
pawn Код:
public OnPlayerDisconnect(playerid)
{
   if(kicked[playerid] == ban)
   {
     //your code
   }
   if(kicked[playerid] == kick)
   {
     //your code
   }
   return 1;
}
OnPlayerScoreChange and OnPlayerGetMoney
Found in my xLog script, but just thought I should post it here.
pawn Код:
SetTimer("CheckMoney",1000,1);
SetTimer("CheckScore",1000,1);
pawn Код:
public CheckMoney()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
      if(M[i] < GetPlayerMoney(i))
      {
        OnPlayerGetMoney(i,GetPlayerMoney(i),M[i]);
      }
      M[i] = GetPlayerMoney(i);
    }
}
pawn Код:
public CheckScore()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
      if(S[i] < GetPlayerScore(i))
      {
        OnPlayerScoreChange(i,GetPlayerScore(i),S[i]);
      }
      S[i] = GetPlayerScore(i);
    }
}
pawn Код:
public OnPlayerGetMoney(playerid,newmoney,oldmoney)
{
    //Do whatever you want when a player gets or loses money
    return 1;
}

public OnPlayerScoreChange(playerid,newscore,oldscore)
{
    //Do whatever you want when a player changes score
    return 1;
}
Reply
#46

1337 Money Grabber.

Description:
This snippet will get a player's money, and if it equals 1337, it will kill the player and decrease their confidence.

Place this under your OnGameModeInit() Callback.
pawn Код:
SetTimer("1337_MoneyCheck", 1000, true);
Now for the Timer :
pawn Код:
public 1337_MoneyCheck()
{
   for(new i; i < MAX_PLAYERS; i++)
   {
     if(IsPlayerConnected(i))
     {
        new cash = GetPlayerMoney(i);
        if(cash == 1337)
        {
           SetPlayerHealth(i, 0.0); // Kills the player.
           SendClientMessage(i, 0x10F441AA, "Not so elite now! xD.");
           ResetPlayerMoney(i); // Sets the player's money back to 0.
        }
     }
   }
}
This script will diminish the quality of your server. I only made it because I was bored and had nothing better to do.

Cheers,
Ramjet.
Reply
#47

I don't see anything useful about it. How about altering it so if the player's name has 1337 characters, then maybe do the resetcash and message?
Reply
#48

Quote:
Originally Posted by Pixels^
I don't see anything useful about it. How about altering it so if the player's name has 1337 characters, then maybe do the resetcash and message?
Surely if it had that many characters in the name, it would get cut off way before it was 1337 in length :S
Reply
#49

Well, I lol'd at the prospect, seems a bit silly though.

Reply
#50

Quote:
Originally Posted by Pixels^
I don't see anything useful about it.
But it maybe to psychotic server owners. TBH I dont care if it is of no use to you, but there is people that may actually want something as lame as this in there scripts (these people have problems).

Quote:
Originally Posted by [RP
Jolteon ]
Well, I lol'd at the prospect, seems a bit silly though.
Damn straight .

Quote:
Originally Posted by Ramjet:SU
I only made it because I was bored and had nothing better to do.
I also felt that there needed to be more randoms snippets out there; there are ludicrous idiots that do want these retarded snippets, but don't have a clue what they are doing; not that making timers are hard; but thats the point.

Quote:
Originally Posted by Pixels^
How about altering it so if the player's name has 1337 characters, then maybe do the resetcash and message?
Does SA-MP have a SetPlayerName() native? No!

The only way this could be plausible is to make a 3rd party program for the samp-server.exe and edit the PlayerName address, and use playerid offsets (0xA80.

Cheers,
Ramjet.
Reply
#51

Jail.

/jail ID (TIME REASON)

If the time you input is 0 (or less), it will put them in jail until they leave the server.

Jails on respawn. In this example it puts you in the blocked off part in Ammunation .

http://usefulsnippets.pastebin.co.uk/14166
Reply
#52

2 loops in 1
This lets you do the same thing 2 loops would do, except in only 1 loop, and both the loops have a different number of loops to do.

MAX_PLAYERS = 100.
MAX_BLAH = 50.

pawn Код:
new i;
while((i < MAX_BLAH) || (i < MAX_PLAYERS)) // smaller the MAX_BLAH or MAX_PLAYERS
{
  if(i < MAX_BLAH) Something[i] = 0; // if i is smaller then MAX_BLAH only
  if(i < MAX_PLAYERS) Other[i] = false; // if i is smaller then MAX_PLAYERS only
  i++; // increase i to do next loop(s)
}
So that will only use 1 loop but can change arrays of different lengths.

Its more effecient then:
pawn Код:
for(new i; i < MAX_PLAYERS; i++) Other[i] = false;
for(new i; i < MAX_BLAH; i++) Something[i] = 0;
You can also do it for any amount of loops you want.
pawn Код:
while((i < MAX_BLAH) || (i < MAX_PLAYERS) || (i < MAX_PIE))
{
  if(i < MAX_BLAH) Something[i] = 0;
  if(i < MAX_PLAYERS) Other[i] = false;
  if(i < MAX_PIE) pies -= 90;
  i++;
}
Reply
#53

Its the idea that you dont have to loop twice.
With 2 loops you go 1, 2, 3,... 1, 2, 3... but with one you just go 1, 2, 3... once so it takes less time.
Reply
#54

A taste of modifying Pawn to be more like VB, for the VB programmers out there who find it hard to adjust:

Using defines we can change the way if() works

pawn Код:
#define If if(
#define Then ){
#define EndIf }
#define Else }else{
So now we can do stuff like this:

pawn Код:
new bool:t = true;
If t == true Then
    //Do somethng
Else
  // Do Something else
EndIf
Big question: Does anyone know how to make defines work for 2 words at once, for instance if i wanted to use something like this:

Dim %1 As Integer

If that can be read by a define then it could become

new %1;

But lets say we wanted to do a float, then thats:

Dim %1 As Float

would become:

new Float:%1;

and i don't know how to accodomate that?
Reply
#55

I hope this is what you want, this seems to work (read notes below though).

pawn Код:
#define Dim%1As%2Integer  new %1;

#include <a_samp>

main() {
    Dim ja As Integer
   
    ja = 3;
   
    printf("%d", ja);
}
The only problem is that if I wanted to make a As Float version, it complains about re-definition .. .

You may find this of interest, but I was unable to find out how it works or if it's doing what I'd like it to do..

Quote:
Originally Posted by Page 95, pawn-lang.pdf
There may be no space characters in the pattern. If you must match a space,
you need to use the "\32;" escape sequence. The substitution text, on the
other hand, may contain space characters. Due to the matching rules of
the macro pattern (explained below), matching a space character is rarely
needed.
Reply
#56

Using that throws a ton of errors my way

pawn Код:
new bool:t = true;
    If t == true Then
        Dim Test As Integer
        Test = 3;
    Else
      // Do Something else
    End If
Using your Dim define

Also no matter how hard i try i cannot get the \32 escape character to work in defines
Reply
#57

Quote:
Originally Posted by Sacky
Using that throws a ton of errors my way

pawn Код:
new bool:t = true;
    If t == true Then
        Dim Test As Integer
        Test = 3;
    Else
      // Do Something else
    End If
Using your Dim define

Also no matter how hard i try i cannot get the \32 escape character to work in defines
It's crashing because you have a space in your "EndIf" ("End If"). Making your last line.. "} if(", your code with the macro definitions above compile fine on my compiler except for a warning: warning 204: symbol is assigned a value that is never used: "Test"
Reply
#58

Your absolutely right! I'm sorry i was so blind about that, well thats one hurdle crossed thanks to Simon
Reply
#59

Quote:
Originally Posted by Pixels^
It's for people who want to make their own CommandText identifiers.
Yeah I understood what it does man, it's just I don't get the point of it. It's just adding a bunch of code to your script that doesn't need to be there IMHO.

Regards

Donny
Reply
#60

Quote:
Originally Posted by Pixels^
Then you would need if(strcmp(cmdtext, "bla", true) == 0) instead of if(strcmp(cmdtext, "/bla", true) == 0) wouldn't you?
pawn Код:
if(text[0] == '!')
{
  text[0] = '/';
  OnPlayerCommandText(playerid,text);
  return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)