SA-MP Forums Archive
protect command - 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: protect command (/showthread.php?tid=561016)



protect command - s3ek - 31.01.2015

i want to add protection anti spam to this command Like : You must wait 5 seconds before using /pgoto again


Код:
CMD:pgoto(playerid,params[])
{
   if(PlayerInfo[playerid][LoggedIn] == 0) {
       SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: You need to be registered to access this command");
   return 1;
}
   new teleid;
   if(sscanf(params,"u",teleid)) return SendClientMessage(playerid, red, "Usage:/pgoto [playerid]");
   if(!IsPlayerConnected(teleid)) return SendClientMessage(playerid, red, "Player is not connected");
   if(teleid == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "This isn't a valid player ID");
   if(tele[teleid]==1) return SendClientMessage(playerid, red, "Player has not enabled tele command");
   new Float:telex,Float:teley,Float:telez,int;
   GetPlayerPos(teleid,telex,teley,telez);
   int = GetPlayerInterior(teleid);
   if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  {
   new vid = GetPlayerVehicleID(playerid);
   SetVehiclePos(vid, telex, teley, telez+1);
   LinkVehicleToInterior(vid, int);
  }
  else
  {
   SetPlayerPos(playerid,telex,teley,telez+1);
   SetPlayerInterior(playerid,int);
  }
   return 1;
}



Re: protect command - zPain - 31.01.2015

pawn Код:
new last_pgoto[MAX_PLAYERS];

// inside the command
// under the logged in check
if((gettime() - last_pgoto[playerid]) < 5)
    return SendClientMessage(playerid, -1, "wait");

// above return line
last_pgoto[playerid] = gettime();



Re: protect command - s3ek - 31.01.2015

not work , what The correct code ?
Quote:

CMDgoto(playerid,params[])
{
if(PlayerInfo[playerid][LoggedIn] == 0) {
SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: You need to be registered to access this command");
return 1;
}
new teleid;
if(sscanf(params,"u",teleid)) return SendClientMessage(playerid, red, "Usage:/pgoto [playerid]");
if(!IsPlayerConnected(teleid)) return SendClientMessage(playerid, red, "Player is not connected");
if(teleid == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "This isn't a valid player ID");
if(tele[teleid]==1) return SendClientMessage(playerid, red, "Player has not enabled tele command");
new Float:telex,Float:teley,Float:telez,int;
GetPlayerPos(teleid,telex,teley,telez);
int = GetPlayerInterior(teleid);
new last_pgoto[MAX_PLAYERS];
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new vid = GetPlayerVehicleID(playerid);
SetVehiclePos(vid, telex, teley, telez+1);
LinkVehicleToInterior(vid, int);
if((gettime() - last_pgoto[playerid]) < 5)
return SendClientMessage(playerid, -1, "wait");
}
else
{
SetPlayerPos(playerid,telex,teley,telez+1);
SetPlayerInterior(playerid,int);
}
last_pgoto[playerid] = gettime();
return 1;
}




Re: protect command - zPain - 01.02.2015

last_pgoto must be declared as a global variable.

pawn Код:
new last_pgoto[MAX_PLAYERS];

CMD:pgoto(playerid,params[]) {
    if(PlayerInfo[playerid][LoggedIn] == 0) {
        SendClientMessage(playerid, COLOR_BRIGHTRED, "ERROR: You need to be registered to access this command");
        return 1;
    }

    if((gettime() - last_pgoto[playerid]) < 5) {
        SendClientMessage(playerid, COLOR_BRIGHTRED, "Error: You must wait 5 seconds before using this command again.");
        return 1;
    }

    new teleid;
    if(sscanf(params,"u",teleid)) {
        return SendClientMessage(playerid, red, "Usage:/pgoto [playerid]");
    }

    if(!IsPlayerConnected(teleid)) {
        return SendClientMessage(playerid, red, "Player is not connected");
    }

    if(teleid == INVALID_PLAYER_ID) {
        return SendClientMessage(playerid, red, "This isn't a valid player ID");
    }
   
    if(tele[teleid]==1) {
        return SendClientMessage(playerid, red, "Player has not enabled tele command");
    }

    new Float:telex,Float:teley,Float:telez,int;
    GetPlayerPos(teleid,telex,teley,telez);
    int = GetPlayerInterior(teleid);

    if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) {
        new vid = GetPlayerVehicleID(playerid);
        SetVehiclePos(vid, telex, teley, telez+1);
        LinkVehicleToInterior(vid, int);
    }

    else {
        SetPlayerPos(playerid,telex,teley,telez+1);
        SetPlayerInterior(playerid,int);
    }

    last_pgoto[playerid] = gettime();
    return 1;
}



Re: protect command - s3ek - 01.02.2015

good, Greetings to you thanks you (y)