Repeat moved object? -
bajskorv123 - 20.02.2010
Hey, I have a ufo for my server and i want it to keep going from car school to north sf.
Im not sure if my code works, i havent tested it, it should work

I want the object so when it goes to north sf, then back to car school, then it goes back to north sf, so it keeps doing it like that all the time.
Heres my code:
pawn Код:
#include <a_samp>
new ufo;
public OnFilterScriptInit()
{
ufo = CreateObject(13607, -2058.7773, -198.6086, 98.033844, 0.0000, 0.0000, 0.0000);//car school
SetTimer("MoveUfo", 10000, false);//Move the ufo 10 seconds after filterscript loads
return 1;
}
forward MoveUfo();
public MoveUfo()
{
MoveObject(ufo, -2039.0299, 1325.1370, 98.033844, 2.5000);//Moves the ufo to north sf
return 1;
}
public OnObjectMoved(objectid)//This gets called after the "ufo" object has been moved
{
if(objectid = ufo)
{
MoveObject(ufo, -2058.7773, -198.6086, 98.033844, 2.5000);//Moves the ufo back to car school
}
return 1;
}
Re: Repeat moved object? -
Torran - 20.02.2010
Dont see why that shouldnt work?
On erm, OnObjectMoved, Add a timer, That moves the ufo again,
So
SetTimer("MovieUfo", 10000, false);
OnObjectMoved
Something like that
Re: Repeat moved object? -
bajskorv123 - 20.02.2010
Like this?
pawn Код:
#include <a_samp>
#define TimeItTakesForUfoToMove Something //I change something later
new ufo;
public OnFilterScriptInit()
{
ufo = CreateObject(13607, -2058.7773, -198.6086, 98.033844, 0.0000, 0.0000, 0.0000);
SetTimer("Move", 10000, false);
return 1;
}
forward Move();
public Move()
{
MoveObject(ufo, -2058.7773, 1320.0000, 98.033844, 2.5000);
return 1;
}
public OnObjectMoved(objectid)
{
if(objectid = ufo)
{
MoveObject(ufo, -2058.7773, -198.6086, 98.033844, 2.5000);
SetTimer("Move", TimeItTakesForUfoToMove, false);
}
return 1;
}
Re: Repeat moved object? -
Torran - 21.02.2010
Yes
Re: Repeat moved object? -
Nero_3D - 21.02.2010
pawn Код:
public OnFilterScriptInit()
{
ufo = CreateObject(13607, -2058.7773, -198.6086, 98.033844, 0.0000, 0.0000, 0.0000);
MoveObject(ufo, -2058.7773, 1320.0000, 98.033844, 2.5000);
}
This would be a way
pawn Код:
public OnObjectMoved(objectid)
{
if(objectid == ufo)
{
MoveObject(ufo, -2058.7773, -198.6086, 98.033844, 2.5000);
ufo += MAX_OBJECTS;
}
else if(objectid == (ufo - MAX_OBJECTS))
{
ufo -= MAX_OBJECTS;
MoveObject(ufo, -2058.7773, 1320.0000, 98.033844, 2.5000);
}
}
Or the one you already had
pawn Код:
forward Move();
public Move()
{
MoveObject(ufo, -2058.7773, 1320.0000, 98.033844, 2.5000);
}
pawn Код:
public OnObjectMoved(objectid)
{
if(objectid == ufo)
{
SetTimer("Move", (MoveObject(ufo, -2058.7773, -198.6086, 98.033844, 2.5000) - 10), false);
//MoveObject returns the time it will take for the object to move in milliseconds
//And the - 10 because if it completely moved it will call OnObjectMoved to move again to the same cords
//So we call the object 10 ms before back (we could do + 10 but then the OnObjectMoved code gets unused executed)
}
}