SA-MP Forums Archive
Adding altitude to this script. - 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: Adding altitude to this script. (/showthread.php?tid=258682)



Adding altitude to this script. - Odyssey - 31.05.2011

Ok, yes, I am a noob for posting so many help threads. But, eh, it's learning, I'm sure I will get better. But, I'm using this script, which displays the health and speed. but now I want the altitude.

pawn Код:
#include <a_samp>
#include <JunkBuster>

#define FILTERSCRIPT

#include <a_samp>

new Text:SPEEDOS[MAX_PLAYERS];
new Text:HEALTH[MAX_PLAYERS];

forward Speedometer(playerid);

public OnFilterScriptInit()
{
    SetTimer("Speedometer", 100, true);
    return 1;
}

public OnPlayerConnect(playerid)
{
    SPEEDOS[playerid] = TextDrawCreate(10.0,200.0," ");
    TextDrawShowForPlayer(playerid,SPEEDOS[playerid]);
    HEALTH[playerid] = TextDrawCreate(10.0,180.0," ");
    TextDrawShowForPlayer(playerid,HEALTH[playerid]);
    return 1;
}

public Speedometer(playerid)
{
    new vehicleid,Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[256],final_speed_int;
    vehicleid = GetPlayerVehicleID(playerid);
    new Float:vehicle_health,final_vehicle_health,health_string[256];
    if(vehicleid != 0)
    {
        GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
        final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*199.4166672; // 250.666667 = kmph  // 199,4166672= mph
        final_speed_int = floatround(final_speed,floatround_round);
        format(speed_string,256,"Speed: %i MPH",final_speed_int);
        TextDrawSetString(SPEEDOS[playerid], speed_string);
        GetVehicleHealth(vehicleid,vehicle_health);
        final_vehicle_health = floatround(floatround(vehicle_health - 250)/ 7.5); //This will make the health show at 100 when the vehicle is not damaged and at 0 when it is in fire.
        format(health_string,256,"Health: %i", final_vehicle_health);
        TextDrawSetString(HEALTH[playerid], health_string);
    }
    else
    {
        TextDrawSetString(SPEEDOS[playerid], " ");
        TextDrawSetString(HEALTH[playerid], " ");
    }
    return 1;
}
As its a flying server what I am creating, I will need something to display the altitude in GTA Meters.

Any help is much aperciated. Thanks.


Re: Adding altitude to this script. - Mike Garber - 31.05.2011

pawn Код:
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,X,Y,Z);
// or
GetVehiclePos(vehicleid,X,Y,Z);

// Z is the altitude



Re: Adding altitude to this script. - Odyssey - 31.05.2011

So where dose that code go into this?

pawn Код:
#include <a_samp>
#include <JunkBuster>

#define FILTERSCRIPT

#include <a_samp>

new Text:SPEEDOS[MAX_PLAYERS];
new Text:HEALTH[MAX_PLAYERS];
new Text:ALT[MAX_PLAYERS]; //Added this

forward Speedometer(playerid);

public OnFilterScriptInit()
{
    SetTimer("Speedometer", 100, true);
    return 1;
}

public OnPlayerConnect(playerid)
{
    SPEEDOS[playerid] = TextDrawCreate(10.0,200.0," ");
    TextDrawShowForPlayer(playerid,SPEEDOS[playerid]);
    HEALTH[playerid] = TextDrawCreate(10.0,180.0," ");
    TextDrawShowForPlayer(playerid,HEALTH[playerid]);
    ALT[playerid] = TextDrawCreate(10.0,160.0," "); //Added this
    TextDrawShowForPlayer(playerid,ALT[playerid]); //Added this
    return 1;
}

public Speedometer(playerid)
{
    new vehicleid,Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[256],final_speed_int;
    vehicleid = GetPlayerVehicleID(playerid);
    new Float:vehicle_health,final_vehicle_health,health_string[256];
    if(vehicleid != 0)
    {
        GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
        final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*199.4166672; // 250.666667 = kmph  // 199,4166672= mph
        final_speed_int = floatround(final_speed,floatround_round);
        format(speed_string,256,"Speed: %i MPH",final_speed_int);
        TextDrawSetString(SPEEDOS[playerid], speed_string);
        GetVehicleHealth(vehicleid,vehicle_health);
        final_vehicle_health = floatround(floatround(vehicle_health - 250)/ 7.5); //This will make the health show at 100 when the vehicle is not damaged and at 0 when it is in fire.
        format(health_string,256,"Health: %i", final_vehicle_health);
        TextDrawSetString(HEALTH[playerid], health_string);
    }
    else
    {
        TextDrawSetString(SPEEDOS[playerid], " ");
        TextDrawSetString(HEALTH[playerid], " ");
        TextDrawSetString(ALT[playerid], " "); //Added this
    }
    return 1;
}



Re: Adding altitude to this script. - futuretrucker - 01.06.2011

You could make it a stock then use it in the text draw from there.


Re: Adding altitude to this script. - Odyssey - 01.06.2011

I dont understand how to use thoose things.


Re: Adding altitude to this script. - futuretrucker - 01.06.2011

Heres a stock you can try. I don't know if it will work tho.

pawn Код:
stock Find(playerid)
{
    new Float:X,Float:Y,Float:Z;
    GetPlayerPos(playerid,X,Y,Z);
    return X,Y,Z;
}



Re: Adding altitude to this script. - Odyssey - 01.06.2011

But how do I put that into my script?


Re: Adding altitude to this script. - Snipa - 01.06.2011

You just add it outside a callback.


Re: Adding altitude to this script. - Odyssey - 01.06.2011

pawn Код:
#include <a_samp>
#include <JunkBuster>

#define FILTERSCRIPT

#include <a_samp>

new Text:SPEEDOS[MAX_PLAYERS];
new Text:HEALTH[MAX_PLAYERS];
new Text:ALT[MAX_PLAYERS];

forward Speedometer(playerid);

public OnFilterScriptInit()
{
    SetTimer("Speedometer", 100, true);
    return 1;
}

public OnPlayerConnect(playerid)
{
    SPEEDOS[playerid] = TextDrawCreate(10.0,200.0," ");
    TextDrawShowForPlayer(playerid,SPEEDOS[playerid]);
    HEALTH[playerid] = TextDrawCreate(10.0,180.0," ");
    TextDrawShowForPlayer(playerid,HEALTH[playerid]);
    ALT[playerid] = TextDrawCreate(10.0,160.0," "); //Added this
    TextDrawShowForPlayer(playerid,ALT[playerid]); //Added this
    return 1;
}

public Speedometer(playerid)
{
    new vehicleid,Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[256],final_speed_int;
    vehicleid = GetPlayerVehicleID(playerid);
    new Float:vehicle_health,final_vehicle_health,health_string[256];
    if(vehicleid != 0)
    {
        GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
        final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*199.4166672; // 250.666667 = kmph  // 199,4166672= mph
        final_speed_int = floatround(final_speed,floatround_round);
        format(speed_string,256,"Speed: %i MPH",final_speed_int);
        TextDrawSetString(SPEEDOS[playerid], speed_string);
        GetVehicleHealth(vehicleid,vehicle_health);
        final_vehicle_health = floatround(floatround(vehicle_health - 250)/ 7.5); //This will make the health show at 100 when the vehicle is not damaged and at 0 when it is in fire.
        format(health_string,256,"Health: %i", final_vehicle_health);
        TextDrawSetString(HEALTH[playerid], health_string);
    }
    else
    {
        TextDrawSetString(SPEEDOS[playerid], " ");
        TextDrawSetString(HEALTH[playerid], " ");
        TextDrawSetString(ALT[playerid], " "); //Added this
    }
    return 1;
}

stock Find(playerid)
{
    new Float:X,Float:Y,Float:Z;
    GetPlayerPos(playerid,X,Y,Z);
    return X,Y,Z;
}
Full code. Now what?


Re: Adding altitude to this script. - Donya - 01.06.2011

try this http://pastebin.com/TMxPEXDj