13.08.2010, 22:35
(
Last edited by pmk1; 15/01/2012 at 04:15 PM.
)
Hello Guys, There for my first tutorial, I Will Edit mckennie's speedo tutorial, to make it call with a timer and I'll show you how to create a Vehicle Health system(Health'o'Meter).
Here is his tutorial:
The Purpose of this tutorial?
-no (or less) lag when there are alot of players on your server;
-will teach you a bit on how to use timers;
-will get you better in pawno!
First of all, create a text draw at the top, under defines, just like in mckennie's script.
Secondly, in public OnPlayerConnectCallback, add this anywhere:
Now that we have the textdraw ready, we must add the speedo script.
at the top, again under defines, add:
this will allow our custom callback that we'll do in the next steps to work.
We will now create a timer, to call the speedo at each 10 milliseconds.
Add this somewhere under ongamemodeinit (or onfilterscriptinit if it's a filterscript)
And Finally, we'll create the public speedometer callback, so that all we've done yet can work!
GetVehicleVelocity will get the speed of the player in the vehicle
final_speed = floatsqroot will then show the speed in KMH or MPH (depending on which you choose)
that's it for the speedo! Now go try it in-game to see if it works :P
Now we're on for the second part; how to creater a vehicle health meter with a timer.
Just like for the Speedo, add this at the top:
Now, under public OnPlayerConnect callback, add this:
The Textdraw is now ready for use! Lets go for the next step.
In order to make the health system work, we have to add this to our public Speedometer callback:
This will be the variables to get vehicle's health for the next steps.
Again under public speedometer callback, find:
under it, add:
Now, again under public speedometer callback search for
Right under it, add
This will make in sort that the health meter doesnt show when on foot.
So now, the Health'o'Meter should work!
Confused? here's the whole script:
Thanks for reading! I hope it can help you and +rep me if it did :P
(Please tell me if i made any mistakes)
Here is his tutorial:
The Purpose of this tutorial?
-no (or less) lag when there are alot of players on your server;
-will teach you a bit on how to use timers;
-will get you better in pawno!
First of all, create a text draw at the top, under defines, just like in mckennie's script.
Code:
new Text:SPEEDOS[MAX_PLAYERS];
Code:
SPEEDOS[playerid] = TextDrawCreate(10.0,200.0," "); TextDrawShowForPlayer(playerid,SPEEDOS[playerid]);
at the top, again under defines, add:
Code:
forward Speedometer(playerid);
We will now create a timer, to call the speedo at each 10 milliseconds.
Add this somewhere under ongamemodeinit (or onfilterscriptinit if it's a filterscript)
Code:
SetTimer("Speedometer", 100, true); //change 100 to what pleases you,but i'd say it's better to keep it like that.
Code:
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); 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))*250.666667; // 250.666667 = kmph // 199,4166672 = mph final_speed_int = floatround(final_speed,floatround_round); format(speed_string,256,"Speed: %i",final_speed_int); TextDrawSetString(SPEEDOS[playerid], speed_string); } else { TextDrawSetString(SPEEDOS[playerid], " "); } return 1; }
final_speed = floatsqroot will then show the speed in KMH or MPH (depending on which you choose)
that's it for the speedo! Now go try it in-game to see if it works :P
Now we're on for the second part; how to creater a vehicle health meter with a timer.
Just like for the Speedo, add this at the top:
Code:
new Text:HEALTH[MAX_PLAYERS];
Code:
HEALTH[playerid] = TextDrawCreate(10.0,200.0," "); TextDrawShowForPlayer(playerid,HEALTH[playerid]);
In order to make the health system work, we have to add this to our public Speedometer callback:
Code:
new Float:vehicle_health,final_vehicle_health,health_string[256];
Again under public speedometer callback, find:
Code:
if(vehicleid != 0) {
Code:
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);
Code:
else { TextDrawSetString(SPEEDOS[playerid], " ");
Code:
TextDrawSetString(HEALTH[playerid], " ");
So now, the Health'o'Meter should work!
Confused? here's the whole script:
Code:
/*------------------------------------------------------- Basic Speed'o'Meter & Health'o'Meter Script By Pmk1 -------------------------------------------------------*/ #define FILTERSCRIPT //------------------------------------------------------- #include <a_samp> //------------------------------------------------------- new Text:SPEEDOS[MAX_PLAYERS]; new Text:HEALTH[MAX_PLAYERS]; //------------------------------------------------------- forward Speedometer(playerid); //------------------------------------------------------- public OnFilterScriptInit() { SetTimer("Speedometer", 100, true); //change 100 to what pleases you,but i'd say it's better to keep it like that. 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))*250.666667; // 250.666667 = kmph // 199,4166672= mph final_speed_int = floatround(final_speed,floatround_round); format(speed_string,256,"Speed: %i",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; } //-------------------------------------------------------
(Please tell me if i made any mistakes)