Help plz - 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: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help plz (
/showthread.php?tid=87256)
Help plz -
cloud9 - 19.07.2009
I just made a command to some thing when an admin type /async playerid or part of name.
But the command works fine with playerid, when ever i use a name or part of it, it just does the command to id 0. can some one help to fix it
pawn Код:
new cmd[256];
new idx;
cmd = strtok(cmdtext, idx);
new tmp[256];
new giveplayer[MAX_PLAYER_NAME];
new sendername[MAX_PLAYER_NAME];
if(strcmp(cmd, "/async", true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /async [playerid/PartOfName]");
return 1;
}
new playa;
if(IsStringAName(tmp))
{
playa = GetPlayerID(tmp);
}
else
{
playa = strval(tmp);
}
GetPlayerName(playa, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
if(GetAdminLevel(playerid) >= 2)
{
if(GetPlayerState(playa) == 9|| GetPlayerState(playa) == 5 || GetPlayerState(playa) == 6 ||GetPlayerState(playa) == 4|| GetPlayerState(playa) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW," Unable to start synchronization");
return 1;
}
if(IsPlayerInAnyVehicle(playa))
{
SendClientMessage(playerid,COLOR_YELLOW," Unable to start synchronization while in a vehicle");
return 1;
}
new string1[128];
new string2[128];
sync[playa] = 1;
SyncPlayer(playa);
format(string1, sizeof(string1), "%s has synced you",sendername);
format(string2, sizeof(string2), "You have synced %s",giveplayer);
SendClientMessage(playa, COLOR_WHITE, string1);
SendClientMessage(playerid, COLOR_WHITE, string2 );
}
else
{
SendClientMessage(playerid, COLOR_YELLOW,"You are not authorized to use this command!");
}
return 1;
}
and the function for it are
pawn Код:
forward GetPlayerID(string[]);
public GetPlayerID(string[])
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) == 1)
{
new testname[MAX_PLAYER_NAME];
GetPlayerName(i, testname, sizeof(testname));
if(strcmp(testname, string, true, strlen(string)) == 0)
{
return i;
}
}
}
return INVALID_PLAYER_ID;
}
forward IsStringAName(string[]);
public IsStringAName(string[])
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) == 1)
{
new testname[MAX_PLAYER_NAME];
GetPlayerName(i, testname, sizeof(testname));
if(strcmp(testname, string, true, strlen(string)) == 0)
{
return 1;
}
}
}
return 0;
}
Re: Help plz -
cloud9 - 19.07.2009
then i used this dcmd one, this also didnt work
pawn Код:
dcmd_async(playerid, params[])
{
new targetid, string1[128], string2[128];
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "Usage: /kick [playerid/partofname]");
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "Player not connected!");
if(GetAdminLevel(playerid) >= 2)
{
if(GetPlayerState(targetid) == 9|| GetPlayerState(targetid) == 5 || GetPlayerState(targetid) == 6 ||GetPlayerState(targetid) == 4|| GetPlayerState(targetid) == 0)
{
SendClientMessage(playerid,COLOR_YELLOW," Unable to start synchronization");
return 1;
}
if(IsPlayerInAnyVehicle(targetid))
{
SendClientMessage(playerid,COLOR_YELLOW," Unable to start synchronization while in a vehicle");
return 1;
}
new targetplayer[MAX_PLAYER_NAME];
new adminplayer[MAX_PLAYER_NAME];
GetPlayerName(targetid, targetplayer, sizeof(targetplayer));
GetPlayerName(playerid, adminplayer, sizeof(adminplayer));
sync[targetid] = 1;
SyncPlayer(targetid);
format(string1, sizeof(string1), "You have been Synced by %s!",adminplayer);
SendClientMessage(targetid,COLOR_YELLOW, string1);
format(string2, sizeof(string2), "You have Synced %s!",targetplayer);
SendClientMessage(playerid,COLOR_YELLOW,string2);
return 1;
}
else
{
SendClientMessage(playerid,COLOR_YELLOW,"You must be level 2 to use this command");
}
return 1;
}