- Hook callbacks & call natives
- A amx with all callbacks in it is not needed anymore. Shoebill will find the callbacks automatically
We are happy to announce the new update. With this update, you can hook custom callbacks from other plugins.
Please make sure, that you use the shoebill-updater (update-shoebill.bat/sh in your server-dir), because many files have changed (shoebill-runtime, launcher, plugin, api)
In this example, I will show you how to hook a callback from FCNPC and call native functions from it:
(plugin url:
https://sampforum.blast.hk/showthread.php?tid=428066)
Add a Hook (Make sure, that you remove the hook when you unload your gamemode / plugin):
Код:
@Override
protected void onEnable() throws Throwable {
Shoebill.get().getAmxInstanceManager().hookCallback("FCNPC_OnCreate", amxCallEvent -> {
System.out.println("FCNPC created a npc with id " + amxCallEvent.getParameters()[0]);
}, "i");
}
@Override
protected void onDisable() throws Throwable {
Shoebill.get().getAmxInstanceManager().unhookCallback("FCNPC_OnCreate"); //remove hook when unloaded.
}
The callback for FCNPC_OnCreate looks like this:
public FCNPC_OnCreate(npcid);
As you can see, it contains 1 parameter of type integer. So, you will need to register the first parameter in the .hookCallback() method at the end.
i -> Integer
f -> Float
s -> String
So, if you have a callback that looks like this:
public OnPlayerChangeName(id, old_name, new_name[]);
you'll have to pass the parameter as following:
Код:
Shoebill.get().getAmxInstanceManager().hookCallback("OnPlayerChangeName", amxCallEvent -> {
}, "iss");
If you want to create a new npc, you will have to do the following (e.g. in a command or when server starts):
The native to create a FCNPC NPC is looking like this:
native FCNPC_Create(name[]);
This native will return the created id, so you will do this to call it:
Код:
@Command
public boolean createnpc(Player player, String name) {
AmxCallable nativeMethod = null;
for(AmxInstance instance : Shoebill.get().getAmxInstanceManager().getAmxInstances()) { //loop through all amxs
if((nativeMethod = instance.getNative("FCNPC_Create")) != null) //check if the amx contains the native
break; //if yes, break out of the loop
}
if(nativeMethod != null) { //when the native method was found, execute it
player.sendMessage(Color.ORANGE, "* Exec with result: " + nativeMethod.call(name)); //call the native with parameter name and send the return value back to the player.
} else {
player.sendMessage(Color.ORANGE, "* Not found!"); //native was not found (plugin not loaded or typo?)
}
return true;
}