Returning strings or floats
#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


Messages In This Thread
Returning strings or floats - by PowerPC603 - 19.12.2013, 17:41
Re: Returning strings or floats - by Pottus - 19.12.2013, 18:01
Re: Returning strings or floats - by Patrick - 19.12.2013, 18:19
Re: Returning strings or floats - by Emmet_ - 19.12.2013, 18:28
Re: Returning strings or floats - by PowerPC603 - 19.12.2013, 20:30
Re: Returning strings or floats - by PowerPC603 - 19.12.2013, 21:29

Forum Jump:


Users browsing this thread: 1 Guest(s)