Raised This Month: $ Target: $400
 0% 

Float variable/Cvar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mlk27
Veteran Member
Join Date: May 2008
Old 02-01-2009 , 04:07   Float variable/Cvar
Reply With Quote #1

i have a confusion with this type of var/cvar

1. if we create a pcvar float eg

Code:
new Float:g_Health
g_health = register_cvar("amx_health", "20")
Code:
new g_Health2
g_health2 = register_cvar("amx_health2", "20.0")
what's the default value in g_Health and g_Health2 ?


2. which of these is correct to store health value in float?

new Float:g_clienthealth = float(get_user_health(id)); or

new Float:g_clienthealth = get_user_health(id); or

new g_clienthealth = float(get_user_health(id))


3. are all values returned from pev, in float? eg pev_health.

Last edited by Mlk27; 02-01-2009 at 04:11.
Mlk27 is offline
Old 02-01-2009, 04:24
xPaw
This message has been deleted by xPaw. Reason: /me totaly wrong
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-01-2009 , 04:35   Re: Float variable/Cvar
Reply With Quote #3

1. The output of register_cvar() is a pointer. Nothing to do with float. Pointer must be used with get_pcvar_[num|float|string]. [ Edit: It doesn't matter if you write 20 or 20.0, depending if you want an int or float, use get_pcvar_num or get_pcvar_float.

2. The output of get_user_health is an integer number. If you specify the Float: tag ; you have to convert it in float. Only your first example is right. Though using float here is pointless.

3. Float are passed by reference in pev. Depending the pev it can be a float, integer or vector. pev_health is a float ( it means you have to write a float value like 80.0 if you use set_pev ) but you can retrieve its value as int. Basically, if the field of pev is a float you must write a float number to set a value, but you can retrieve the value either as integer either as float. ( If you have for example : pev_fuser1 contening 52.26, pev ( id, pev_fuser1 ) will return 52 and pev ( id, pev_fuser1, MyVar ), MyVar will return 52.26.

Edit : xPaw, you're totaly wrong..

Last edited by Arkshine; 02-01-2009 at 04:45.
Arkshine is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 01:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode