Returning strings or floats
#1

Hi,

I've got a problem.

I'm using multiple filterscripts to split up some stuff.
Speedometer script, admin script and housing/businesses script.
This way, I can later re-use those systems easily when I would create a new gamemode.

But by doing this, alot of data must be transferred between those scripts.
I'm using CallRemoteFunction to do this.
In the speedometer script for example, I need to know if a player is an admin before a command may be used in the speedometer script.
So, from within the speedometer script, I'm calling a remote function inside the admin script, which returns 1 or -1 to the speedometer script.
This works fine as they are integers.

But I don't seem to be able to return floats or strings this way.

Inside the speedometer script:
Code:
if (CallRemoteFunction("Admin_GetPlayerLevel", "i", playerid) > 3)
SendClientMessage(playerid, 0xFFFFFFFF, "You have admin-lvl 3");
Admin-script:
Code:
forward Admin_GetPlayerLevel(playerid);
Public Admin_GetPlayerLevel(playerid)
{
return APlayerData[playerid][PlayerLevel];
}
This works for example.
The speedometer script makes a call to the admin script, which gets the admin-lvl of the given player and returns it.

But how can I make the same system returning floats and strings? In case I need coordinates or a name returned.

I have made a work-around for this though, but it's quite complex.

The speedometer script makes a call using CallRemoteFunction to get the vehicle-name of an owned vehicle from the housing script (owned vehicles can be renamed by the owner).
The housing script answers that call and uses another CallRemoteFunction to transfer the name to the speedometer script, which receives it and stores the name in a variable.

This works, but it's complex to manage if you need to do this for alot of different things.
Each variable passed around needs a global variable in the other script to store that result until it is used.

How can you return floats/strings?
Is it possible?
Reply
#2

There is absolutely no need for multiple filterscripts, use callback hooking and compile them into the gamemode but to answer your question try this.

#include <a_samp>

pawn Code:
main() {
    new Float:t = Test();
    printf("%f", t);
}

forward Float:Test();
public Float:Test() { return 1.0; }
You can test that code on this website.

http://slice-vps.nl:7070/
Reply
#3

Quote:
Originally Posted by [uL]Pottus
View Post
There is absolutely no need for multiple filterscripts, use callback hooking and compile them into the gamemode but to answer your question try this.

#include <a_samp>

pawn Code:
main() {
    new Float:t = Test();
    printf("%f", t);
}

forward Float:Test();
public Float:Test() { return 1.0; }
You can test that code on this website.

http://slice-vps.nl:7070/
True, I'll answer the how to return string #TeamWork, how ever you could use a stock or like the one below, as long the function with Float: tag needs to be above the function, so it wouldn't give an error: warning 208: function with tag result used before definition, forcing reparse

pawn Code:
#include <a_samp>

//Returning a float.
Float:ReturnFloat()
{
    return 1.0;
}

//Returning a string
ReturnString(string[])
{
    print(string);
    return string;
}

//Debug Purposes
main()
{
    new Float:RetFloat = ReturnFloat();
    printf("%f", RetFloat);
    ReturnString("Long String, Test Me, Test me.");
    return true;
}
Debug Result (Using PPG)
Code:
1.000000
Long String, Test Me, Test me.
Reply
#4

You'll need to use properties, as you can't return strings with "CallRemoteFunction".

https://sampwiki.blast.hk/wiki/setproperty
https://sampwiki.blast.hk/wiki/getproperty
Reply
#5

Quote:
Originally Posted by [uL]Pottus
View Post
There is absolutely no need for multiple filterscripts, use callback hooking and compile them into the gamemode but to answer your question try this.

#include <a_samp>

pawn Code:
main() {
    new Float:t = Test();
    printf("%f", t);
}

forward Float:Test();
public Float:Test() { return 1.0; }
You can test that code on this website.

http://slice-vps.nl:7070/
Some people wanted to use a different housing system or business system in my gamemode PPC Trucking and wanted all the housing/business code removed from it.
Or even the entire admin system, or speedometer stuff.
But since everything is merged into eachother, that was nearly impossible to do.

And since I want to create another gamemode after PPC Trucking V2, I don't wanna look over a gamemode which will contain over 20.000 lines of code to find all housing/business/admin/speedometer related stuff and get it out before I can start working on a second gamemode.

That's why I opted for all separate filterscripts that communicate with eachother using CallRemoteFunction.

Properties look interesting but seem to be almost the same as PVars.

If CallRemoteFunction won't do it, I'll probably stay doing things the same as I'm doing now.
This is my current code to transfer vehicle-names:
Speedometer script:
Code:
// This function calls the housing script to ask for the player's vehicle-name
// The remote function will send the name back to this script through the "Speedo_StorePlayerVehicleName" function and store it in the player's account
INT_GetOwnedVehicleName(playerid, vehicleid)
{
	return CallRemoteFunction("Housing_GetVehicleName", "ii", playerid, vehicleid);
}

// This function stores the given vehicle-name for the player (it has been asked by this script by the INT_GetOwnedVehicleName function)
forward Speedo_StorePlayerVehicleName(playerid, vName[]);
public Speedo_StorePlayerVehicleName(playerid, vName[])
{
	format(APlayerData[playerid][VehicleName], 50, vName);
}
Housing script:
Code:
// This function makes another call to the speedometer script to send the requested vehiclename
forward Housing_GetVehicleName(playerid, vehicleid);
public Housing_GetVehicleName(playerid, vehicleid)
{
	// Send the vehiclename back to the speedometer script
	CallRemoteFunction("Speedo_StorePlayerVehicleName", "is", playerid, AVehicleData[vehicleid][VehicleName]);
}
As you can see, the speedometer script uses "INT_GetOwnedVehicleName(playerid, vehicleid)" to ask for the vehiclename of the given vehicle (this vehiclename is stored in the housing script) and store it in the given player's account.
The housing script then uses another CallRemoteFunction to send the vehiclename back to the speedometer script.
The speedometer script then stores the given vehiclename in the player's account and is ready to be used.

It's actually simple to setup, but will require alot of those separate functions for each string I want to transfer between scripts (not much though).


It's good that floats are supported though, this will cut down on the extra functions.
Reply
#6

Maybe it's even possible to combine all my filterscripts into one big filterscript (speedometer, housing, business and admin stuff).
Then only data must be transferred between the gamemode and the combined filterscript, which is alot less.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)