Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- /*
- This is a example of how to use CallLocalFunction,
- this shows how you can create a callback called "OnPlayerHealthChange", and how to actually
- "call" the callback.
- Written by Gamer931215
- */
- new Float:old_health[MAX_PLAYERS];
- public OnPlayerConnect(playerid)
- {
- old_health[playerid] = 100.0;
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- //Getting Player's new health
- new Float:new_health;
- GetPlayerHealth(playerid,new_health);
- if(new_health != old_health[playerid]) //If the health on the latest update isnt matching
- {
- /*CallLocalFunction("functionname","format",parameters)
- functionname = name of function
- format = formats (i = integer, f = float, s = string) of the parameters
- parameters = the parameters which you want to sent with it (in this case playerid,oldhealth,newhealth)
- */
- CallLocalFunction("OnPlayerHealthChange","iff",playerid,old_health[playerid],new_health); //call OnPlayerHealthChange
- old_health[playerid] = new_health; //update health
- }
- return 1;
- }
- /*This function will now be called with CallLocalFunction!
- Local functions can be called in scripts which uses this as include, AND own scripts.
- If you want to use functions from a different filterscript/gamemode use CallRemoteFunction()!
- */
- forward OnPlayerHealthChange(playerid,Float:oldhealth,Float:newhealth);
- public OnPlayerHealthChange(playerid,Float:oldhealth,Float:newhealth)
- {
- //Do something here
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement