[Include] [New Player Callbacks] Version 1.4 - BigETI
#1

Here I want to introduce you an include, where you'll be able to write inside more callbacks

What are callbacks?
Callbacks are functions which will be called if something performed an action.

What are now the callbacks which includes in this include?

pawn Код:
public OnPlayerEnteredVehicle(playerid, vehicleid, seatid)
public OnPlayerExitedVehicle(playerid, vehicleid)
public OnPlayerSkinChange(playerid, oldskin, newskin)
public OnPlayerHoldWeaponChange(playerid, oldslot, oldweapon, newslot, newweapon)
public OnPlayerWeaponStateChange(playerid, oldstate, newstate)
public OnPlayerWeaponDataChange(playerid, slot, oldweapon, newweapon)
public OnPlayerAmmoDataChange(playerid, slot, oldammo, newammo)
public OnPlayerMoneyChange(playerid, oldmoney, newmoney)
public OnPlayerHealthChange(playerid, Float:oldhealth, Float:newhealth)
public OnPlayerArmourChange(playerid, Float:oldarmour, Float:newarmour)
public OnPlayerAnimationIndexChange(playerid, oldindex, newindex)
public OnPlayerTargetPlayer(playerid, oldtarget, newtarget, bool:istargeting)
public OnPlayerSpecialActionChange(playerid, oldsaction, newsaction)
public OnPlayerAnalogKeysChange(playerid, oldy, newy, oldx, newx)
public OnPlayerXYZChange(playerid, Float:oldx, Float:oldy, Float:oldz, Float:newx, Float:newy, Float:newz)
public OnPlayerVehicleHealthChange(playerid, vehicleid, Float:oldhealth, Float:newhealth, bool:isissuer)
public OnPlayerVirtualWorldChange(playerid, oldworld, newworld)
//Optional callbacks below
public OnPVarDelete(playerid, varname[], oldtype)
public OnPVarCreate(playerid, varname[], type)
public OnPVarTypeChange(playerid, varname[], oldtype, newtype)
public OnPVarIntChange(playerid, varname[], oldint_value, newint_value)
public OnPVarStringChange(playerid, varname[], oldstring_value[], newstring_value[])
public OnPVarFloatChange(playerid, varname[], Float:oldfloat_value, Float:newfloat_value)
Usage:
Just add ncbs.inc in one of your script (For example a filterscript). Do not use this include more than one time. Use ncbs_forwads.inc at another scripts to get the remoted callbacks called in your scripts.
To remote callbacks you have to keep defined USE_IN_ALL_SCRIPTS.
ncbs_defines.inc makes you able to define parameters you need.

Example of adding those includes:

Adding ncbs.inc into my filterscript:

pawn Код:
#define FILTERSCRIPT
#include <ncbs>
public OnFilterScriptInit()
{
    print("\n------------------------");
    print(" Example Filterscript...");
    print("------------------------\n");
    return 1;
}
Adding ncbs_forwards.inc into my gamemode:
pawn Код:
#include <ncbs_forwards>
main()
{
    print("\n--------------------");
    print(" Example Gamemode...");
    print("--------------------\n");
}
Description:
pawn Код:
public OnPlayerEnteredVehicle(playerid, vehicleid, seatid)
Gets called if the player has entered any vehicle.


pawn Код:
public OnPlayerExitedVehicle(playerid, vehicleid)
Gets called if the player has left his/her vehicle.
Returning 0 will deny updating the old variable.



pawn Код:
public OnPlayerSkinChange(playerid, oldskin, newskin)
Gets called if the player changed his/her skin. (With SetPlayerSkin or mods).
Returning 0 will deny updating the old variable.



pawn Код:
public OnPlayerHoldWeaponChange(playerid, oldslot, oldweapon, newslot, newweapon)
Gets called if the player changed the weapon on his/her hand.
Returning 0 will deny updating the old variable.



pawn Код:
public OnPlayerWeaponStateChange(playerid, oldstate, newstate)
Gets called if the player has changed his/her weapon state (check https://sampwiki.blast.hk/wiki/Weapon_States).
Returning 0 will deny updating the old variable.



pawn Код:
public OnPlayerWeaponDataChange(playerid, slot, oldweapon, newweapon)
Gets called if the player spawned/lost a weapon (Spawning mit GivePlayerWeapon or cheats).
Returning 0 will deny updating the old variable.



pawn Код:
public OnPlayerAmmoDataChange(playerid, slot, oldammo, newammo)
Gets called if the player spawned ammo for a special weapon slot (Spawning with GivePlayerWeapon or cheats).
Returning 0 will deny updating the old variable.


pawn Код:
public OnPlayerMoneyChange(playerid, oldmoney, newmoney)
Gets called if the player has changed his/her money (With GivePlayerMoney oder Cheats)
Returning 0 will deny updating the old variable.


pawn Код:
public OnPlayerHealthChange(playerid, Float:oldhealth, Float:newhealth)
Gets called if the player's has been modified (Increasing at respawn, with SetPlayerHealth or cheats).
Returning 0 will deny updating the old variable.



pawn Код:
public OnPlayerArmourChange(playerid, Float:oldarmour, Float:newarmour)
Gets called if the player's armour has been modified (Increasing with SetPlayerArmour or cheats).
Returning 0 will deny updating the old variable.



pawn Код:
public OnPlayerAnimationIndexChange(playerid, oldindex, newindex)
Gets called if the player changed his/her animation.
Returning 0 will deny updating the old variable.



pawn Код:
public OnPlayerTargetPlayer(playerid, oldtarget, newtarget, bool:istargeting)
Gets called if the player is aiming on a player or not.
Returning 0 will deny updating the old variable.


pawn Код:
public OnPlayerSpecialActionChange(playerid, oldsaction, newsaction)
Gets called if the player changed his/her special acton (with SetPlayerSpecialAction or mods/cheats).
Returning 0 will deny updating the old variable.



pawn Код:
public OnPlayerAnalogKeysChange(playerid, oldy, newy, oldx, newx)
Gets called if the up, down, left and right buttons got touched.
Returning 0 will deny updating the old variable.



pawn Код:
public OnPlayerVehicleHealthChange(playerid, vehicleid, Float:oldhealth, Float:newhealth, bool:isissuer)
Gets called if the player's vehicle health got changed.
Returning 0 will deny updating the old variable.



pawn Код:
public OnPlayerVirtualWorldChange(playerid, oldworld, newworld)
Gets called if the player changed properly his/her virtual world (Since virtual worlds are serversided so you can't modify it with cheats).
Returning 0 will deny using SetPlayerVirtualWorld.


Optional callbacks:
pawn Код:
public OnPVarDelete(playerid, varname[], oldtype)
Gets only called if a PVar has been deleted (check https://sampwiki.blast.hk/wiki/DeletePVar)


pawn Код:
public OnPVarCreate(playerid, varname[], type)
Gets only called if a PVar has been created.
Returning 0 will deny using SetPVarInt, SetPVarString or SetPVarFloat.



pawn Код:
public OnPVarTypeChange(playerid, varname[], oldtype, newtype)
Gets only called if the PVar type has been changed.
Returning 0 will deny using SetPVarInt, SetPVarString or SetPVarFloat.



pawn Код:
public OnPVarIntChange(playerid, varname[], oldint_value, newint_value)
Gets only called if SetPVarInt changed its own value.
Returning 0 will deny using SetPVarInt.



pawn Код:
public OnPVarStringChange(playerid, varname[], oldstring_value[], newstring_value[])
Gets only called if SetPVarString changed its own value.
Returning 0 will deny using SetPVarString.



pawn Код:
public OnPVarFloatChange(playerid, varname[], Float:oldfloat_value, Float:newfloat_value)
Gets only called if SetPVarFloat changed its own value.
Returning 0 will deny using SetPVarFloat.


Known Bugs:
  • OnPlayerWeaponDataChange and OnPlayerAmmoDataChange gets only called if another action has been also executed (SA:MP fault)
  • There are some minor issues between multiple script (gonna release soon a better version)
  • No more bugs found..
Credits:
  • Added ALS hooking (made by ******)
  • Thanks to wups telling me how to return the callbacks properly by using funcidx
  • Giving me the idea for using an OPU delay to prevent overkill (cessil)
  • The SA:MP development team
  • Myself..
Updates:
  • Version 1.5: Added OnPlayerXYZChange and OnPlayerTargetPlayer (main idea: https://sampforum.blast.hk/showthread.php?tid=293525)
    All callbacks have to return a value else their old variable won't get updated and they get recalled after next delayed player update or even some callbacks will just deny executing some functions. (For example: SetPlayerVirtualWorld, SetPVarInt, SetPVarFloat, SetPVarString, DeletePVar etc.)
  • Version 1.4: Added OnPlayerChangeMoney, OnPlayerEnteredVehicle, OnPlayerExitedVehicle, OnPlayerAnalogKeysChange and OnPlayerVehicleHealthChange.
    The callbacks are now callable at another scripts.
    new_callbacks.inc has been renamed to ncbs.inc
    Added ncbs_forwards.inc (Used to use the callbacks at another scripts)
    Added ncbs_defines.inc (Used to change changable defined parameters)
    Some major/minor bug fixes..
  • Version 1.3: Includes OnPlayerUpdate delay (idea from cessil's OPU delay for anti cheats)
    Every single (I mean really every single!) callback is now choosable.
    Improved speed for some callbacks.
    Bug fixes..
  • Version 1.2: Using the ALS hooking method (made by ******) and using the correct method of returning existing/non existing callbacks (suggestion from wups)
    OnPVar callbacks are now optional (uncomment the USE_PVAR_CALLBACKS define inside the include to make use of the PVar callbacks)
  • Version 1.1: Added OnPlayerSpecialActionChange callback.
  • Version 1: First release!
Where I can download this file?


New:
Download the 1.5 package at Solidfiles
or
Pastebin Download 1.5 (ncbs.inc)
Pastebin Download 1.5 (ncbs_forwards.inc)
Pastebin Download 1.5 (ncbs_defines.inc)

Old:
Download the 1.4 package at Solidfiles
or
Pastebin Download 1.4 (ncbs.inc)
Pastebin Download 1.4 (ncbs_forwards.inc)
Pastebin Download 1.4 (ncbs_defines.inc)

Please report for any bugs!

Regards: BigETI
Reply
#2

hmm looks like useful, thanks!
Reply
#3

Quote:
Originally Posted by LZLo
Посмотреть сообщение
hmm looks like useful, thanks!
Agreed! I will save this incase some of these callbacks become usefull for my script.
Thank you for the share!
Reply
#4

its n1 i will use it
Reply
#5

Thank you all
Reply
#6

As I said on IRC: Awesome!
Reply
#7

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
As I said on IRC: Awesome!
Thanks thanks
Reply
#8

Awesome (i fail'd)
Reply
#9

Awesome.
Useful for others.
Reply
#10

good work buddy

+rep
Reply
#11

Very useful !
Reply
#12

Quote:
Originally Posted by ******
Посмотреть сообщение
You REALLY need to look up ALS if you want this to be compatible with other libraries. Currently this will give warnings when used with YSI/ZCMD/Streamer/foreach/many other less common ones.
Okay didn't thought about the ALS thing.

Quote:
Originally Posted by ******
Посмотреть сообщение
Also, this only seems to work inside one script, which frankly isn't all that useful - if you change a skin in your mode you know it has changed, knowing when other scripts (e.g. filterscripts) change the skin is much more useful information.
The point is, that this should get only called in scripts you need the callbacks else if I use CallRemoteFunction instead of CallLocalFunction and I include this inside several scripts, so a callback will get called on how much scripts I have included this include.

Quote:
Originally Posted by ******
Посмотреть сообщение
I was looking through the code and it seemed quite nice, until I saw "SetVar" - why? That only obfuscates a common PAWN ability, making code harder to read.
Well you can comment #define USE_PVAR_CALLBACKS to disable the OnPVar Callbacks.

Quote:
Originally Posted by ******
Посмотреть сообщение
Edit: I should add that I'm one of the people who criticise problems with things and assume that everything not mentioned (especially effort) is fine, but I should learn to praise more as it helps some people/
I may point that your reviews just helps peoples to improve their own works

Btw I just added
pawn Код:
public OnPlayerSpecialActionChange(playerid, oldsaction, newsaction)
since I had forget it on the last release and added some descriptions on the main post.

Of course I'll use the ALS technique on the next release since as you can see that ****** wrote that my include doesn't fit with another certain used includes.

Anyways thank you all.
Reply
#13

Nice script, had this idea earlier, but never started doing it. Oh well, i should say i hate your setvar define, and as ****** already mentioned, your callback hooking is bad. Another thing to mention, you should do funcidx before calling a function. Because, if people don't have OnPlayerUpdate in their gamemode, then "return CallLocalFunction("ETI_OnPlayerUpdate", "d", playerid);" will be "return 0;" which causes desync.
Check my includes(OPSP for example).
Reply
#14

Awesome.
Reply
#15

I just updated it and it includes now the ALS hooking method and returns correctly the callbacks by using a method with funcidx.
Edit: OnPVar callbacks are now optional.

Please report for any bugs.
Thanks!

Regards
Reply
#16

You understand, that your calling funcidx and calllocalfunction at EVERY onplayerupdate? A better solution would be saving it to a variable OnGameModeInit.
Reply
#17

I've improved now the stability and speed of this include.
Read the changelog on the main post.

Regards
Reply
#18

Updated and as you wished I made ways to use this include in several scripts.
I've also added a few callbacks more.
Descriptions and changelog are foundable on the main post.

Regards

Edit: Can a forum mod/admin update the topic name of this thread please?
Reply
#19

Nice, good work.
5/5
Reply
#20

Thanks
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)