SA-MP Forums Archive
[Include] [New Player Callbacks] Version 1.4 - BigETI - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] [New Player Callbacks] Version 1.4 - BigETI (/showthread.php?tid=280549)

Pages: 1 2


[New Player Callbacks] Version 1.5 (SA:MP 0.3d RC7 or higher required) - BigETI - BigETI - 01.09.2011

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: Credits: Updates: 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


Re: [New Player Callbacks] Version 1 - BigETI - LZLo - 01.09.2011

hmm looks like useful, thanks!


Re: [New Player Callbacks] Version 1 - BigETI - Improvement™ - 01.09.2011

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!


Re: [New Player Callbacks] Version 1 - BigETI - Speed - 01.09.2011

its n1 i will use it


Re: [New Player Callbacks] Version 1 - BigETI - BigETI - 01.09.2011

Thank you all


Re: [New Player Callbacks] Version 1 - BigETI - [03]Garsino - 01.09.2011

As I said on IRC: Awesome!


Re: [New Player Callbacks] Version 1 - BigETI - BigETI - 01.09.2011

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


Re: [New Player Callbacks] Version 1 - BigETI - steki. - 01.09.2011

Awesome (i fail'd)


Re: [New Player Callbacks] Version 1 - BigETI - Rock_Ro - 01.09.2011

Awesome.
Useful for others.


Re : [New Player Callbacks] Version 1 - BigETI - Velko - 02.09.2011

good work buddy

+rep


Re: [New Player Callbacks] Version 1 - BigETI - IstuntmanI - 02.09.2011

Very useful !


Re: [New Player Callbacks] Version 1 - BigETI - BigETI - 02.09.2011

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.


Re: [New Player Callbacks] Version 1 - BigETI - wups - 02.09.2011

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).


Re: [New Player Callbacks] Version 1 - BigETI - Darnell - 02.09.2011

Awesome.


Re: [New Player Callbacks] Version 1 - BigETI - BigETI - 02.09.2011

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


Re: [New Player Callbacks] Version 1 - BigETI - wups - 02.09.2011

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


Re: [New Player Callbacks] Version 1.2 - BigETI - BigETI - 06.09.2011

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

Regards


AW: [New Player Callbacks] Version 1.4 - BigETI - BigETI - 27.09.2011

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?


Re: [New Player Callbacks] Version 1.2 - BigETI - [DOG]irinel1996 - 27.09.2011

Nice, good work.
5/5


AW: [New Player Callbacks] Version 1.4 - BigETI - BigETI - 27.09.2011

Thanks