Advertisement
gamer931215

Example usage of CallLocalFunction()

Sep 4th, 2011
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.48 KB | None | 0 0
  1. #include <a_samp>
  2. /*
  3.     This is a example of how to use CallLocalFunction,
  4.     this shows how you can create a callback called "OnPlayerHealthChange", and how to actually
  5.     "call" the callback.
  6.    
  7.     Written by Gamer931215
  8. */
  9. new Float:old_health[MAX_PLAYERS];
  10.  
  11. public OnPlayerConnect(playerid)
  12. {
  13.     old_health[playerid] = 100.0;
  14.     return 1;
  15. }
  16.  
  17. public OnPlayerUpdate(playerid)
  18. {
  19.     //Getting Player's new health
  20.     new Float:new_health;
  21.     GetPlayerHealth(playerid,new_health);
  22.  
  23.     if(new_health != old_health[playerid]) //If the health on the latest update isnt matching
  24.     {
  25.         /*CallLocalFunction("functionname","format",parameters)
  26.             functionname = name of function
  27.             format = formats (i = integer, f = float, s = string) of the parameters
  28.             parameters = the parameters which you want to sent with it (in this case playerid,oldhealth,newhealth)
  29.         */
  30.         CallLocalFunction("OnPlayerHealthChange","iff",playerid,old_health[playerid],new_health); //call OnPlayerHealthChange
  31.         old_health[playerid] = new_health; //update health
  32.     }
  33.     return 1;
  34. }
  35.  
  36. /*This function will now be called with CallLocalFunction!
  37.     Local functions can be called in scripts which uses this as include, AND own scripts.
  38.     If you want to use functions from a different filterscript/gamemode use CallRemoteFunction()!
  39. */
  40. forward OnPlayerHealthChange(playerid,Float:oldhealth,Float:newhealth);
  41. public OnPlayerHealthChange(playerid,Float:oldhealth,Float:newhealth)
  42. {
  43.     //Do something here
  44.     return 1;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement