SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 19/12/2010, 01:53 AM   #1
VirSpectorX
Big Clucker
 
Join Date: Nov 2009
Posts: 109
Reputation: 0
Default Timer Problem

I have a problem when making a timer. Look at part of my script.

On the top of the script:
pawn Code:
forward takeover(playerid, gangzoneid);
forward counter(playerid, gangzoneid);

And then, I added these functions:
pawn Code:
//Gangzone Functions
public takeover(playerid, gangzoneid)
{
    new string[256];
    if(GetGangzoneOwner(gangzoneid) >= 0)
    {
        format(string, sizeof(string), "|- {FFFF00}%s {00FF00}has successfully taking over the territory of {FFFF00}%s {00FF00} -|", PlayerName(playerid), GetTeamName(GetGangzoneOwner(gangzoneid)));
        SendClientMessageToAll(0x00FF00AA, string);
    }
    else
    {
        format(string, sizeof(string), "|- {FFFF00}%s {00FF00}has successfully taking over a territory -|", PlayerName(playerid));
        SendClientMessageToAll(0x00FF00AA, string);
    }

    GangzoneOwner[gangzoneid] = GetPlayerTeam(playerid);
    GangzoneChangeOwner[gangzoneid] = -1;

    GangZoneHideForAll(gangzoneid);
    GangZoneShowForAll(gangzoneid, GetPlayerColor(playerid));
    GangzoneColor[gangzoneid] = GetPlayerColor(playerid);

    KillTimer(GetPVarInt(playerid, "gzcounter"));
}

public counter(playerid, gangzoneid)
{
    new Float:junk, Float:y;
    new string[256];
    GetPlayerPos(playerid, junk, y, junk);

    if(IsPlayerInRangeOfPoint(playerid, 30, GangzoneCheckpoint[gangzoneid][0], y, GangzoneCheckpoint[gangzoneid][2]))
    {
        if(!IsPlayerInRangeOfPoint(playerid, 20, GangzoneCheckpoint[gangzoneid][0], y, GangzoneCheckpoint[gangzoneid][2]))
        {
            GameTextForPlayer(playerid, "~w~Watch out! ~r~You're too far from the ~y~checkpoint!~n~~w~Go back to the checkpoint!", 2000, 2);
        }
    }
    else
    {
        GameTextForPlayer(playerid, "~r~You failed on trying to ~y~takeover~r~ this territory", 4000, 2);

        format(string, sizeof(string), "|- {FFFF00}%s {FF0000}has failed on trying to takeover the territory -|", PlayerName(playerid));
        SendClientMessageToAll(0xFFFF00AA, string);

        KillTimer(GetPVarInt(playerid, "gztimer"));
        KillTimer(GetPVarInt(playerid, "gzcounter"));
    }

    SendClientMessage(playerid, 0xFFFF00AA, "1 second elapsed"); //This is the debug
}

And, I added this in OnPlayerCommandText (Somewhere in it):
pawn Code:
SetPVarInt(playerid, "gztimer", SetTimerEx("takeover", 60000, false, "ii", playerid, IsPlayerInGangzoneCheckpoint(playerid)));
SetPVarInt(playerid, "gzcounter", SetTimerEx("counter", 1000, true, "ii", playerid, IsPlayerInGangzoneCheckpoint(playerid)));

I used the command, I saw that 1 second elapsed message (which is the debug I wanted), but the take over doesn't. I've wait for 1 minute and still nothing happened (I count with the debug). Anyone can help please?
VirSpectorX is offline  
Old 19/12/2010, 02:00 AM   #2
Rachael
Huge Clucker
 
Rachael's Avatar
 
Join Date: Feb 2010
Posts: 380
Reputation: 28
Default Re: Timer Problem

I don't know what IsPlayerInGangzoneCheckpoint(playerid) returns, but it looks like it returns 1 for true or 0 for false?
Then you use this value as gangzoneid in your timer. Maybe this is intentional, maybe not.
Rachael is offline  
Old 19/12/2010, 02:26 AM   #3
VirSpectorX
Big Clucker
 
Join Date: Nov 2009
Posts: 109
Reputation: 0
Default Re: Timer Problem

The IsPlayerInGangzoneCheckpoint(playerid) returns the gangzone ID (No, not "real" gangzone ID, it's another gangzone ID between 0 to 6) and it returns -1 if the palyer isn't in gangzone.

The functions work perfectly, only the timer doesn't run
VirSpectorX is offline  
Old 19/12/2010, 02:34 AM   #4
VirSpectorX
Big Clucker
 
Join Date: Nov 2009
Posts: 109
Reputation: 0
Default Re: Timer Problem

Anyone
VirSpectorX is offline  
Old 19/12/2010, 02:38 AM   #5
Rachael
Huge Clucker
 
Rachael's Avatar
 
Join Date: Feb 2010
Posts: 380
Reputation: 28
Default Re: Timer Problem

if your function IsPlayerInGangzoneCheckpoint(playerid) doesn't return an actual gangzoneid, then I don't think you should be using GangZoneHideForAll(gangzoneid); in the takeover function.

I suggest you use printf / print to debug this. ie find out if the timer is being called, what values the variables have, and then take it from there.
Rachael is offline  
Old 19/12/2010, 03:17 AM   #6
VirSpectorX
Big Clucker
 
Join Date: Nov 2009
Posts: 109
Reputation: 0
Default Re: Timer Problem

Hmm, you got a point actually...
VirSpectorX is offline  
Old 19/12/2010, 03:43 AM   #7
VirSpectorX
Big Clucker
 
Join Date: Nov 2009
Posts: 109
Reputation: 0
Default Re: Timer Problem

The Territory has flashed. But the timer still won't run. Any idea?
VirSpectorX is offline  
Old 19/12/2010, 04:22 AM   #8
Rachael
Huge Clucker
 
Rachael's Avatar
 
Join Date: Feb 2010
Posts: 380
Reputation: 28
Default Re: Timer Problem

If that is the case, split the SetPVarInt command up into its parts, use some extra variables, and printf the results.
Rachael is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Timer Problem ShawnMiller1337 Help Archive 8 15/12/2010 10:56 PM
timer problem dark_clown Help Archive 5 20/10/2010 07:25 PM
timer problem WardenCS Help Archive 5 13/10/2010 12:41 PM
Timer Problem Jakku Help Archive 4 26/07/2009 06:16 PM
Problem with this timer... Zebadee Help Archive 0 18/02/2009 10:50 PM


All times are GMT. The time now is 03:16 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.