Detecting nearby Andromadas - 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: Detecting nearby Andromadas (
/showthread.php?tid=372149)
Detecting nearby Andromadas -
Prostilov - 25.08.2012
Hello, I'm trying to make a vehicle transportation system (vehicle goes into an andromada and is then flown to another airport in San Andreas)
The thing that I am having difficulties with, is detecting if there are any Andromadas near, this my code (when the player presses the JUMP key).
Код:
if(newkeys == KEY_JUMP)
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(GetVehicleModel(i) == 592)
{
GetVehiclePos(i, Float:ax, Float:ay, Float:az);
}
}
if(IsPlayerInAnyVehicle(playerid))
{
if(!IsAPlane(newcar))
{
if(GetVehicleDistanceFromPoint(newcar, Float:ax, Float:ay, Float:az) < 20)
{
SendClientMessage(playerid, COLOR_GREEN, "IT WORKS!!");
}
SendClientMessage(playerid, COLOR_RED, "You are not near an Andromada!");
}
}
SendClientMessage(playerid, COLOR_RED, "You are not in any vehicle!");
}
Re: Detecting nearby Andromadas -
Jeffry - 25.08.2012
Hey,
pawn Код:
if(newkeys == KEY_JUMP)
{
if(IsPlayerInAnyVehicle(playerid))
{
new Float:ax,Float:ay,Float:az,Float:px,Float:py,Float:pz, ID=-1, Float:Distance = 20.0; //Max. Distamce to the Adnromada. (Set to 20.0)
GetPlayerPos(playerid,px,py,pz);
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(GetVehicleModel(i) == 592)
{
GetVehiclePos(i, Float:ax, Float:ay, Float:az);
new Float:tmp=floatsqroot( ( (ax-px)*(ax-px) ) + ( (ay-py)*(ay-py) ) + ( (az-pz)*(az-pz) ) );
if(Distance>tmp)
{
Distance=tmp;
ID=i;
}
}
}
if(ID != -1) SendClientMessage(playerid, COLOR_GREEN, "IT WORKS!!");
else SendClientMessage(playerid, COLOR_RED, "You are not near an Andromada!");
}
}
else SendClientMessage(playerid, COLOR_RED, "You are not in any vehicle!");
}
Try this. I use a similar thing for my Property System.
Cheers!
Re: Detecting nearby Andromadas -
Prostilov - 25.08.2012
Hello, I have replaced my piece of code with yours.
But now, when I tried to compile it, the compiler crashed, do you know what may be causing this?
Re: Detecting nearby Andromadas -
Prostilov - 25.08.2012
Never mind, there was a bracket too much.
But, it works, thank you very much! REP+