Vehicle Health
#1

Hello, ima making a script, who shows the vehicle's health with TextDraw commands. The problem is when i get in car , the text dont appear and nothing shows, i maked it if the car health is more than 0,250, 500 and 750 to have different colours at the text. Here is the code: I put that in public OnPlayerConnect(playerid):
Код:
public OnPlayerConnect(playerid)
{
	SendClientMessage(playerid, 0x9955DEEE, "Welcome to Ex7r3m3 pLaY Bulgaria!Type /help for more information!");
    new pNam[30], string[128];
    GetPlayerName(playerid, pNam, 30);
    format(string, 256, "%s влезна в сървара.", pNam);
    SendClientMessageToAll(0xAFAFAFAA,string);
   	new Float:vehiclehealth;
	new VehHealth;
    new vehicleid = GetPlayerVehicleID(playerid);
	VehHealth = GetVehicleHealth(vehicleid, vehiclehealth);
	format(string, sizeof(string), "Vehicle Health %i",VehHealth);
	VehicleHealthText = TextDrawCreate(240.0, 580.0, string);
	TextDrawTextSize(VehicleHealthText, 12.0, 13.6);
	TextDrawFont(VehicleHealthText, 1);
 	TextDrawSetString(VehicleHealthText, string);
    TextDrawAlignment(VehicleHealthText,0);
    TextDrawBackgroundColor(VehicleHealthText,0x000000ff);
    TextDrawLetterSize(VehicleHealthText,0.499999,0.899999);
    TextDrawColor(VehicleHealthText,0xffffffff);
    TextDrawSetOutline(VehicleHealthText,1);
    TextDrawSetProportional(VehicleHealthText,1);
    TextDrawSetShadow(VehicleHealthText,1);

	if(VehHealth > 0)
	{
	    TextDrawColor(VehicleHealthText, 0xFF0000FF);
	    return 0;
	}
	if(VehHealth > 250)
	{
        TextDrawColor(VehicleHealthText, 0xFD7E00FF);
	    return 0;
	}
	if(VehHealth > 500)
	{
        TextDrawColor(VehicleHealthText, 0xF2FF00FF);
	    return 0;
	}
	if(VehHealth > 750)
	{
        TextDrawColor(VehicleHealthText, 0x05E600FF);
	    return 0;
	}
	return 1;
}
And that is in public OnPlayerEnterVehicle and public OnPlayerExitVehicle:
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new vNam, string[128];
    vNam = GetVehicleModel(vehicleid);
    format(string, sizeof(string), "Качихте се в %i",vNam);
    SendClientMessage(playerid, 0x0039FFFF, string);
 	TextDrawShowForPlayer(playerid, VehicleHealthText);
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    new vNam, string[128];
    vNam = GetVehicleModel(vehicleid);
    format(string, sizeof(string), "Слязохте от %i",vNam);
    SendClientMessage(playerid, 0x0039FFFF, string);
    TextDrawHideForPlayer(playerid, VehicleHealthText);
	return 1;
}
I puted that at the begin of script :
Код:
new Text:VehicleHealthText;
Reply
#2

why don't u use /dl command for health
Reply
#3

You cannot use
pawn Код:
var = GetVehicleHealth(vehicleid, Float: health);
!!!
Unlike other functions, the vehicle's health will be stored in variable health passed by reference and not in var!
So, your code should look something like this:
pawn Код:
Float: vhealth;
GetVehicleHealth(vehicleid, vhealth); // storing the value in vhealth
new string[128];
format(string, sizeof (string), "Your vehicle's health is %f", vhealth); // you could use string for TextDrawSetString or SendClientMessage, etc.
Reply
#4

Quote:
Originally Posted by jiwan
Посмотреть сообщение
why don't u use /dl command for health
I dont want it with command, just i am making a fun server and it will be cool when player get in veh to show him health, km/h and vehicle name , which will be mine second FS By The Way can you help me to solve this problem anyway? Thank you about the reply
Reply
#5

sry for 2nd thread, but the result is the same, i checked everything and i have just this warnings...:
Код:
D:\server\gamemodes\lvdm.pwn(153) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\gamemodes\lvdm.pwn(198) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\gamemodes\lvdm.pwn(207) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\gamemodes\lvdm.pwn(218) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\gamemodes\lvdm.pwn(230) : warning 219: local variable "string" shadows a variable at a preceding level
D:\server\gamemodes\lvdm.pwn(2416) : warning 219: local variable "str" shadows a variable at a preceding level
D:\server\gamemodes\lvdm.pwn(2423) : warning 219: local variable "str" shadows a variable at a preceding level
D:\server\gamemodes\lvdm.pwn(2430) : warning 219: local variable "string" shadows a variable at a preceding level
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

8 Warnings.
Reply
#6

This warnings can be solved by renaming string and str, because these values are defined somewhere at top of the script (e.g. before first public, that youve in your script).

LetsOWN.
Reply
#7

I solved them, but still dont work...
Reply
#8

Your code has many mistakes... starting from that you missed
pawn Код:
new Text:VehicleHealthText
(goes at the top of your gamemode)


Secondly, you should create the textdraw under OnGameModeInit, without using a string!
pawn Код:
VehicleHealthText = TextDrawCreate(240.0, 580.0, "None");
    TextDrawTextSize(VehicleHealthText, 12.0, 13.6);
    TextDrawFont(VehicleHealthText, 1);
    TextDrawSetString(VehicleHealthText, string);
    TextDrawAlignment(VehicleHealthText,0);
    TextDrawBackgroundColor(VehicleHealthText,0x000000ff);
    TextDrawLetterSize(VehicleHealthText,0.499999,0.899999);
    TextDrawColor(VehicleHealthText,0xffffffff);
    TextDrawSetOutline(VehicleHealthText,1);
    TextDrawSetProportional(VehicleHealthText,1);
    TextDrawSetShadow(VehicleHealthText,1);
Then you will do a new callback that will check the vehicle health, there you can also make the color changing, and setting the textdraw string to display the vehicle health!
Reply
#9

About "new Text:VehicleHealthText" I already hav it "new Text:VehicleHealthText;"... and still dont work, just dont show .... it can be from the X and Y text positions? look my callback :
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(!IsPlayerInAnyVehicle(playerid) == false)
	{
 		GetVehicleHealth(vehicleid, vhealth);
 		format(str1, sizeof (str1), "Vehicle Health:%f", vhealth);
 		TextDrawSetString(VehicleHealthText, str1);
		TextDrawTextSize(VehicleHealthText, 2.0, 3.6);
		TextDrawFont(VehicleHealthText, 1);
 		TextDrawShowForPlayer(playerid, VehicleHealthText);
		if(vhealth > 0)
		{
	    	TextDrawColor(VehicleHealthText, 0xFF0000FF);
	    	return 1;
		}
		if(vhealth > 250)
		{
    	    TextDrawColor(VehicleHealthText, 0xFD7E00FF);
	    	return 1;
		}
		if(vhealth > 500)
		{
 	       TextDrawColor(VehicleHealthText, 0xF2FF00FF);
	    	return 1;
		}
		if(vhealth > 750)
		{
   		   TextDrawColor(VehicleHealthText, 0x05E600FF);
			return 1;
		}
		return 0;
	}
	return 1;
}
And i use/copy your script on your last post in OnGameModeInIt public
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)