31.08.2011, 20:31
I wanted to know how I can script a /me cmd like the ones in an RP server, i would appreciate a tutorial or a detailed post Thank you
if(strcmp(cmd, "/me", true) == 0)
{
if(IsPlayerConnected(playerid))
{
GetPlayerName(playerid, sendername, sizeof(sendername));
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, COLOR_GRAD2, "USAGE: /me [action]");
return 1;
}
format(string, sizeof(string), "* %s %s", sendername, result);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
printf("%s", string);
}
return 1;
}
if(strcmp(cmdtext,"/me",true,3)== 0)
{
if ( cmdtext[ 3 ] != ' ' || !cmdtext[ 4 ] )
return SendClientMessage( playerid, -1, "USAGE: /me (action)" );
new pName[MAX_PLAYER_NAME],string[128];
GetPlayerName(playerid,pName,sizeof(pName));
format(string,sizeof(string),"**%s%s.",pName,cmdtext[3]);
SendClientMessageToAll(0xFFFFFFFF,string);
return 1;
}
pawn Код:
|
CMD:me(playerid, params[])
{
new action[256], string[256], name[24], Float:x, Float:y, Float:z;
if(sscanf(params, "s[256]", action))
{
SendClientMessage(playerid, COLOR, "USAGE: /me [action]");
}
else
{
GetPlayerName(playerid, name, 24);
GetPlayerPos(playerid, x, y, z);
format(string, 256, "* %s %s *", name, action);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 10, x, y, z))
{
SendClientMessage(i, COLOR, string);
}
}
}
return 1;
}
I recommend using sscanf and zcmd. The way you could do this with these is....
PHP код:
|