SA-MP Forums Archive
Useful Snippets - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: Useful Snippets (/showthread.php?tid=281)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30


Re: Useful Snippets - ғαιιοцт - 05.03.2009

Quote:
Originally Posted by NigNog1
I find that hard to beleive that you successfully tested it. It still won't work.

hmm it should work
I don't see anything wrong


Re: Useful Snippets - MenaceX^ - 05.03.2009

My code is shorter and it does the same effect, also it doesn't have bugs.
pawn Code:
RPName(playerid)
{
  new n[24];
  GetPlayerName(playerid,n,24);
  for(new i=0;i<strlen(n);i++)
  if(n[i]=='_') n[i]=' ';
  return n;
}
I don't see any point in using yours instead of mine.


Re: Useful Snippets - Nubotron - 05.03.2009

You maybe want to know that shorter isn't always better...and your code is like, 3 times slower (just a guess) that *****'s one. If you care more about code beauty than efficiency, stop scripting already! You can have efficient and beautyfull code but you should never sacrifice speed or memory usage.

Just a question: have you read ***** post fully or just first line?

And just so you know, *****'s code is even shorter than yours, once you remove it's brackets.


Re: Useful Snippets - ғαιιοцт - 05.03.2009

Quote:
Code:
RPName(playerid)
{
	new
		n[MAX_PLAYER_NAME],
		i = -1;
	GetPlayerName(playerid, n, MAX_PLAYER_NAME);
	for (new i = 0, j = strlen(n); i < j; i++)
	{
		if (n[i] == '_')
		{
			n[i] = ' ';
		}
	}
	return n;
}

// native function
strlen(const str[])
{
	new
		i = 0;
	while (str[i])
	{
		i++;
	}
	return i;
}
why create "i" twice?


******* - Zoopaman - 11.03.2009

Yay I finally have done it! Inspired by this, I made a *******-style PM system (but you can actually make a real SA:MP ******* with this )

Syntax: "@name/id message" or "@ name/id message" - both work (I haven't tested it with names w/ spaces tho).

Ok I hope I don't miss a part of the code :P And pls don't dis this code because even I'm quite surprised it works, since it came to me while daydreaming :P

So here we go.
Above all:
pawn Code:
forward OnPlayerAtCmd(playerid, cmdtext[]);
in OnPlayerText:
pawn Code:
if(text[0] == '@') {OnPlayerAtCmd(playerid, text[1]); return 0;}
out of callbacks:
pawn Code:
public OnPlayerAtCmd(playerid, cmdtext[])
{
    new idx;
    new string[128];
    new sendername[MAX_PLAYER_NAME];
    new giveplayer[MAX_PLAYER_NAME];
    new cmd[128];
    new tmp[128];
    new giveplayerid;
    cmd[idx] = cmdtext[0]; // this is important - it's what lets you *not* have the whole command and enter the name right after '@'
//The rest except the one above line is pretty much usual PM stuff. This sample is from GodFather (sorry, haters :))
//Also, I'm not sure, but I think that [idx] and [0] can be different. I tried replacing [0] with [1] and [2], but no change whatsoever.
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp))
    {
        SendClientMessage(playerid, COL_HELP, "USAGE: @[Player ID/Name] [Message]");
        return 1;
    }
    giveplayerid = ReturnUser(tmp);
    if (IsPlayerConnected(giveplayerid))
    {
        GetPlayerName(playerid, sendername, sizeof(sendername));
        GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' '))
        {
            idx++;
        }
        new offset = idx;
        new result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
        {
            result[idx - offset] = cmdtext[idx];
            idx++;
        }
        result[idx - offset] = EOS;
        if(!strlen(result))
        {
            SendClientMessage(playerid, COL_HELP, "USAGE: @[Player ID/Name] [Message]");
            return 1;
        }
        format(string, sizeof(string), "New reply from %s (ID: %d): '%s'", sendername, playerid, (result));
        SendClientMessage(giveplayerid, COL_REPLY, string);
        return 1;
    } else {
        SendClientMessage(giveplayerid, COL_ERROR, "Recipient not online");
    }
    return 1;
}
Feel free to use it and add parameters and IsPlayerConnected's and whatever


Re: Useful Snippets - ICECOLDKILLAK8 - 11.03.2009

Names with spaces get cut in SA:MP AFAIK e.g. "Hai Dere" would become "Hai" i think


Re: Useful Snippets - MenaceX^ - 11.03.2009

SendDeathMessage was made by ******?


Re: Useful Snippets - FrazZ - 12.03.2009

yea, according to everyone :P


Re: Useful Snippets - LarzI - 12.03.2009

Don't wanna be harsh, but I hope you know that ****** was one of the devs?


Re: Useful Snippets - MenaceX^ - 12.03.2009

Quote:
Originally Posted by lrZ^
Don't wanna be harsh, but I hope you know that ****** was one of the devs?
Yes I know and I knew it -__-
I just didn't know he made the SendDeathMessage.


Re: Useful Snippets - Zoopaman - 13.03.2009

and you're trying to tell that /pm name msg is easier and faster and overall better to use than @name msg?


Re: Useful Snippets - FrazZ - 13.03.2009

Pretty much.


Re: Useful Snippets - Pyrokid - 13.03.2009

I'm not 100% sure this would work, but it should. Maybe you could do receiverid = ReturnUser in OnPlayerPrivmsg (using the function of course) and get the same result as the ******* with a lot less code.


Re: Useful Snippets - Zoopaman - 13.03.2009

basically the only piece of code is "cmd[idx] = cmdtext[0];" - everything else is just the PM mechanism included in the gamemode


Re: Useful Snippets - Selluliitti_mies - 22.03.2009

This is easy way stop DDB
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  new currentState = GetPlayerState(playerid);
	if(IsPlayerInAnyVehicle(playerid) && currentState == PLAYER_STATE_DRIVER) {
	if(newkeys & KEY_FIRE)
	{
	if(newkeys & KEY_LOOK_RIGHT)
	{
	GameTextForPlayer(playerid, "Don't DDB!", 5000, 5);
	TogglePlayerControllable(playerid,0);
	}else if(newkeys & KEY_LOOK_LEFT)
	{
	GameTextForPlayer(playerid, "Don't DDB!", 5000, 5);
	TogglePlayerControllable(playerid,0);
	}
	}
	}
	if(oldkeys & KEY_FIRE) {
	if(oldkeys & KEY_LOOK_RIGHT)
	{
	TogglePlayerControllable(playerid,1);
	}else if(oldkeys & KEY_LOOK_LEFT)
	{
	TogglePlayerControllable(playerid,1);
	}
	}
}



Re: Useful Snippets - Danut - 23.03.2009

or if he kill with Drive-By



pawn Код:
//OnPlayerDeath

   if(killerid != 255)
   {
        if(GetPlayerState(killerid) == 2 || GetPlayerState(killerid) == 3)
        {
          if(ProxDetectorS(30, killerid, playerid))
          {
            if(!IsPlayerInAnyVehicle(playerid))
            {
              GetPlayerName(killerid,killer,sizeof(killer));
              format(string,sizeof(string),"%s has been kicked. Reason: DriveBy Kill.",killer);
              SendClientMessageToAll(KICK_COLOR,string);
             SendClientMessage(killerid, KICK_COLOR, "You have been kicked. Reason: DriveBy Kill.");
             Kick(killerid);
             return 1;
            }
          }
        }
  }



Re: Useful Snippets - Rks25 - 24.03.2009

This wont compile MoroJr
I for example hadn't definded ProxDetectorS and string... so that gave me 2 errors.
Not forget to define everything.


Re: Useful Snippets - luby - 26.03.2009

Код:
public OnPlayerUpdate(playerid){
	SetPlayerColor(playerid, random(0xFFFFFFFF));
	return true;
}
Random colors


Re: Useful Snippets - MenaceX^ - 26.03.2009

Quote:
Originally Posted by Luby
Код:
public OnPlayerUpdate(playerid){
	SetPlayerColor(playerid, random(0xFFFFFFFF));
	return true;
}
Random colors
Won't work.


Re: Useful Snippets - luby - 26.03.2009

Quote:
Originally Posted by MenaceX^
Quote:
Originally Posted by Luby
Код:
public OnPlayerUpdate(playerid){
	SetPlayerColor(playerid, random(0xFFFFFFFF));
	return true;
}
Random colors
Won't work.
Works for me.