SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/02/2018, 05:14 AM   #1
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 288
Reputation: 15
Default health_name

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

Code:
			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,

Code:
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 (c) 1997-2006, ITB CompuPhase


1 Error.
The error lines are

Code:
GetPlayerHealth(Healthh); //1649

SetPlayerName(playerid, Healthh,name); // 1651
ivndosos is online now   Reply With Quote
Old 13/02/2018, 05:46 AM   #2
Fratello
Huge Clucker
 
Fratello's Avatar
 
Join Date: May 2016
Location: Howard University
Posts: 316
Reputation: 38
Default Re: health_name

Read the wiki.
__________________
"It's not what you expect from life; But what life expect from you!"
Fratello is offline   Reply With Quote
Old 13/02/2018, 06:18 AM   #3
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,124
Reputation: 187
Default Re: health_name

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 Code:
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.
__________________
Quote:
Originally Posted by RogueDrifter
-For fuck's sake people stop deleting your help threads you're just losing chances of ever getting help again...
[Tutorial]:Anti-cheat guide ||Mini-game 101||VC/LC maps install

[Github]:Link [Pastebin]:Link [Forum]:Link [Server]:Link [Discord]:Link



Quote:
Originally Posted by RogueDrifter
-I'm now available to script small scripts for payments done through paypal.
RogueDrifter is online now   Reply With Quote
Old 13/02/2018, 07:15 AM   #4
KayJ
Gangsta
 
KayJ's Avatar
 
Join Date: Apr 2014
Location: India
Posts: 687
Reputation: 53
Default Re: health_name

PHP Code:
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.
__________________
We've a community of 15 people who do crazy things, from mapping to playing. Join us and contribute, Here (Not currently working for anyone for anything, will work after april/may).

SA:MP Wikipedia Profile | My upcoming project(s) | My Project(s) Media

Quote:
Originally Posted by Infinity View Post
Why!? Why do people still use #pragma tabsize 0?! This should have been banned, burned and thrown into a deep pit.
KayJ is offline   Reply With Quote
Old 13/02/2018, 10:29 AM   #5
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 288
Reputation: 15
Default Re: health_name

Quote:
Originally Posted by KayJ View Post
PHP Code:
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
ivndosos is online now   Reply With Quote
Old 13/02/2018, 10:47 AM   #6
PepsiCola23
Gangsta
 
Join Date: May 2015
Posts: 512
Reputation: 2
Default Re: health_name

PHP Code:
            format(strsizeof(str),"%.0f_%s"Healthh,name);
            
SetPlayerName(playeridstr); 
PepsiCola23 is offline   Reply With Quote
Old 13/02/2018, 11:20 AM   #7
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 288
Reputation: 15
Default Re: health_name

This seems to be working

Code:
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..
ivndosos is online now   Reply With Quote
Old 13/02/2018, 11:35 AM   #8
PepsiCola23
Gangsta
 
Join Date: May 2015
Posts: 512
Reputation: 2
Default Re: health_name

if you want to make it update,you gotta make a function for that.
PepsiCola23 is offline   Reply With Quote
Old 13/02/2018, 11:50 AM   #9
ivndosos
Huge Clucker
 
ivndosos's Avatar
 
Join Date: Sep 2014
Location: Russian Federation, Kaliningrad.
Posts: 288
Reputation: 15
Default Re: health_name

mind giving an example?
ivndosos is online now   Reply With Quote
Old 13/02/2018, 12:49 PM   #10
Mugala
Gangsta
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: behind u
Posts: 529
Reputation: 23
Default Re: health_name

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 Code:
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 Code:
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;

__________________
here to help
Mugala is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 02:55 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.