24.06.2010, 08:33
How to do these RP commands (/me /do)?
And an example scrip please
Thanks
And an example scrip please
Thanks
if(strcmp(cmd, "/me", true) == 0) { if(IsPlayerConnected(playerid)) { if(gPlayerLogged[playerid] == 0) { SendClientMessage(playerid, COLOR_GREY, " You havent logged in yet !"); return 1; } 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; } if(PlayerInfo[playerid][pMaskuse] == 1) { format(string, sizeof(string), "* Stranger %s", result); } else { 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(cmd, "/do", true) == 0) { if(IsPlayerConnected(playerid)) { if(gPlayerLogged[playerid] == 0) { SendClientMessage(playerid, COLOR_GREY, " You havent logged in yet !"); return 1; } 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: /do [action]"); return 1; } if(PlayerInfo[playerid][pMaskuse] == 1) { format(string, sizeof(string), "* %s (( Stranger ))", result); } else { format(string, sizeof(string), "* %s (( %s ))", result, sendername); } ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE); printf("%s", string); } return 1; }
COMMAND:me(playerid, params[])
{
new text[128], string[128];
if(sscanf(params, "s[127]", text)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /me [action]");
format(string, sizeof(string), "** %s %s", RemoveUnderScore(playerid), text);
NewProx(playerid, 0xC688D4AA, string, 30.0);
return 1;
}
COMMAND:do(playerid, params[])
{
new text[128], string[128];
if(sscanf(params, "s[127]", text)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /do [action]");
format(string, sizeof(string), "** %s (( %s ))", text, RemoveUnderScore(playerid));
NewProx(playerid, 0xC688D4AA, string, 30.0);
return 1;
}
// This is used to send the message only to nearby players.
stock NewProx(playerid, color, string[], Float:radi)
{
new Float:pposx, Float:pposy, Float:pposz;
new Float:oldpposx, Float:oldpposy, Float:oldpposz;
new Float:temppposx, Float:temppposy, Float:temppposz;
GetPlayerPos(playerid, oldpposx, oldpposy, oldpposz);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
{
GetPlayerPos(i, pposx, pposy, pposz);
temppposx = (oldpposx -pposx);
temppposy = (oldpposy -pposy);
temppposz = (oldpposz -pposz);
if (((temppposx < radi) && (temppposx > -radi)) && ((temppposy < radi) && (temppposy > -radi)) && ((temppposz < radi) && (temppposz > -radi)))
{
SendClientMessage(i, color, string);
}
}
}
return 1;
}
// This will save you a lot of code, formats a "rp name" out of a playerid.
stock RemoveUnderScore(playerid)
{
new namewithoutunderscorename[MAX_PLAYER_NAME];
GetPlayerName(playerid,namewithoutunderscorename,sizeof(namewithoutunderscorename));
for(new i = 0; i < MAX_PLAYER_NAME; i++)
{
if(namewithoutunderscorename[i] == '_') namewithoutunderscorename[i] = ' ';
}
return namewithoutunderscorename;
}
//----------------------------------[ME]-----------------------------------------------
if(strcmp(cmd, "/me", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(gPlayerLogged[playerid] == 0)
{
SendClientMessage(playerid, COLOR_GREY, " You havent logged in yet !");
return 1;
}
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;
}
if(PlayerInfo[playerid][pMaskuse] == 1)
{
format(string, sizeof(string), "* Stranger %s", result);
}
else
{
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;
}
//----------------------------------[Do]-----------------------------------------------
if(strcmp(cmd, "/do", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(gPlayerLogged[playerid] == 0)
{
SendClientMessage(playerid, COLOR_GREY, " You havent logged in yet !");
return 1;
}
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: /do [action]");
return 1;
}
if(PlayerInfo[playerid][pMaskuse] == 1)
{
format(string, sizeof(string), "* %s (( Stranger ))", result);
}
else
{
format(string, sizeof(string), "* %s (( %s ))", result, sendername);
}
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)) // 3 is the length of /me
{
if(!cmdtext[3])return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /me [action]");
new str[128];
GetPlayerName(playerid, str, sizeof(str));
format(str, sizeof(str), "* %s %s", str, cmdtext[4]);
SendClientMessageToAll(0xFFFF00AA, str);
return 1;
}
if(!strcmp(cmdtext, "/do", true, 3)) // 3 is the length of /me
{
if(!cmdtext[3])return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /do [action]");
new str[128];
GetPlayerName(playerid, str, sizeof(str));
format(str, sizeof(str), "* %s (( %s ))", str, cmdtext[4]);
SendClientMessageToAll(0xFFFF00AA, str);
return 1;
}
CMD:me( playerid, params[ ] ) {
new string[ 128 ], pName[ 24 ]; GetPlayerName( playerid, pName, 24 );
format( string, sizeof string, "%s %s", pName, params ); return SendClientMessageToAll( 0xAAAAAA, string ); // change the color
}