Need a funktion - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Need a funktion (
/showthread.php?tid=262065)
Need a funktion -
cruising - 16.06.2011
Hello!
i have this
pawn Код:
if(PlayerToPoint(5.0,playerid,-764.6052,452.9893,10.3964))
{
new vehicleid = GetPlayerVehicleID(playerid);
SetVehicleHealth(vehicleid, 0.0);
return 1;
}
but i dont know were to put it or how to make it to a single funktion.
If you enter this coords in your vehicle, it just blows up, thats it.
Re: Need a funktion -
Sasino97 - 16.06.2011
Somewhere, outside any other function:
pawn Код:
stock ExplodeVehicle(vehicleid)
{
new Float:X,Float:Y,Float:Z;
GetVehiclePos(vehicleid, X, Y, Z);
CreateExplosion(X, Y, Z, 7, 5);
SetVehicleHealth(vehicleid, 0);
}
And when you want to explode a vehicle, put "ExplodeVehicle(vehicleid)" in the event.
EDIT: I've now understood:
pawn Код:
public OnPlayerUpdate(playerid)
{
if(PlayerToPoint(playerid, X, Y, Z) < RADIUS) // Or IsPlayerInRangeOfPoint(playerid, RADIUS, X, Y, Z)
{
ExplodeVehicle(GetPlayerVehicleID(playerid));
}
return 1;
}
Re: Need a funktion -
Lorenc_ - 16.06.2011
Well, PlayerToPoint is old. Theres already a new function called IsPlayerInRangeOfPoint, consider using that because it might be lots more accurate than the default function you have.
Re: Need a funktion -
Sasino97 - 16.06.2011
There's a difference between "PlayerToPoint" and "IsPlayerInRangeOfPoint".
PlayerToPoint returns the distance
IsPlayerInRangeOfPoint returns true or false
Re: Need a funktion -
Simon - 16.06.2011
Quote:
Originally Posted by [GF]Sasino97
There's a difference between "PlayerToPoint" and "IsPlayerInRangeOfPoint".
PlayerToPoint returns the distance
IsPlayerInRangeOfPoint returns true or false
|
Yes, that's correct. You do not need to calculate the distance. The main difference between them is efficiency, not accuracy.
IsPlayerInRangeOfPoint is a lot more efficient for range checking. It compares the squares and does not use an expensive square root operation.