How to move vehicles? -
ATGOggy - 22.02.2015
I want to move a vehicle instead of an object in MoveObject.
How to do that? Can I create a shamal (as object) with CreateObject?
I want to make a moving shamal without NPCs etc. Any idea?
Re: How to move vehicles? -
Schneider - 22.02.2015
Here you can learn how to move and program vehicles:
https://sampwiki.blast.hk/wiki/Category:NPC
Re: How to move vehicles? -
CalvinC - 22.02.2015
Use
SetVehicleVelocity.
Re: How to move vehicles? -
ATGOggy - 22.02.2015
Quote:
Originally Posted by CalvinC
|
But there's no callback for it like OnObjectMoved
Re: How to move vehicles? -
Extremo - 22.02.2015
This is the beauty of sa-mp. It doesn't feed you all the systems by default. Often you will need to improvise. Store the locations of all vehicles. If they have a driver, ignore the vehicle until they no longer do and store it again if necessary and otherwise compare locations and trigger your own callback.
EDIT: If you want to be really fancy, create an object inside every vehicle using
AttachObjectToVehicle and move that object WITH the vehicle - causing the callback to be triggered everytime it moves, however I am pretty sure you'll have to remove the attachment before hand and attach it afterwards again and this makes it a little complicated, but this way you can avoid checking the locations of vehicles all the time.
Re: How to move vehicles? -
CalvinC - 22.02.2015
Then you can just use your own function.
pawn Код:
SetVehicleVelocityEx(vehicleid, Float:x, Float:y, Float:z)
{
SetVehicleVelocity(vehicleid, x, y, z);
// Whatever else you want to do
}
Re: How to move vehicles? -
Extremo - 22.02.2015
Or.. you can do it like CalvinC and not embarrass yourself by overcomplicating things.
Re: How to move vehicles? -
ATGOggy - 22.02.2015
But look this:
https://sampwiki.blast.hk/wiki/SetVehicleVelocity
Read that note:- 'This function has no affect on un-occupied vehicles and does not affect trains.'
Also, will this work:
pawn Код:
CreateObject(519,0,0,0,0,0,0);
id 519 is shamal.
Re: How to move vehicles? -
Gammix - 22.02.2015
Theres another method of detecting if the vehicle stops after accelerating it

here i made it in a hurry!)
pawn Код:
new bool:moved[MAX_VEHICLES];
public OnGameModeInit()
{
SetTimer("OnTimePass", 1000, true);
return 1;
}
stock MoveVehicle(id, Float:x, Float:y, Float:z)
{
moved[id] = true;
return SetVehicleVelocity(id, x, y, z);
}
forward OnTimePass();
public OnTimePass()
{
for(new i; i < MAX_VEHICLES; i++)
{
if(moved[i])
{
new Float:f[3];
GetVehicleVelocity(i, f[0], f[1], f[2]);
if(f[0] == 0.0 && f[1] == 0.0 && f[2] == 0.0)
{
moved[i] = false;
CallLocalFunction("OnVehicleMoved", "d", i);
}
}
}
return 1;
}
forward OnVehicleMoved(id);
public OnVehicleMoved(id)
{
//do your stuff here. "id" refers to vehicle id and this callback is called when a vehicle stops after being accelerated
return 1;
}
Not recommended though.
EDIT: use NPC recording to do so. Or make use of RNPC or FCNPC plugin.
in game npc recorder:
https://sampforum.blast.hk/showthread.php?tid=299207
Re: How to move vehicles? -
Patrik356b - 22.02.2015
Or just create the an object which looks like the shamal and apply MoveObject
Quote:
Originally Posted by ATGOggy
will this work:
pawn Код:
CreateObject(519,0,0,0,0,0,0);
id 519 is shamal.
|
No, you can not create vehicles as objects.