CallRemoteFunction
#1

This code is in my FS
pawn Код:
new Float:spawns[][4] =
{
    {-2335.0002,-1612.7473,483.7189,218.3687}
};
   
forward Float:GetSpawn(coord);
public Float:GetSpawn(coord)
{
    if(coord < 0 || coord > 3) return -1.0;
    return spawns[0][coord];
}
This code is in my GM
pawn Код:
Float:x=CallRemoteFunction("GetSpawn","i",0),
    Float:y=CallRemoteFunction("GetSpawn","i",1),
    Float:z=CallRemoteFunction("GetSpawn","i",2) + 5.0,
    Float:a=CallRemoteFunction("GetSpawn","i",3);
But for some reasons the result it
Код:
-988680192.000000 
0.000000 
5.000000 
0.000000
Reply
#2

you forgot to add the Float: tag in front of CallRemoteFunction otherwise it thinks that it returns an int and tried to convert it to a float

Best would be to add a macro
PHP код:
native Float_GetSpawn(func[] = "GetSpawn"form[] = "i", {Float_}: ...) = CallRemoteFunction;
#define GetSpawn( _GetSpawn(_,_, 
Reply
#3

The code up is kinda very cofusing, can't understand what you want to say.
pawn Код:
Veh[playerid]= CreateVehicle(CallRemoteFunction("MapInfoCheck","ii",CurrentGameMode,4),CallRemoteFunction("GetSpawn","i",0),CallRemoteFunction("GetSpawn","i",1),CallRemoteFunction("GetSpawn","i",2)+5.0,CallRemoteFunction("GetSpawn","i",3), random(256), random(256), -1, 0);
    printf("%f  %f  %f  %f",CallRemoteFunction("GetSpawn","i",0),CallRemoteFunction("GetSpawn","i",1),CallRemoteFunction("GetSpawn","i",2),CallRemoteFunction("GetSpawn","i",3));
    print("PASS");
    PutPlayerInVehicle(playerid, Veh[playerid], 0);
    print("PASS");
    TogglePlayerControllable(playerid,false);
    print("PASS");
    GhostModeTimer[playerid] = CallRemoteFunction("MapInfoCheck","ii",CurrentGameMode,3);
    print("PASS");
    printf("%d",GhostModeTimer[playerid]);
I tried this code and the results in print were perfect but the spawning of vehicle was out of map(bonds) which causes a screen freeze..

Код:
native Float: _GetSpawn(func[] = "GetSpawn", form[] = "i", {Float, _}: ...) = CallRemoteFunction;
where do I add this? And why? I'm using the CallRemoteFunction in other places too but adding a float tag in it would be like?

could you explain it a bit more please.
Reply
#4

You just need to add a Float: tag in front of CallRemoteFunction
PHP код:
Float:Float:CallRemoteFunction("GetSpawn","i",0),
Float:Float:CallRemoteFunction("GetSpawn","i",1),
Float:Float:CallRemoteFunction("GetSpawn","i",2) + 5.0,
Float:Float:CallRemoteFunction("GetSpawn","i",3); 
That would solve your problem but calling it like that looks kind of ugly and you are wasting memory because each constant string you use in a function call gets allocated into the data section (many "GetSpawn" and "i" instead of just one)

Therefor you should redefine the function or create a new function
PHP код:
// 1. Redefinition of CallRemoteFunction with default parameters
native Float_GetSpawn(func[] = "GetSpawn"form[] = "i", {Float_}: ...) = CallRemoteFunction;
// Macro to use the default parameter for func[] and form[]
#define GetSpawn( _GetSpawn(_,_,
// If you use this you need to put it somewhere at the top / include
// 2. Or you create a function - although with that method you lose some speed
FloatGetSpawn(coord) return FloatCallRemoteFunction("GetSpawn""i"coord);
// That could be put anywhere but you would get a forcing reparse warning if you put if after the first usage
// => Should also be somewhere at the top / include to avoid the warning 
After that it would look like that
PHP код:
Float:GetSpawn(0),
Float:GetSpawn(1),
Float:GetSpawn(2) + 5.0,
Float:GetSpawn(3); 
To convert your code just use the search and replace tool

Quote:
Originally Posted by AroseKhanNiazi
Посмотреть сообщение
I tried this code and the results in print were perfect but the spawning of vehicle was out of map(bonds) which causes a screen freeze..
The reason is simple, printf doesn't care which type of data you pass to it
But if you pass an int to a Float parameter like in CreateVehicle the compiler will do that
PHP код:
CreateVehicle(CallRemoteFunction("MapInfoCheck","ii",CurrentGameMode,4),float(CallRemoteFunction("GetSpawn","i",0)),float(CallRemoteFunction("GetSpawn","i",1)),...); 
It tries to convert the returned value of CallRemoteFunction to a float although it is already a float resulting in something undefined
Reply
#5

ah thanks working perfect now.. I never knew this all worked like this thanks for this.

Need to wait 24 hours before giving you rep.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)