Useful Snippets

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
Reply

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.
Reply

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.
Reply

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?
Reply

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
Reply

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

SendDeathMessage was made by ******?
Reply

yea, according to everyone :P
Reply

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

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.
Reply

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

Pretty much.
Reply

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.
Reply

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

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);
	}
	}
}
Reply

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;
            }
          }
        }
  }
Reply

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

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

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

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.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)