How to move vehicles?
#1

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?
Reply
#2

Here you can learn how to move and program vehicles:
https://sampwiki.blast.hk/wiki/Category:NPC
Reply
#3

Use SetVehicleVelocity.
Reply
#4

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
But there's no callback for it like OnObjectMoved
Reply
#5

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.
Reply
#6

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
}
Reply
#7

Or.. you can do it like CalvinC and not embarrass yourself by overcomplicating things.
Reply
#8

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.
Reply
#9

Theres another method of detecting if the vehicle stops after accelerating ithere 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
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)