AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Returning a value(SOLVED) (https://forums.alliedmods.net/showthread.php?t=77351)

Dores 09-11-2008 08:33

Returning a value(SOLVED)
 
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?:?

Arkshine 09-11-2008 08:36

Re: Returning a value
 
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 )

Orangutanz 09-11-2008 09:07

Re: Returning a value
 
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 ) }

Alka 09-11-2008 10:08

Re: Returning a value
 
@Orangutanz - new Float:test = MyFunction( 100 );

[X]-RayCat 09-11-2008 10:13

Re: Returning a value
 
Quote:

Originally Posted by arkshine (Post 684323)
[code]flo
Code:

return pev( index, pev_health )

Why not just use that? Best method. ;)

Dores 09-11-2008 10:25

Re: Returning a value
 
Quote:

Originally Posted by [X]-RayCat (Post 684351)
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?:o

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!:up:

Arkshine 09-11-2008 10:36

Re: Returning a value
 
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.

Dores 09-11-2008 10:42

Re: Returning a value
 
Then get_user_health(..) it is!:mrgreen:
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...

[X]-RayCat 09-11-2008 11:20

Re: Returning a value
 
Quote:

Originally Posted by dor123 (Post 684356)
Then get_user_health(..) it is!:mrgreen:
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...

Orangutanz 09-11-2008 11:42

Re: Returning a value
 
Quote:

Originally Posted by Alka (Post 684348)
@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 :mrgreen:


All times are GMT -4. The time now is 03:13.

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