Accessing floats from a different script
#1

I've been scripting for a while now, and I've never needed to access a float that's inside the gamemode, from a filterscript.

I've never had a problem when I access integers.
(I use CallRemoteFunction)

This is just an example of course:
Код:
Gamemode:
public Float: GetPlayerHealthEx(playerid)
{
    new Float: f;
    GetPlayerHealth(playerid, f);
    return f;
}

Filterscript:
CallRemoteFunction("GetPlayerHealthEx", "i", playerid);
Maybe I'm doing something completely stupid and I'm not noticing it, but it's not working.
I tried debugging, and all it did is make me more confused:
Код:
new
    Float: test = 100.0,
    Float: h = GetPlayerHealthEx(playerid);
printf("test: %f", test);
printf("h: %f", h);
if (test > h)
    print("test > h");
What it prints out:
Код:
test: 100.000000
h: 50.000000
The only way I'm getting it to work is by using PVars..
Reply
#2

Have from the gamemode the public function with Float: tag to return the float value and in filterscript:
pawn Код:
new
    health = CallRemoteFunction("GetPlayerHealthEx", "i", playerid);

printf("health from fs: %f", Float: health);
Reply
#3

You could also use PVars ([G/S]etPVarFloat)
Reply
#4

Quote:
Originally Posted by Spmn
Посмотреть сообщение
You could also use PVars ([G/S]etPVarFloat)
I did change it to that before making this thread, but I prefer using normal variables.

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Have from the gamemode the public function with Float: tag to return the float value and in filterscript:
pawn Код:
new
    health = CallRemoteFunction("GetPlayerHealthEx", "i", playerid);

printf("health from fs: %f", Float: health);
Thank you Konstantinos, it works!

"You must spread some Reputation around before giving it to Konstantinos again."
Damn it..
Reply
#5

I give you some advice, do not create a variable equivalent to HP, as with GetPlayerHealthEx function return the float value
pawn Код:
printf("h: %f", h);
change in
pawn Код:
printf("h: %f", GetPlayerHealthEx(playerid));
Reply
#6

I was only giving an example, but creating a variable and setting it to something, and then using that variable multiple times it better than using CallRemoteFunction multiple times.

Код:
new Float: h = CallRemoteFunction("GetPlayerHealthEx", "i", playerid);
if (h ...)
else if (h ...)
printf("%f", h);
SetPlayerHealth(playerid, h);
is better than

Код:
if (CallRemoteFunction("GetPlayerHealthEx", "i", playerid) ...)
else if (CallRemoteFunction("GetPlayerHealthEx", "i", playerid) ...)
printf("%f", CallRemoteFunction("GetPlayerHealthEx", "i", playerid));
SetPlayerHealth(playerid, CallRemoteFunction("GetPlayerHealthEx", "i", playerid));
Reply
#7

The problem is that CallRemoteFunction don't know the correct tag and treats the float as integer

To save memory and the problem with the tag you should either create a function or use native

With native this could look like
PHP код:
// Float: GetPlayerHealthEx(playerid) - returns current health
native Float_GetPlayerHealthEx(func[] = "GetPlayerHealthEx"form[] = "i", {Float_}: ...) = CallRemoteFunction;
#define GetPlayerHealthEx( _GetPlayerHealthEx(_,_, 
Reply
#8

Thank you Nero_3D.
Would there be any difference in speed and memory usage if I do this:
[/code]#define GetPlayerHealthEx(%0) Float: CallRemoteFunction("GetPlayerHealthEx", "i", %0)[/code]
Instead of what you posted?
Reply
#9

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Thank you Nero_3D.
Would there be any difference in speed and memory usage if I do this:
[/code]#define GetPlayerHealthEx(%0) Float: CallRemoteFunction("GetPlayerHealthEx", "i", %0)[/code]
Instead of what you posted?
Speed-wise it would be the same but memory-wise not, if you do it like that both strings would be placed again and again into the memory, with the natives it would be as if you had declared both string global and reuse them each time
Reply
#10

Alright, thanks for the help.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)