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



Problem - Twinki1993 - 07.01.2012

Well I am making command Signal which will add a signal next to you. I found object and everything needed as I wanted, but I have problem now. I want to set a timer 5 seconds, which will after 5 seconds delete the object, but I don't get it what's the problem with this.

When I added the timer the script just stopped working. Please help me. Without the timer it was working normaly but still I want the timer with it.

Код:
if (strcmp("/signal", cmdtext, true) == 0)
	{
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        new Signal;
        Signal = CreateObject(18674,x,y,z, 0.0, 0.0, 96.0);
        CreateObject(Signal,x,y,z, 0.0, 0.0, 96.0);
	{
	        SetTimer("Signal", 5000, false);
	}
	DestroyObject(Signal);
        return 1;
	}
Bump: I never worked with these timers before.


Re: Problem - BlackWolf120 - 07.01.2012

pawn Код:
if (strcmp("/signal", cmdtext, true) == 0)
{
    new Float:x, Float:y, Float:z, SignalObj;
    GetPlayerPos(playerid, x, y, z);
    SignalObj = CreateObject(18674,x,y,z, 0.0, 0.0, 96.0);
    SetTimer("Signal", 5000, false);
    return 1;
}

forward Signal();
public Signal()
{
    DestroyObject(SignalObj);
    return 1;
}
Structure should look like this


Re: Problem - Twinki1993 - 07.01.2012

All that bellow OnPlayerCommand?


Re: Problem - BlackWolf120 - 07.01.2012

only the command under OnPlayerCommand.

The timer and its forward you can place where ever you want it to have but OUTside of a callback/function.


Re: Problem - Psymetrix - 07.01.2012

Just a little edit of BlackWolf's code.
pawn Код:
// The command.
if (strcmp("/signal", cmdtext, true) == 0)
{
    new Float:x, Float:y, Float:z, SignalObj;
    GetPlayerPos(playerid, x, y, z);
    SignalObj = CreateObject(18674,x,y,z, 0.0, 0.0, 96.0);
    SetTimerEx( "Signal", 5000, false, "i", SignalObj );
    return 1;
}

// Somewhere outside onplayercommandtext.
forward Signal( objectid );
public Signal( objectid )
{
    DestroyObject( objectid );
    return 1;
}



Re: Problem - BlackWolf120 - 07.01.2012

overloocked that, thx Psymetrix, should work now.


Re: Problem - Twinki1993 - 07.01.2012

Thanks ^_^