SA-MP Forums Archive
Disable car moving, pushing - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Disable car moving, pushing (/showthread.php?tid=554624)



Disable car moving, pushing - bobsona - 04.01.2015

Hello, I want to disable car moving and pushing.
I want all the cars can move only if you are in the car as driver and you are driving the car.
Any ideas how that's possible?


Re: Disable car moving, pushing - Sid_Alexander - 04.01.2015

Quote:
Originally Posted by bobsona
Посмотреть сообщение
Hello, I want to disable car moving and pushing.
I want all the cars can move only if you are in the car as driver and you are driving the car.
Any ideas how that's possible?
If you're talking about the player pushing the car, That is not possible to disable from what i think.


Re: Disable car moving, pushing - Threshold - 04.01.2015

https://sampwiki.blast.hk/wiki/OnUnoccupiedVehicleUpdate


Re: Disable car moving, pushing - bobsona - 04.01.2015

Any example code for my case with OnUnoccupiedVehicleUpdate?


Re: Disable car moving, pushing - Abagail - 04.01.2015

pawn Код:
public OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat, Float:new_x, Float:new_y, Float:new_z, Float:vel_x, Float:vel_y, Float:vel_z)
{
        new Float: pos[3];
        GetTrunkPos(vehicleid, pos[0], pos[1], pos[2]);
        if(IsPlayerInRangeOfPoint(playerid, 4.5, pos[0], pos[1], pos[2]))
        {
                GetVehiclePos(vehicleid, pos[0], pos[1], pos[2]);
                SetVehiclePos(vehicleid, pos[2], pos[1], pos[2]);
        }
    return 1;
}
You can try doing something like this.


Re: Disable car moving, pushing - Lawbringer - 04.01.2015

Quote:
Originally Posted by Abagail
Посмотреть сообщение
pawn Код:
public OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat, Float:new_x, Float:new_y, Float:new_z, Float:vel_x, Float:vel_y, Float:vel_z)
{
        new Float: pos[3];
        GetTrunkPos(vehicleid, pos[0], pos[1], pos[2]);
        if(IsPlayerInRangeOfPoint(playerid, 4.5, pos[0], pos[1], pos[2]))
        {
                GetVehiclePos(vehicleid, pos[0], pos[1], pos[2]);
                SetVehiclePos(vehicleid, pos[2], pos[1], pos[2]);
        }
    return 1;
}
You can try doing something like this.
Basically the same as this, but with one suggestion:
1. Save the vehicle position when a player exits it. Save it into a global array.
2. OnUnoccupiedVehicleUpdate if the position has changed by more than 0.1, then teleport the vehicle back to the last recorded position (from when the player exited) and return 1 to sync the update to all players.


Re: Disable car moving, pushing - bobsona - 04.01.2015

How can I save the vehicle position when a player exits it into a global array?
For the second point I could not understand what you mean exactly.
I apologize for the stupid questions, but I'm still a beginner in PAWN scripting.
The syntax is still difficult for me.


Re: Disable car moving, pushing - Threshold - 05.01.2015

pawn Код:
public OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat, Float:new_x, Float:new_y, Float:new_z, Float:vel_x, Float:vel_y, Float:vel_z)
{
    new Float: pos[3];
    GetVehiclePos(vehicleid, pos[0], pos[1], pos[2]);
    SetVehiclePos(vehicleid, pos[0], pos[1], pos[2]);
    return 0;
}



Re: Disable car moving, pushing - Lordzy - 05.01.2015

This callback is called VERY frequently, I suggest you to return 0 so that it won't be synchronized to anyone else in case if a player is trying to push it. But that would become hassle if other cars hit them and they were supposed to move, or in cases like an explosion.

I see no way to avoid players pushing the vehicle efficiently on SA-MP right now, other than increasing it's mass (client modification will be required). But since the main post asks that vehicle shouldn't be moved unless it has got a driver, it's better to use "return 0" under OnUnoccupiedVehicleUpdate callback.