This cmd spamming chat - 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)
+--- Thread: This cmd spamming chat (
/showthread.php?tid=336142)
This cmd spamming chat -
Face9000 - 21.04.2012
Hello,i've maked this simple /lock command to lock and unlock cars (just in one cmd),but it spam the chat after i lock or unlock the car.
pawn Код:
CMD:lock(playerid, params[])
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFFFFFAA,"You have to be inside a vehicle.");
for(new i=0; i < MAX_PLAYERS; i++)
{
if(i == playerid) continue;
if(LockVeh[playerid] == false)
{
GameTextForPlayer(playerid, "~r~Vehicle Locked. Use again /lock to unlock it.", 5000, 5);
SendClientMessage(playerid,yellow,"Vehicle locked.Use again /lock to unlock it.");
LockVeh[playerid] = true;
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,0,1);
}else{
GameTextForPlayer(playerid, "~g~Vehicle Unlocked. Use /loc to lock it.", 5000, 5);
SendClientMessage(playerid,yellow,"Vehicle unlocked.Use /lock to lock it.");
LockVeh[playerid] = false;
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,0,0);
}
}
return 1;
}
It spawns "Vehicle unlocked.Use /lock to lock it." and "Vehicle locked.Use again /lock to unlock it."
What's wrong?
Re: This cmd spamming chat -
Richie© - 21.04.2012
SendClientMessage is inside the loop, therefore it spams. Put the SendClientMessage outside of the loop.
if you do it e.g like this, it wont spam:
pawn Код:
CMD:lock(playerid, params[])
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFFFFFAA,"You have to be inside a vehicle.");
if(LockVeh[playerid] == false)
{
GameTextForPlayer(playerid, "~r~Vehicle Locked. Use again /lock to unlock it.", 5000, 5);
SendClientMessage(playerid,yellow,"Vehicle locked.Use again /lock to unlock it.");
LockVeh[playerid] = true;
for(new i=0; i < MAX_PLAYERS; i++)
{
if(i == playerid) continue;
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,0,1);
}
}
}
else
{
GameTextForPlayer(playerid, "~g~Vehicle Unlocked. Use /loc to lock it.", 5000, 5);
SendClientMessage(playerid,yellow,"Vehicle unlocked.Use /lock to lock it.");
LockVeh[playerid] = false;
for(new i=0; i < MAX_PLAYERS; i++)
{
if(i == playerid) continue;
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,0,0);
}
}
}
return 1;
}
Re: This cmd spamming chat -
Face9000 - 21.04.2012
Ah,thanks,+rep.