Timer problem
#1

OnPlayerConnect , I've set a 30 minute tax timer for the player who just connected so they can pay taxes every 30 minutes. When the timer reaches 30 minutes, they will pay taxes once.

The problem is, if I gmx the server, the tax timer is set twice because of the first time the player joined and second time because of the gmx. Now when 30 minutes reaches, they pay tax twice because the timer was set twice.

I've tried killing the timer in OnGameModeInit and on OnPlayerDisconnect but it still sets twice because of the gmx.

Anyone know why ?
Reply
#2

That's really weird,honestly,may I see the code?
Reply
#3

Well when I set the timer , this is all there is:

pawn Код:
if(!IsPlayerNPC(playerid))
    {
        SetPVarInt(playerid, "Taxes", SetTimerEx("Taxes", 30000, true, "i", playerid));
    }
Note , the 30000 milliseconds in the timer was used for testing purposes only , that isn't 30 minutes
Reply
#4

Your code it's a bit strange,but here's a possible fix:
pawn Код:
forward Taxes(playerid);
new SetTax[MAX_PLAYERS];

OnPlayerConnect(playerid)
{
   SetTax[playerid]=SetTimerEx("Taxes",30000,true,"i",playerid);
   return 1;
}

OnPlayerDisconnect(playerid)
{
   KillTimer(SetTax[playerid]);
   return 1;
}

public Taxes(playerid)
{
   //code
   return 1;
}
Don't use SetPVarInt with a timer anymore...try to adapt your code following the example I gave you
Reply
#5

Quote:
Originally Posted by Cjgogo
Посмотреть сообщение
Your code it's a bit strange,but here's a possible fix:
pawn Код:
forward Taxes(playerid);
new SetTax[MAX_PLAYERS];

OnPlayerConnect(playerid)
{
   SetTax[playerid]=SetTimerEx("Taxes",30000,true,"i",playerid);
   return 1;
}

OnPlayerDisconnect(playerid)
{
   KillTimer(SetTax[playerid]);
   return 1;
}

public Taxes(playerid)
{
   //code
   return 1;
}
Don't use SetPVarInt with a timer anymore...try to adapt your code following the example I gave you
Thanks but it still didn't work

Maybe it's my Onplayerdisconnect code ?

Any other solutions ?
Reply
#6

Try killing the timer OnGameModeExit so will be killed when you gmx.
Reply
#7

Nevermind , I solved the problem.

There was another OnPlayerConnect(); function in OnGameModeInit in my script for some reason which kept setting off OnPlayerConnect twice, and I had forgot to disable it. It had nothing to do with the timers or PVars or ongamemodeexit or onplayerconnect.

Thanks for the help though guys
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)