SA-MP Forums Archive
Cant get the Timer working, Plz help -.- - 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: Cant get the Timer working, Plz help -.- (/showthread.php?tid=346849)



Cant get the Timer working, Plz help -.- - jordy.kiesebrink - 30.05.2012

Can someone help me fixing this annoying timer which I cant get working

Here is the part of the action when swearing was detected.
pawn Код:
new tname[MAX_PLAYER_NAME];
GetPlayerName(playerid,tname,sizeof(tname));
new CheatString[256];
format(CheatString,sizeof(CheatString),"Administrator bot muted %s for Swearing / Forbidden Word",tname);
if(PlayerAcc[playerid][Muted] == 1) return 1;
SendClientMessageToAll(red,CheatString);
PlayerAcc[playerid][Muted] = 1;
GameTextForPlayer(playerid, "~r~You have been muted!",5000,1);
SetTimerEx("unmute", 60000, true, "i", playerid);
It should call the unmute after 60000 milisecond (1 minute) and then unmute the muted player..
But sometimes it unmutes me after 3 seconds and sometimes it wont even unmute me

pawn Код:
forward Checking();
public unmute(playerid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    if(IsPlayerConnected(i) && PlayerAcc[i][Muted] == 1)
    PlayerAcc[i][Muted] = 0;
    SendClientMessage(playerid ,red,"You have been unmuted! You can talk now!");
}
I want it so that if the swearing was detected the bot muted the swearing player and after 1 minute the bot will unmute the player, and for now its not really working well when the bot have to mute 2 players -.-

It doesnt gives me errors but its just not doing what i want

I also tried this without proper results:
pawn Код:
public unmute(playerid)
{
    new Target;
    if(PlayerAcc[Target][Muted] == 1)
    SendClientMessage(Target,red,"You have been unmuted! You can talk now!");
    PlayerAcc[Target][Muted] = 0;
 
}



Re: Cant get the Timer working, Plz help -.- - RoboN1X - 30.05.2012

i think there is no problem on the first code, but
Quote:
Originally Posted by jordy.kiesebrink
Посмотреть сообщение
pawn Код:
forward Checking();
public unmute(playerid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    if(IsPlayerConnected(i) && PlayerAcc[i][Muted] == 1)
    PlayerAcc[i][Muted] = 0;
    SendClientMessage(playerid ,red,"You have been unmuted! You can talk now!");
}
What is Checking() for?
and why you need to loop it for all players since you're already using
pawn Код:
SetTimerEx("unmute", 60000, true, "i", playerid); // this will set a timer to call callback for the playerid with repeat option enabled
Quote:
Originally Posted by jordy.kiesebrink
Посмотреть сообщение
pawn Код:
public unmute(playerid)
{
    new Target;
    if(PlayerAcc[Target][Muted] == 1)
    SendClientMessage(Target,red,"You have been unmuted! You can talk now!");
    PlayerAcc[Target][Muted] = 0;
 
}
it won't make the player get unmute, because you just create a new variable "Target" with no value, try changing them to playerid
pawn Код:
public unmute(playerid)
{
    if(PlayerAcc[playerid][Muted] == 1) { // check if the player is muted
        PlayerAcc[Target][Muted] = 0; // set the player variable to 0 or not muted
        SendClientMessage(playerid, red, "You have been unmuted! You can talk now!"); // send the message to player
    }
}
also change the SetTimerEx parameter, you don't need to repeat calling the "unmute" callback
pawn Код:
SetTimerEx("unmute", 60000, false, "i", playerid); // set a timer to call "unmute" for "playerid(i)" in 60000 ms = 1 minute without repeating the timer
also make sure you have forwarded the unmute callback
Note: not tested, hope it works
for info, https://sampwiki.blast.hk/wiki/SetTimerEx


Re: Cant get the Timer working, Plz help -.- - jordy.kiesebrink - 30.05.2012

I copyed the wrong forward it should be
pawn Код:
forward unmute(playerid);//above in the script

public unmute(playerid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    if(IsPlayerConnected(i) && PlayerAcc[i][Muted] == 1)
    PlayerAcc[i][Muted] = 0;
    SendClientMessage(playerid ,red,"You have been unmuted by Chuck! You can talk now!");
}
I thought if I set a timer after the bot muted a player he should call the unmute public after the timer was passed (1 minute) and then it should unmute a player so I looped through all the players to check who is muted and then unmute that target but it should be the playerid, So if I take this

pawn Код:
public unmute(playerid)
{
    if(PlayerAcc[playerid][Muted] == 1) { // check if the player is muted
        PlayerAcc[Target][Muted] = 0; // set the player variable to 0 or not muted
        SendClientMessage(playerid, red, "You have been unmuted! You can talk now!"); // send the message to player
    }
}
and then with the false timer, I thought it should repeat becouse the player can swear the next time without calling it back but thats bullshit then..

so then it should work in theorie?