This cmd spamming chat
#1

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

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

Ah,thanks,+rep.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)