Attaching objects to vehicles
#1

Hi guys.
I am scripting something, which includes attaching 2 objects to a vehicle.
When a player types a command, one of the objects will be attached to the vehicle, and after one second, the other object will be attached to the vehicle. I know this is simple to do with timers, but is there any way to avoid using a timer? I know that some other scripting languages have "wait" functions.

Hope you can help. Thanks.
Reply
#2

yes of course maybe with functions gettime() not?
Reply
#3

Quote:
Originally Posted by dEcooR
Посмотреть сообщение
yes of course maybe with functions gettime() not?
gettime is used to get the time in the server. This has nothing with that to do.
Thanks for your time though.
Reply
#4

Try this:

pawn Код:
wait(seconds)
{
new _newTime[4], _oldTime[4];
gettime(_oldTime[0], _oldTime[1], _oldTime[2]);
_oldTime[3] = _oldTime[2] + (_oldTime[1] * 60) + (_oldTime[0] * 600);

while(_newTime[3] != (_oldTime[3] + seconds))
{
gettime(_newTime[0], _newTime[1], _newTime[2]);
_newTime[3] = _newTime[2] + (_newTime[1] * 60) + (_newTime[0] * 600);
}
}
Then use wait(1);
To wait one sec

And yeah GetTime() will help.

Код:
This is not mine.
Read this
V

Edit: Wait fonction freezes the server, use this include : Sleep
Reply
#5

Hello guys I need help I have my code but where do I put it? Under what function?

new objectid = CreateObject(10245);
new vehicleid = GetPlayerVehicleID(playerid);
AttachObjectToVehicle(objectid, vehicleid, 0.0303, 1.6107, 6.4743, 0.0000, 0.0000, 314.6721);

Thanks in advance
Reply
#6

Quote:
Originally Posted by DeMoX
Посмотреть сообщение
Try this:

pawn Код:
wait(seconds)
{
new _newTime[4], _oldTime[4];
gettime(_oldTime[0], _oldTime[1], _oldTime[2]);
_oldTime[3] = _oldTime[2] + (_oldTime[1] * 60) + (_oldTime[0] * 600);

while(_newTime[3] != (_oldTime[3] + seconds))
{
gettime(_newTime[0], _newTime[1], _newTime[2]);
_newTime[3] = _newTime[2] + (_newTime[1] * 60) + (_newTime[0] * 600);
}
}
Then use wait(1);
To wait one sec

And yeah GetTime() will help.

Код:
This is not mine.
Read this
V

Edit: Wait fonction freezes the server, use this include : Sleep
All of this is non-sense you don't want to prevent your script from working, just use a timer what is the big deal ? Usually people use timers when they don't have to your trying to do the opposite by not using timers. However what your trying to do won't work unless a timer is used.

If it's syntax your looking for try y_timers https://sampforum.blast.hk/showthread.php?tid=182948 your looking for this part.

pawn Код:
timer DelayedTimer[500](playerid)
{
    printf("May be called after 0.5 seconds");
}

main()
{
    defer DelayedTimer(42);
}
I don't think it could be easier to read than that.
Reply
#7

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
All of this is non-sense you don't want to prevent your script from working, just use a timer what is the big deal ? Usually people use timers when they don't have to your trying to do the opposite by not using timers. However what your trying to do won't work unless a timer is used.

If it's syntax your looking for try y_timers https://sampforum.blast.hk/showthread.php?tid=182948 your looking for this part.

pawn Код:
timer DelayedTimer[500](playerid)
{
    printf("May be called after 0.5 seconds");
}

main()
{
    defer DelayedTimer(42);
}
I don't think it could be easier to read than that.
Alright, thanks!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)