Cuff release timer
#1

So I want this to happen; after I cuff someone, that player should be free to move again after 20 seconds.

This is the code:
Код:
CMD:cuff(playerid, params[])
{
    new ID; new pname[24]; new opname[24]; new string[200];
    if(!IsPlayerACop(playerid)) return SendClientMessage(playerid, COLOR_RED,"You are not a law enforcement.");
	if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You cannot use this command in a vehicle.");
	if(sscanf(params, "u", ID)) return SendClientMessage(playerid, COLOR_RED, "Usage: /cuff (ID)");
	if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, COLOR_RED, "Invalid ID.");
	GetPlayerName(ID, opname, 24); GetPlayerName(playerid, pname, 24);
	if(GetDistanceBetweenPlayers(playerid, ID) > 3) return SendClientMessage(playerid, COLOR_RED, "That player is too far away to be cuffed.");
	if(IsPlayerInAnyVehicle(ID)) return SendClientMessage(playerid, COLOR_RED, "That player is in a vehicle. You cannot cuff him.");
	if(IsPlayerACop(playerid)) return SendClientMessage(playerid, COLOR_RED, "You cannot cuff other Law Enforcements.");
	TogglePlayerControllable(ID, 0);
	GameTextForPlayer(ID, "~b~HANDCUFFED!", 5000, 1);
	format(string, sizeof(string), "[POLICE] Officer %s(%d) has put hand cuffs on you. You cannot move.", pname, playerid);
	SendClientMessage(ID, COLOR_LIGHTBLUE, string);
	format(string, 200, "[DISPATCH] Officer %s(%d) has cuffed player %s(%d)", pname, playerid, opname, ID);
	
	SendClientMessage(playerid, COLOR_LIGHTBLUE, "[POLICE] You have cuffed a suspect. You have 30 seconds before they get uncuffed.");
I want to make the TogglePlayerControllable(ID,1) after 20 seconds when someone get cuffed. How should I do this?
Please help, reputation will be given.
Reply
#2

u want someone cuff & after 20 sec he got automatically uncuff ? like that ?
Reply
#3

hmm , try this
pawn Код:
public OnGameModeInit()
{
    SetTimer("UnCuff", 20000, true);
    return 1;
}

CMD:cuff(playerid, params[])
{
    new ID, pname[24]; new opname[24]; new string[200];
    if(!IsPlayerACop(playerid)) return SendClientMessage(playerid, COLOR_RED,"You are not a law enforcement.");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You cannot use this command in a vehicle.");
    if(sscanf(params, "u", ID)) return SendClientMessage(playerid, COLOR_RED, "Usage: /cuff (ID)");
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, COLOR_RED, "Invalid ID.");
    GetPlayerName(ID, opname, 24); GetPlayerName(playerid, pname, 24);
    if(GetDistanceBetweenPlayers(playerid, ID) > 3) return SendClientMessage(playerid, COLOR_RED, "That player is too far away to be cuffed.");
    if(IsPlayerInAnyVehicle(ID)) return SendClientMessage(playerid, COLOR_RED, "That player is in a vehicle. You cannot cuff him.");
    if(IsPlayerACop(playerid)) return SendClientMessage(playerid, COLOR_RED, "You cannot cuff other Law Enforcements.");
    TogglePlayerControllable(ID, 1);
    GameTextForPlayer(ID, "~b~HANDCUFFED!", 5000, 1);
    format(string, sizeof(string), "[POLICE] Officer %s(%d) has put hand cuffs on you. You cannot move.", pname, playerid);
    SendClientMessage(ID, COLOR_LIGHTBLUE, string);
    format(string, 200, "[DISPATCH] Officer %s(%d) has cuffed player %s(%d)", pname, playerid, opname, ID);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "[POLICE] You have cuffed a suspect. You have 30 seconds before they get uncuffed.");
    UnCuff(playerid);
    return 1;
}

forward UnCuff(playerid);
public UnCuff(playerid)
{
    new ID, string[256], opname[MAX_PLAYER_NAME];
    GetPlayerName(ID, opname, sizeof(opname));
    TogglePlayerControllable(ID, 0);
    format(string, sizeof(string), "%s has been Uncuff anymore!", opname, ID);
    SendPlayerMessageToPlayer(ID, playerid, string);
    return 1;
}
idk if works , just try, if not works tell me.
Reply
#4

pawn Код:
//in top of script
new t = 20;
new Timer;
forward UnCuff(ID);


public OnFilterScriptInit()
{
 
    return 1;
}
//your command
CMD:cuff(playerid, params[])
{
    new ID; new pname[24]; new opname[24]; new string[200];
    if(!IsPlayerACop(playerid)) return SendClientMessage(playerid, COLOR_RED,"You are not a law enforcement.");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You cannot use this command in a vehicle.");
    if(sscanf(params, "u", ID)) return SendClientMessage(playerid, COLOR_RED, "Usage: /cuff (ID)");
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, COLOR_RED, "Invalid ID.");
    GetPlayerName(ID, opname, 24); GetPlayerName(playerid, pname, 24);
    if(GetDistanceBetweenPlayers(playerid, ID) > 3) return SendClientMessage(playerid, COLOR_RED, "That player is too far away to be cuffed.");
    if(IsPlayerInAnyVehicle(ID)) return SendClientMessage(playerid, COLOR_RED, "That player is in a vehicle. You cannot cuff him.");
    if(IsPlayerACop(playerid)) return SendClientMessage(playerid, COLOR_RED, "You cannot cuff other Law Enforcements.");
    TogglePlayerControllable(ID, 0);
    GameTextForPlayer(ID, "~b~HANDCUFFED!", 5000, 1);
    format(string, sizeof(string), "[POLICE] Officer %s(%d) has put hand cuffs on you. You cannot move.", pname, playerid);
    SendClientMessage(ID, COLOR_LIGHTBLUE, string);
    format(string, 200, "[DISPATCH] Officer %s(%d) has cuffed player %s(%d)", pname, playerid, opname, ID);
   
         Timer =  SetTimerEx("UnCuff", 1000, true,"d",ID);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "[POLICE] You have cuffed a suspect. You have 30 seconds before they get uncuffed.");
}

//where you want but not in a callback
public UnCuff(ID)
{
       for(new i; i != MAX_PLAYERS;i++)
         {
              d--;
               if(d == 0)
               {
                         TogglePlayerControllable(i,true);
                         KillTimer(Timer);
                           d = 0;
                }
         }
}
Reply
#5

Quote:
Originally Posted by Devilxz97
Посмотреть сообщение
hmm , try this
pawn Код:
public OnGameModeInit()
{
    SetTimer("UnCuff", 20000, true);
    return 1;
}

CMD:cuff(playerid, params[])
{
    new ID, pname[24]; new opname[24]; new string[200];
    if(!IsPlayerACop(playerid)) return SendClientMessage(playerid, COLOR_RED,"You are not a law enforcement.");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You cannot use this command in a vehicle.");
    if(sscanf(params, "u", ID)) return SendClientMessage(playerid, COLOR_RED, "Usage: /cuff (ID)");
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, COLOR_RED, "Invalid ID.");
    GetPlayerName(ID, opname, 24); GetPlayerName(playerid, pname, 24);
    if(GetDistanceBetweenPlayers(playerid, ID) > 3) return SendClientMessage(playerid, COLOR_RED, "That player is too far away to be cuffed.");
    if(IsPlayerInAnyVehicle(ID)) return SendClientMessage(playerid, COLOR_RED, "That player is in a vehicle. You cannot cuff him.");
    if(IsPlayerACop(playerid)) return SendClientMessage(playerid, COLOR_RED, "You cannot cuff other Law Enforcements.");
    TogglePlayerControllable(ID, 1);
    GameTextForPlayer(ID, "~b~HANDCUFFED!", 5000, 1);
    format(string, sizeof(string), "[POLICE] Officer %s(%d) has put hand cuffs on you. You cannot move.", pname, playerid);
    SendClientMessage(ID, COLOR_LIGHTBLUE, string);
    format(string, 200, "[DISPATCH] Officer %s(%d) has cuffed player %s(%d)", pname, playerid, opname, ID);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "[POLICE] You have cuffed a suspect. You have 30 seconds before they get uncuffed.");
    UnCuff(playerid);
    return 1;
}

forward UnCuff(playerid);
public UnCuff(playerid)
{
    new ID, string[256], opname[MAX_PLAYER_NAME];
    GetPlayerName(ID, opname, sizeof(opname));
    TogglePlayerControllable(ID, 0);
    format(string, sizeof(string), "%s has been Uncuff anymore!", opname, ID);
    SendPlayerMessageToPlayer(ID, playerid, string);
    return 1;
}
idk if works , just try, if not works tell me.
I keeps sending me the message every 20 seconds saying "Captain_Mani has been uncuff anymore". I want it only to uncuff when I cuff someone.

@XStormiest; That is giving me errors. o.o

Please help.
Reply
#6

This may work, a little thing, your code is pretty messed up, try fixing this mess, it may help you alot for prevent future mistakes.
pawn Код:
CMD:cuff(playerid, params[])
{
    new ID,pname[24],opname[24],string[200];
    if(!IsPlayerACop(playerid)) return SendClientMessage(playerid, COLOR_RED,"You are not a law enforcement.");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You cannot use this command in a vehicle.");
    if(sscanf(params, "u", ID)) return SendClientMessage(playerid, COLOR_RED, "Usage: /cuff (ID)");
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, COLOR_RED, "Invalid ID.");
    GetPlayerName(ID, opname, 24); GetPlayerName(playerid, pname, 24);
    if(GetDistanceBetweenPlayers(playerid, ID) > 3) return SendClientMessage(playerid, COLOR_RED, "That player is too far away to be cuffed.");
    if(IsPlayerInAnyVehicle(ID)) return SendClientMessage(playerid, COLOR_RED, "That player is in a vehicle. You cannot cuff him.");
    if(IsPlayerACop(ID)) return SendClientMessage(playerid, COLOR_RED, "You cannot cuff other Law Enforcements.");
    TogglePlayerControllable(ID, 0);
    GameTextForPlayer(ID, "~b~HANDCUFFED!", 5000, 1);
    format(string, sizeof(string), "[POLICE] Officer %s(%d) has put hand cuffs on you. You cannot move.", pname, playerid);
    SendClientMessage(ID, COLOR_LIGHTBLUE, string);
    format(string, 200, "[DISPATCH] Officer %s(%d) has cuffed player %s(%d)", pname, playerid, opname, ID);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "[POLICE] You have cuffed a suspect. You have 30 seconds before they get uncuffed.");
    SetTimerEx(#cuffed,2000*10,false,"i",ID); // it gonna repate once, since is set to false, and only for the ID, which is the victim.
    return 1;
}
forward cuffed(playerid);
public cuffed(playerid)
{
    SendClientMessage(playerid,-1,#you're free);
    return TogglePlayerControllable(playerid, 1); // unfreezing him.
}
@ These guys that posted above are kinda wrong, first one is not required a loop or even call the settimer every second, is just required once, and doesn't require to destroy it, cause it's once.

second, why we would put a settimer on ongamemodeinit? to call it every 20 seconds, kinda useless.
Reply
#7

Quote:
Originally Posted by leonardo1434
Посмотреть сообщение
This may work, a little thing, your code is pretty messed up, try fixing this mess, it may help you alot for prevent future mistakes.
pawn Код:
CMD:cuff(playerid, params[])
{
    new ID,pname[24],opname[24],string[200];
    if(!IsPlayerACop(playerid)) return SendClientMessage(playerid, COLOR_RED,"You are not a law enforcement.");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You cannot use this command in a vehicle.");
    if(sscanf(params, "u", ID)) return SendClientMessage(playerid, COLOR_RED, "Usage: /cuff (ID)");
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, COLOR_RED, "Invalid ID.");
    GetPlayerName(ID, opname, 24); GetPlayerName(playerid, pname, 24);
    if(GetDistanceBetweenPlayers(playerid, ID) > 3) return SendClientMessage(playerid, COLOR_RED, "That player is too far away to be cuffed.");
    if(IsPlayerInAnyVehicle(ID)) return SendClientMessage(playerid, COLOR_RED, "That player is in a vehicle. You cannot cuff him.");
    if(IsPlayerACop(ID)) return SendClientMessage(playerid, COLOR_RED, "You cannot cuff other Law Enforcements.");
    TogglePlayerControllable(ID, 0);
    GameTextForPlayer(ID, "~b~HANDCUFFED!", 5000, 1);
    format(string, sizeof(string), "[POLICE] Officer %s(%d) has put hand cuffs on you. You cannot move.", pname, playerid);
    SendClientMessage(ID, COLOR_LIGHTBLUE, string);
    format(string, 200, "[DISPATCH] Officer %s(%d) has cuffed player %s(%d)", pname, playerid, opname, ID);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "[POLICE] You have cuffed a suspect. You have 30 seconds before they get uncuffed.");
    SetTimerEx(#cuffed,2000*10,false,"i",ID); // it gonna repate once, since is set to false, and only for the ID, which is the victim.
    return 1;
}
forward cuffed(playerid);
public cuffed(playerid)
{
    SendClientMessage(playerid,-1,#you're free);
    return TogglePlayerControllable(playerid, 1); // unfreezing him.
}
@ These guys that posted above are kinda wrong, first one is not required a loop or even call the settimer every second, is just required once, and doesn't require to destroy it, cause it's once.

second, why we would put a settimer on ongamemodeinit? to call it every 20 seconds, kinda useless.
Thanks a lot man. +repped
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)