09.06.2015, 14:48
(
Последний раз редактировалось mk124; 09.06.2015 в 19:45.
)
- Call Shoebill-Functions from Pawn
If you want to update, please use the shoebill-updater. Just start the update-shoebill.bat/.sh file and shoebill will download the newest version.
I'm happy to tell you, that Shoebill now supports calling Java functions from Pawn. At this moment, Integers, Floats and Strings are supported. You can also pass variables by their reference and change their value in Java.
Here is a little example:
At first, you need to add a new native function into your Pawn-Script:
pawn Код:
native CallShoebillFunction(name[], {Float,_}:...);
Now, you need to register a function, this happens in Java. Every AMX-File has it's own function-pool. If you want to register a function in every amx-file, you need to loop through all amx instances or add a eventhandler to the AmxLoadEvent. In this example, I will register my function in the AmxLoadEvent, so it's available for every amx-file.
PHP код:
eventManager.registerHandler(AmxLoadEvent.class, e -> {
e.getAmxInstance().registerFunction("GetPlayerFactionName", objects -> {
Player player = Player.get((Integer) objects[0]);
//Do something to get player's faction etc.
objects[1] = "Los Santos PoPo";
//Return value for pawn (not always needed)
return 1;
}, Integer.class, String.class);
});
First, you need to declare a new, then you need to add the function that will be called in java. After that, you need to add the parameter-types, in this case Integer (for the playerid) and then a String (as reference, the faction name will be written into this variable). If you register function, you also need to unregister them via the .unregisterFunction-Method:
PHP код:
eventManager.registerHandler(AmxUnloadEvent.class, e -> {
e.getAmxInstance().unregisterFunction("GetPlayerFactionName");
});
pawn Код:
public OnPlayerConnect(playerid)
{
new factionName[] = "Unknown";
CallShoebillFunction("GetPlayerFactionName", playerid, factionName);
printf("Factionname: %s", factionName);
return 1;
}