Timer Help
#1

Hello
Im making a Drag Strip, and have gates that Drop and come back up, but they are Cmds.
how would i make this on a timer that goes off every 20 seconds?
Ive looked at wiki and it made no sense.
What ive got:
gates Up:
Quote:

new drag1;
new drag2;

Quote:

drag1 = CreateObject(970, -172.43, 1409.84, 66.71, 0.00, 0.00, 90.00);
drag2 = CreateObject(970, -172.43, 1404.64, 66.71, 0.00, 0.00, 90.00);

Gates Down :
Quote:

if(strcmp(cmdtext,"/drag",true)==0)
{
MoveObject(drag1, -172.43, 1409.84, 65.87 , 5.00);
MoveObject(drag2, -172.43, 1404.64, 65.87 , 5.00);
return 1;
}

Quote:

if(strcmp(cmdtext,"/dragreset",true)==0)
{
MoveObject(drag1, -172.43, 1409.84, 66.71 , 5.00);
MoveObject(drag2, -172.43, 1404.64, 66.71 , 5.00);
return 1;
}

So how would i put a timer on this? i want it to lower every 20 sec?
Reply
#2

Try this code, Maybe it will work

Quote:

new drag1, drag2;
drag1 = CreateObject(970, -172.43, 1409.84, 66.71, 0.00, 0.00, 90.00);
drag2 = CreateObject(970, -172.43, 1404.64, 66.71, 0.00, 0.00, 90.00);
forward Open(playerid);
forward Close(playerid);
SetTimerEx("Open", 40000, true, "d" , playerid);
public Open(playerid)
{
SetTimerEx("Close", 20000, true, "d" , playerid);
MoveObject(drag1, -172.43, 1409.84, 66.71 , 5.00);
MoveObject(drag2, -172.43, 1404.64, 66.71 , 5.00);
}
public Close(playerid)
{
MoveObject(drag1, -172.43, 1409.84, 65.87 , 5.00);
MoveObject(drag2, -172.43, 1404.64, 65.87 , 5.00);
}

Reply
#3

Sorry im noob how would i put that in my GM?
Reply
#4

Put this at the top on the script(under the includes)
pawn Код:
new drag1;
new drag2;
new DragPos;
The objects and the timer should be under OnGameModeInIt
pawn Код:
SetTimer("Drag",20*1000,1);
DragPos = 0;
drag1 = CreateObject(970, -172.43, 1409.84, 66.71, 0.00, 0.00, 90.00);
drag2 = CreateObject(970, -172.43, 1404.64, 66.71, 0.00, 0.00, 90.00);
Put this at the bottom of the script.
pawn Код:
forward Drag();
public Drag()
{
switch(DragPos)
{
case 0:
{
MoveObject(drag1, -172.43, 1409.84, 65.87 , 5.00);
MoveObject(drag2, -172.43, 1404.64, 65.87 , 5.00);
DragPos = 1;
return 1;
}
case 1:
{
MoveObject(drag1, -172.43, 1409.84, 66.71 , 5.00);
MoveObject(drag2, -172.43, 1404.64, 66.71 , 5.00);
DragPos = 0;
return 1;
}
}
return 1;
}
Reply
#5

Thank you guys SOOO Much, Worked nicely, one problem tho, it stays down for 20 sec and up for 20 sec, how can i make it stay Up for 20 sec and down for 4 sec?
Reply
#6

You'll have to change the timer from 20 seconds to 4 second, then the vatiable would do the trick
Simple math 4 X 5 = 20 which means when the variable reaches 5 the gate will get closed.
pawn Код:
new drag1;
new drag2;
new DragPos;
pawn Код:
SetTimer("Drag",4*1000,1);
DragPos = 0;
drag1 = CreateObject(970, -172.43, 1409.84, 66.71, 0.00, 0.00, 90.00);
drag2 = CreateObject(970, -172.43, 1404.64, 66.71, 0.00, 0.00, 90.00);
pawn Код:
forward Drag();
public Drag()
{
switch(DragPos)
{
case 0:
{
MoveObject(drag1, -172.43, 1409.84, 65.87 , 5.00);
MoveObject(drag2, -172.43, 1404.64, 65.87 , 5.00);
DragPos ++;
return 1;
}
case 5:
{
MoveObject(drag1, -172.43, 1409.84, 66.71 , 5.00);
MoveObject(drag2, -172.43, 1404.64, 66.71 , 5.00);
DragPos = 0;
return 1;
}
}
return 1;
}
Reply
#7

Quote:
Originally Posted by DaRk_RaiN
Посмотреть сообщение
You'll have to change the timer from 20 seconds to 4 second, then the vatiable would do the trick
Simple math 4 X 5 = 20 which means when the variable reaches 5 the gate will get closed.
pawn Код:
new drag1;
new drag2;
new DragPos;
pawn Код:
SetTimer("Drag",4*1000,1);
DragPos = 0;
drag1 = CreateObject(970, -172.43, 1409.84, 66.71, 0.00, 0.00, 90.00);
drag2 = CreateObject(970, -172.43, 1404.64, 66.71, 0.00, 0.00, 90.00);
pawn Код:
forward Drag();
public Drag()
{
switch(DragPos)
{
case 0:
{
MoveObject(drag1, -172.43, 1409.84, 65.87 , 5.00);
MoveObject(drag2, -172.43, 1404.64, 65.87 , 5.00);
DragPos ++;
return 1;
}
case 5:
{
MoveObject(drag1, -172.43, 1409.84, 66.71 , 5.00);
MoveObject(drag2, -172.43, 1404.64, 66.71 , 5.00);
DragPos = 0;
return 1;
}
}
return 1;
}
Thx Again, +REP,
Quote:

Dragposs = ++;
-------------------
: error 029: invalid expression, assumed zero
error 022: must be lvalue (non-constant)

So i changed it back to DragPoss = 0;

should this still work?
Reply
#8

I can't find that in my previous post,where did you find it?
Reply
#9

Edit: Ohh dude soo sorry i put =++; and it was ++; My bad sorry, Fixed
Edit: Hmm the gates have dissapared when i use this new code
Its the "case 5:" that stopped it, i changed it to 1 and they where back
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)