Advertisement
Urik_Kane

Jason's Buymenu sync subscription

Nov 10th, 2016
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. --  On the serverside, inside the buy function of the faction buymenu, put
  2.     Events:Fire("FactionMenuPurchaseVehicleAlert", player)
  3.     --  This fires a notice to ALL the modules on that side of the network(Server or client side, in this case server).
  4.     --  The data being sent is the playerObject. You could easily send a table with lots of data in it.
  5.    
  6. --  In the init of the regular menu put:
  7.     Events:Subscribe("FactionMenuPurchaseVehicleAlert", self, self.FactionMenuPurchaseVehicleAlert)
  8.     --  This receives the above mentioned event notice. ONLY a module with this subscription will act on it, though they all will hear it. Just like in normal network communication.
  9.  
  10. function BuyMenu:FactionMenuPurchaseVehicleAlert(player)
  11.     --  This function is called when the event notice is received.
  12.     if IsValid(player) then
  13.         --  Validate that the player obj is still valid. It's possible they lagged out between the communication (even though it's essentially instant).
  14.         local veh   =   self.vehicles[player:GetId()]
  15.         --  Since the player is valid, we now use the playerObject to key into the BuyMenu vehicle table the same way it is done in the other areas of the BuyMenu, with Player ID.
  16.         if IsValid(veh) then
  17.         --  We check to see if the vehicle is valid.
  18.         --  If there is no vehicle purchased yet, veh should be nil.
  19.         --  If a vehicle was purchased but is no longer valid, IsValid returns false and this check fails.
  20.         --  If a vehicle was previously purchased and is still valid, veh will be that vehicleObject.
  21.             veh:Remove()
  22.             --  We now remove the vehicle.
  23.         end
  24.     end
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement