Anti vehicle teleport question - 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: Anti vehicle teleport question (
/showthread.php?tid=484463)
Anti vehicle teleport question -
dusk - 30.12.2013
Hello, recently some annoying individuals teleported all unused vehicles to the same spot causing crashes for everyone near. And that got me where I am now.
I created(I believe I did) something that will help my server to avoid similiar situations.
I used the idea from this:
https://sampforum.blast.hk/showthread.php?tid=272182 + the notes from JernejL in that same topic.
I want opinions. How effective will it be(if I will at all)?
I hooked the SetVehiclePos function
pawn Код:
stock AC_SetVehiclePos(vehicleid,Float:x,Float:y,Float:z)
{
RealVehiclePositions[vehicleid][0] = x;
RealVehiclePositions[vehicleid][1] = y;
RealVehiclePositions[vehicleid][2] = z;
return SetVehiclePos(vehicleid, x, y, z);
}
#if defined _ALS_SetVehiclePos
#undef SetVehiclePos
#else
#define _ALS_SetVehiclePos
#endif
#define SetVehiclePos AC_SetVehiclePos
pawn Код:
public OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat)
{
new time = gettime();
if(time >LastVehicleACCheck[vehicleid])
{
LastVehicleACCheck[vehicleid] = time;
new Float:x,Float:y,Float:z;
GetVehiclePos(vehicleid, x, y, z);
if(RealVehiclePositions[vehicleid][0] == 0.0 && RealVehiclePositions[vehicleid][1] == 0.0 && RealVehiclePositions[vehicleid][2] == 0.0)
{
RealVehiclePositions[vehicleid][0] = x;
RealVehiclePositions[vehicleid][1] = y;
RealVehiclePositions[vehicleid][2] = z;
return;
}
new Float:distance = GetVehicleDistanceFromPoint(vehicleid,RealVehiclePositions[vehicleid][0],RealVehiclePositions[vehicleid][1],RealVehiclePositions[vehicleid][2]);
if(distance > MAX_VEHICLE_DISTANCE_CHANGE)
{
SetVehiclePos(vehicleid,RealVehiclePositions[vehicleid][0],RealVehiclePositions[vehicleid][1],RealVehiclePositions[vehicleid][2]);
}
RealVehiclePositions[vehicleid][0] = x;
RealVehiclePositions[vehicleid][1] = y;
RealVehiclePositions[vehicleid][2] = z;
}
return;
}
Funny, when a player exited the vehicle it would be set back to it's position...so I added this OnPlayerExitVehicle:
pawn Код:
new Float:x,Float:y,Float:z;
GetVehiclePos(vehicleid,x,y,z);
RealVehiclePositions[vehicleid][0] = x;
RealVehiclePositions[vehicleid][1] = y;
RealVehiclePositions[vehicleid][2] = z;
pawn Код:
public OnVehicleSpawn(vehicleid)
{
new Float:x,Float:y,Float:z;
GetVehiclePos(vehicleid, x, y, z);
RealVehiclePositions[vehicleid][0] = x;
RealVehiclePositions[vehicleid][1] = y;
RealVehiclePositions[vehicleid][2] = z;
return 1;
}
All feedback about the code will be appreciated.
(Now that I think about it, perhaps this should have been in the "Discussion" forum? But I'm actually asking for help, so I'll leave it here).
Re: Anti vehicle teleport question -
dusk - 01.01.2014
bump