SA-MP Forums Archive
health_name - 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: health_name (/showthread.php?tid=649670)



health_name - ivndosos - 13.02.2018

So I was messing a little around with pawn trying to make something,

What I'm trying to make is adding current player's health on their name, Let's say I have 56 HP so my name will be 56_ivndosos,
That's the code I tried to make but I got a few errors along the way

Код:
			new Float:Healthh,str[128], name[MAX_PLAYER_NAME];
			GetPlayerName(playerid, name, sizeof(name));
			GetPlayerHealth(Healthh);
			format(str, sizeof(str),"%.0f_%s", Healthh,name);
			SetPlayerName(playerid, Healthh,name);
This code is on OnPlayerUpdate callback,

Код:
C:\Users\yan\Desktop\LS DM\gamemodes\DBv1.pwn(1649) : warning 213: tag mismatch
C:\Users\yan\Desktop\LS DM\gamemodes\DBv1.pwn(1651) : error 035: argument type mismatch (argument 2)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
The error lines are

Код:
GetPlayerHealth(Healthh); //1649

SetPlayerName(playerid, Healthh,name); // 1651



Re: health_name - Fratello - 13.02.2018

Read the wiki.


Re: health_name - RogueDrifter - 13.02.2018

First of all, GetPlayerHealth has 2 params :
1- playerid(integer)
2- health (float)
So it should be GetPlayerHealth(playerid, healthh);


Your 2nd problem is thats not how pawn works, SetPlayerName is 2 params only playerid and name string, so if you want to implement a custom string you ought to use format first

PHP код:
format(stringsizeof(string), "%d %s"namehealth);
SetPlayerName(playeridstring); 
Thats an example but i used %d instead of %f for float to avoid spamming the name with all of the numbers although not sure what that will return.


Re: health_name - KayJ - 13.02.2018

PHP код:
new Text3D:HPInfo;
public 
OnGameModeInit()
{
    
// This will fully disable all player nametags
    // (including health and armour bars)
    
ShowNameTags(0);
}
public 
OnPlayerSpawn(playerid)
{
    new 
HPstring[120];
    new 
Float:pHealth;
    new 
Float:pArmour;
    
GetPlayerHealth(playeridpHealth);
    
GetPlayerArmour(playeridpArmour);
    
format(HPstring,sizeof(HPstring),"%s{FFFFFF}%.0f hp, %.0f armour"pHealthpArmour);
    
Update3DTextLabelText(HPInfo0xFFFFFFFFHPstring);
    return 
1;
}
public 
OnPlayerUpdate(playerid)
{
    new 
HPstring[120];
    new 
Float:pHealth;
    new 
Float:pArmour;
    
GetPlayerHealth(playeridpHealth);
    
GetPlayerArmour(playeridpArmour);
    
format(HPstring,sizeof(HPstring),"%s{FFFFFF}%.0f hp, %.0f armour"pHealthpArmour);
    
Update3DTextLabelText(HPInfo0xFFFFFFFFHPstring);
    return 
1;

Don't use SetPlayerName as it'll save on player's disconnection which can cause trouble.


Re: health_name - ivndosos - 13.02.2018

Quote:
Originally Posted by KayJ
Посмотреть сообщение
PHP код:
new Text3D:HPInfo;
public 
OnGameModeInit()
{
    
// This will fully disable all player nametags
    // (including health and armour bars)
    
ShowNameTags(0);
}
public 
OnPlayerSpawn(playerid)
{
    new 
HPstring[120];
    new 
Float:pHealth;
    new 
Float:pArmour;
    
GetPlayerHealth(playeridpHealth);
    
GetPlayerArmour(playeridpArmour);
    
format(HPstring,sizeof(HPstring),"%s{FFFFFF}%.0f hp, %.0f armour"pHealthpArmour);
    
Update3DTextLabelText(HPInfo0xFFFFFFFFHPstring);
    return 
1;
}
public 
OnPlayerUpdate(playerid)
{
    new 
HPstring[120];
    new 
Float:pHealth;
    new 
Float:pArmour;
    
GetPlayerHealth(playeridpHealth);
    
GetPlayerArmour(playeridpArmour);
    
format(HPstring,sizeof(HPstring),"%s{FFFFFF}%.0f hp, %.0f armour"pHealthpArmour);
    
Update3DTextLabelText(HPInfo0xFFFFFFFFHPstring);
    return 
1;

Don't use SetPlayerName as it'll save on player's disconnection which can cause trouble.
Yeah but I don't want it to be a text label I want it to be as his name


Re: health_name - PepsiCola23 - 13.02.2018

PHP код:
            format(strsizeof(str),"%.0f_%s"Healthh,name);
            
SetPlayerName(playeridstr); 



Re: health_name - ivndosos - 13.02.2018

This seems to be working

Код:
public OnPlayerSpawn(playerid)
{
  	new Float:hp, string[50], name[MAX_PLAYER_NAME];
	GetPlayerHealth(playerid,hp);
	GetPlayerName(playerid, name, sizeof(name));
	format(string, sizeof(string), "%.0f_%s", hp, name);
	SetPlayerName(playerid, string);
In game it shows 100_invdosos

But the problem is, it doesn't update! Even on the onplayerupdate callback..


Re: health_name - PepsiCola23 - 13.02.2018

if you want to make it update,you gotta make a function for that.


Re: health_name - ivndosos - 13.02.2018

mind giving an example?


Re: health_name - Mugala - 13.02.2018

you have to create a timer or just simply add a code in OnPlayerUpdate
the code is same as your OnPlayerSpawn code.

for example:
PHP код:
public OnPlayerUpdate(playerid)
{
    new 
Float:hpstring[50], name[MAX_PLAYER_NAME];
    
GetPlayerHealth(playerid,hp);
    
GetPlayerName(playeridnamesizeof(name));
    
format(stringsizeof(string), "%.0f_%s"hpname);
    
SetPlayerName(playeridstring);
    return 
1;

EDIT: if you have a float problems, than use floatround, like this code
PHP код:
public OnPlayerUpdate(playerid)
{
    new 
Float:hpstring[50], name[MAX_PLAYER_NAME];
    
GetPlayerHealth(playerid,hp);
    
GetPlayerName(playeridnamesizeof(name));
    
format(stringsizeof(string), "%d_%s"floatround(hpfloatround_round), name);
    
SetPlayerName(playeridstring);
    return 
1;