Airplane Heading Help! -
SoHidden - 16.10.2012
I have a friend that needs help scripting, so i decided to help him (he has a airplane server) and i need some help. For the pilot, they need to know where they're heading (0 degrees to 360 degrees, 0 being north). Is that even possible, to do such a thing. If it can be done, can someone help me script it...for the pilots to see only. Thanks in advance!
~SoHidden
Re : Airplane Heading Help! -
lelemaster - 16.10.2012
Код:
if(GetVehicleVehicleSeat(playerid) != 0) return 1;
new vehicleid = GetPlayerVehicleID(playerid);
if(GetVehicleModel(vehicleid) == 460 || GetVehicleModel(vehicleid) == 476 || GetVehicleModel(vehicleid) == 511) //and continue like that for all airplanes.
{
new Float:a;
GetVehicleZAngle(vehicleid, a);
if(a > 45 && a < 135)
{
//codes for east
}
else if(a > 135 && a < 225)
{
//codes for south
}
else if(a > 225 && a < 315)
{
//codes for west
}
else if(!(a > 135 && a < 315)
{
//codes for north
}
}
Re: Airplane Heading Help! -
SchurmanCQC - 16.10.2012
Expanding lelemaster's post;
pawn Код:
public OnPlayerUpdate(playerid) {
new Float:p_Angle;
new p_Vehicle;
if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0) {
p_Vehicle = GetPlayerVehicleID(playerid);
GetVehicleZAngle(p_Vehicle, p_Angle);
if(p_Angle > 45 && p_Angle < 135) {
//codes for east
}
else if(p_Angle > 135 && p_Angle< 225) {
//codes for south
}
else if(p_Angle > 225 && p_Angle < 315) {
//codes for west
}
else if(p_Angle > 135 && p_Angle < 315) {
//codes for north
}
}
return 1;
}
Re : Airplane Heading Help! -
lelemaster - 16.10.2012
He shouldn't use OnPlayerUpdate. I think it will take much more CPU usage than a timer of 1 to 2 seconds. It doesn't have to be updated so fast because anyways, a plane isn't changing angle really fast. So I suggest he make a timer for it.
Exemple:
Код:
//top of your script
forward AngleUpdate();
//in ongamemodeinit
SetTimer("AngleUpdate", 1500, 1);
//now the public
public AngleUpdate()
{
for(new i = 0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(GetVehicleVehicleSeat(i) != 0) return 1;
new vehicleid = GetPlayerVehicleID(i);
if(GetVehicleModel(vehicleid) == 460 || GetVehicleModel(vehicleid) == 476 || GetVehicleModel(vehicleid) == 511) //and continue like that for all airplanes.
{
new Float:a;
GetVehicleZAngle(vehicleid, a);
if(a > 45 && a < 135)
{
//codes for east
}
else if(a > 135 && a < 225)
{
//codes for south
}
else if(a > 225 && a < 315)
{
//codes for west
}
else if(!(a > 135 && a < 315)
{
//codes for north
}
}
}
}
return 1;
}
<
By the way Schurman, GetPlayerVehicleSeat will return -1 is the player isn't in a vehicle, so you don't have to put IsPlayerInAnyVehicle.
Re: Airplane Heading Help! -
CoaPsyFactor - 16.10.2012
Well, you should see my OnPlayerUpdate, and server is working fine, with no cpu usage
. But I agree with lelemaster, you can make one timer that will loop through all players, or for every player a timer, but timer that should be counting only when player is in plane, after he leaves the plane, timer should be killed, it's your call, with player update you can make Real Time Angle View, but I don't think that is necessary
Re: Airplane Heading Help! -
SoHidden - 19.10.2012
Thank you all for the help! I owe my friends server to you guys.
~SoHidden