03.10.2011, 17:46
CallRemoteFunction only returns integers. I've tested this too and struggled with it, until I found a work-around:
Script: MainScript
Script: OtherScript
In the main-script, you call the function "SomeFunction" and this will call the remote function "OtherScript_GetPlayerData" and send the playerid as a parameter.
In the other script, the function is executed and sends the name of that player and his coordinates back as parameters using another remote call: "MainScript_StorePlayerData".
This remote function (which is located in the main-script) stores the sent data in global variables.
Then the next lines of the function "SomeFunction" are executed to print the player's name and his coordinates.
So you can pass strings and floats to other script using multiple CallRemoteFunction calls.
Script: MainScript
pawn Code:
// Global variables on top of your script
new Float:PlayerX, Float:PlayerY, Float:PlayerZ, PlayerName[24];
// This function stores the name and coordinates of the requested player when using the function OtherScript_GetPlayerData
forward MainScript_StorePlayerData(const pName[], Float:pX, Float:pY, Float:pZ);
public MainScript_StorePlayerData(const pName[], Float:pX, Float:pY, Float:pZ)
{
// Store the name of the player that was passed to this script
format(PlayerName, sizeof(PlayerName), pName);
// Store his coordinates
PlayerX = pX;
PlayerY = pY;
PlayerZ = pZ;
}
SomeFunction(playerid)
{
// Use this function to get data from another script
CallRemoteFunction("OtherScript_GetPlayerData", "i", playerid);
printf("PlayerName: %s", PlayerName);
printf("Coordinates: %f, %f, %f", PlayerX, PlayerY, PlayerZ);
)
pawn Code:
// Put this in the other script
forward OtherScript_GetPlayerData(playerid);
public OtherScript_GetPlayerData(playerid)
{
// Send the playername and his coordinates back to the mainscript for further use
CallRemoteFunction("MainScript_StorePlayerData", "sfff", pData[playerid][PlayerName], pData[playerid][PlayerX], pData[playerid][PlayerY], pData[playerid][PlayerZ]);
}
In the other script, the function is executed and sends the name of that player and his coordinates back as parameters using another remote call: "MainScript_StorePlayerData".
This remote function (which is located in the main-script) stores the sent data in global variables.
Then the next lines of the function "SomeFunction" are executed to print the player's name and his coordinates.
So you can pass strings and floats to other script using multiple CallRemoteFunction calls.