Raised This Month: $ Target: $400
 0% 

Returning a value(SOLVED)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 09-11-2008 , 08:33   Returning a value(SOLVED)
Reply With Quote #1

I tried to get a player's health like this:
PHP Code:
    new Float:health;
    
pevindexpev_healthhealth );
    
floatroundhealth );
    
    return 
health
But compiler says there's a tag mismatch with the return health;.
What am I doing wrong here?
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ

Last edited by Dores; 09-11-2008 at 10:42.
Dores is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-11-2008 , 08:36   Re: Returning a value
Reply With Quote #2

Code:
floatround( health );
    
    return health;

=>
Code:
return floatround( health );

Or I think it's possible to retrieve directly like that :

Code:
return pev( index, pev_health )
Or using too :

Code:
 return get_user_health( index )
__________________

Last edited by Arkshine; 09-11-2008 at 08:38.
Arkshine is offline
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 09-11-2008 , 09:07   Re: Returning a value
Reply With Quote #3

Either do what Arkshine mentions or make your function a float.

Code:
// Example setup Float:MyFunction( VALUE ) {     return float( VALUE ) } // example of usage public plugin_init() {     new Float:test = MyFunction( 100 )     server_print( "MyFunction: %f", test ) }

Last edited by Orangutanz; 09-11-2008 at 11:39.
Orangutanz is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 09-11-2008 , 10:08   Re: Returning a value
Reply With Quote #4

@Orangutanz - new Float:test = MyFunction( 100 );
Alka is offline
[X]-RayCat
Senior Member
Join Date: Sep 2006
Old 09-11-2008 , 10:13   Re: Returning a value
Reply With Quote #5

Quote:
Originally Posted by arkshine View Post
[code]flo
Code:
return pev( index, pev_health )
Why not just use that? Best method. ;)
[X]-RayCat is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 09-11-2008 , 10:25   Re: Returning a value
Reply With Quote #6

Quote:
Originally Posted by [X]-RayCat View Post
Why not just use that? Best method. ;)
Doesn't pev_health returns health as a float?

Quote:
Originally Posted by arkshine
return floatround( health );
I tried that and it returned tag mismatch as well but I guess I simply forgot to tag 'health' with Float:... (Float:health)...

Quote:
Originally Posted by Orangutanz
... make your function a float...
I don't want it to return a float, but an integer (unless I can round the function...).

Well, it appears I'm just too lazy to see if there are any other natvies/stocks/functions like get_user_health(..) which is much more simpler... But I think using the fakemeta way is a bit safer. Am I right?

Should I use:
PHP Code:
      return get_user_healthindex ); 
or
PHP Code:
      new Float:health;
      
pevindexpev_healthhealth );
      
      return 
floatroundhealth ); 
??

Thanks all of you guys for the help, once I figure out what is the best method (amxmodx or fakemeta [or any other module]), i'll +K you all!
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ

Last edited by Dores; 09-11-2008 at 10:32.
Dores is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-11-2008 , 10:36   Re: Returning a value
Reply With Quote #7

Quote:
I tried that and it returned tag mismatch as well but I guess I simply forgot to tag 'health' with Float:... (Float:health)...
No, but since you don't provide the whole code, we can not say if you have missed something. Also, instead of using floatround, use the one of both others methods.

Quote:
But I think the using the fakemeta way is a bit safer
Both are safe. get_user_health() is probably slight faster.
__________________
Arkshine is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 09-11-2008 , 10:42   Re: Returning a value
Reply With Quote #8

Then get_user_health(..) it is!
Thanks a lot arkshine and all the others!
+k

P.S: when i use: return floatround(health); it works fine but i'll go with get_user_health anyways...
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ

Last edited by Dores; 09-11-2008 at 10:45.
Dores is offline
[X]-RayCat
Senior Member
Join Date: Sep 2006
Old 09-11-2008 , 11:20   Re: Returning a value
Reply With Quote #9

Quote:
Originally Posted by dor123 View Post
Then get_user_health(..) it is!
Thanks a lot arkshine and all the others!
+k

P.S: when i use: return floatround(health); it works fine but i'll go with get_user_health anyways...
http://www.ghwchronic.com/pev_research.php

Good information about pevs: String, Float, Integers etc...
[X]-RayCat is offline
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 09-11-2008 , 11:42   Re: Returning a value
Reply With Quote #10

Quote:
Originally Posted by Alka View Post
@Orangutanz - new Float:test = MyFunction( 100 );
Thanks for pointing that out, I was getting excited over Comodo releasing there Internet Suite. So I wrote it in a rush
Orangutanz 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 03:13.


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