PDA

View Full Version : moveobject with timer plz help me :|


noamch1997
16/08/2014, 11:58 AM
I want to make my object to move with timer from:
X1,Y1,Z1 -->X2,Y2,Y3-->X3,Y3,Z3-->X4,Y4,Z4-->X5,Y5,Z5-->X6,Y6,Z6 .
with timer .. I want to make this move , to move over and over again without stop (when player near the object - somthing like 30.000)

the object X,Y,Z :
X1Y1Z1 - http://prntscr.com/4dbnpz
X2Y2Z2 - http://prntscr.com/4dbnvs
X3Y3Z3 - http://prntscr.com/4dboii
X4Y4Z4 - http://prntscr.com/4dbolm
X5Y5Z5 - http://prntscr.com/4dbodl
X6Y6Z6 - http://prntscr.com/4dboom

I dont know how to make it..someone can help me plz ? I will +REP
tnx very much !!!!!!!!!!!!!

Lofti
16/08/2014, 12:11 PM
Have you tried using settimer and killtimer for every object's coordinates? Im gueesing you want to make the spawnings random not in the same order everytime.

MicroD
16/08/2014, 12:13 PM
I can give you idea because I have no time to code it for you.
So you want to check if a player is close to your object at a given distance by using snippet or what ever to check it. After that you create object at the initial spot and if player is close give it some movement ( http://wiki.sa-mp.com/wiki/MoveObject ) after object is moved to X2Y2Z2 it will call his mother (http://wiki.sa-mp.com/wiki/OnObjectMoved) and tell her that he's done. Inside OnObjectMoved you want to create a check if it's the object you're moving and if it is make switch function which will go through states of object movement which you can control by creating a simple variable named "state" or what ever. And that's pretty much it once it get sto the last case 5: you put state variable back to 0. That's what came onto my mind when I saw this, there might be a bit easier way?

Virtual1ty
16/08/2014, 12:15 PM
Check out the pirateship.pwn that comes with the SA: MP server on how to do this. Use OnObjectMoved to set next point, or stop the object/kill the timer or reset. Good luck!

noamch1997
16/08/2014, 12:40 PM
Have you tried using settimer and killtimer for every object's coordinates? Im gueesing you want to make the spawnings random not in the same order everytime.

I can give you idea because I have no time to code it for you.
So you want to check if a player is close to your object at a given distance by using snippet or what ever to check it. After that you create object at the initial spot and if player is close give it some movement ( http://wiki.sa-mp.com/wiki/MoveObject ) after object is moved to X2Y2Z2 it will call his mother (http://wiki.sa-mp.com/wiki/OnObjectMoved) and tell her that he's done. Inside OnObjectMoved you want to create a check if it's the object you're moving and if it is make switch function which will go through states of object movement which you can control by creating a simple variable named "state" or what ever. And that's pretty much it once it get sto the last case 5: you put state variable back to 0. That's what came onto my mind when I saw this, there might be a bit easier way?

Check out the pirateship.pwn that comes with the SA: MP server on how to do this. Use OnObjectMoved to set next point, or stop the object/kill the timer or reset. Good luck!



I am beginner in Pawn and I dont know how to write it .. please someone may code it for me ? its very simple to you :|
plz plz !!!
tnx !

noamch1997
16/08/2014, 04:24 PM
someone ? plz ? I wil rep you

noamch1997
17/08/2014, 04:01 PM
plz someone ! just example for me :|

noamch1997
17/08/2014, 10:31 PM
plz someone ! just example for me

noamch1997
18/08/2014, 03:38 PM
someone ?

noamch1997
19/08/2014, 01:33 AM
it easey for you .. why nobody can give me an example ? i just want to learn

Jefff
19/08/2014, 02:08 AM
forward MoveObjects(index);
public MoveObjects(index)
{
index %= 5;
static time;
switch(index)
{
case 0: time = MoveObject(objectid, X1, Y1, Z1, speed);
case 1: time = MoveObject(objectid, X2, Y2, Z2, speed);
case 2: time = MoveObject(objectid, X3, Y3, Z3, speed);
case 3: time = MoveObject(objectid, X4, Y3, Z4, speed);
case 4: time = MoveObject(objectid, X5, Y4, Z5, speed);
default: time = MoveObject(objectid, X6, Y6, Z6, speed);
}
++index;
SetTimerEx("MoveObjects",time+150,false,"i",index);
}

for start object
MoveObjects(0);

Nero_3D
19/08/2014, 02:12 AM
And to check if a player is near the object you need to do add something like that

// global
new bool: gMoveObjects;

// stolen code from Jeff
forward MoveObjects(index);
public MoveObjects(index)
{
new Float: X, Float: Y, Float: Z;
GetObjectPos(objectid, X, Y, Z);

for(new i; i != MAX_PLAYERS; ++i)
{
if(IsPlayerInRangeOfPoint(i, 30.0, X, Y, Z))
{
static time;
switch(index %= 6)
{
case 0: time = MoveObject(objectid, X1, Y1, Z1, speed);
case 1: time = MoveObject(objectid, X2, Y2, Z2, speed);
case 2: time = MoveObject(objectid, X3, Y3, Z3, speed);
case 3: time = MoveObject(objectid, X4, Y3, Z4, speed);
case 4: time = MoveObject(objectid, X5, Y4, Z5, speed);
case 5: time = MoveObject(objectid, X6, Y6, Z6, speed);
}
++index;
SetTimerEx("MoveObjects",time+150,false,"i",index);
return ;
}
}
gMoveObjects = false;
}
// OnPlayerUpdate - to start the movement
if(gMoveObjects == false)
{
new Float: X, Float: Y, Float: Z;
GetObjectPos(objectid, X, Y, Z);

if(IsPlayerInRangeOfPoint(playerid, 30.0, X, Y, Z))
{
gMoveObjects = true;
MoveObjects(0);
}
}

noamch1997
19/08/2014, 04:19 PM
delete this message

noamch1997
19/08/2014, 05:15 PM
where i should to put my object X Y Z ?
and where i should to put the moves object X Y Z ?

Nero_3D
19/08/2014, 06:05 PM
where i should to put my object X Y Z ?
and where i should to put the moves object X Y Z ?

You see the 6 cases ?, replace the X1, Y1, Z1, ... X6, Y6, Z6 with your coordinates that you mentioned in the first post

switch(index %= 6) {
case 0: time = MoveObject(objectid, X1, Y1, Z1, speed);
case 1: time = MoveObject(objectid, X2, Y2, Z2, speed);
case 2: time = MoveObject(objectid, X3, Y3, Z3, speed);
case 3: time = MoveObject(objectid, X4, Y3, Z4, speed);
case 4: time = MoveObject(objectid, X5, Y4, Z5, speed);
case 5: time = MoveObject(objectid, X6, Y6, Z6, speed);
}

Pottus
19/08/2014, 06:08 PM
You need to set the position of the object once it stops moving (between frames) otherwise there will be sync issues for players.