Advertisement
Chronos_Ouroboros

Untitled

Dec 17th, 2017
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. class S7_ShopMenu_EventHandler : EventHandler {
  2. override void NetworkProcess (ConsoleEvent e) {
  3. if (e.IsManual || e.Player < 0) // Don't execute this if it was called manually or the player isn't given/valid
  4. return;
  5. if (!playeringame [e.Player] || !players [e.Player].mo) // Don't execute if the player isn't ingame, the player is null or the player's PlayerPawn is null
  6. return;
  7.  
  8. let player = S7_BasePlayer (players [e.Player].mo);
  9. if (!player)
  10. return;
  11.  
  12. Array<String> strings;
  13. e.Name.Split (strings, ":");
  14. if (strings.Size () < 2 || strings [0] != "S7_ShopMenu") // Return if the array has less than two strings or the first string isn't "S7_ShopMenu"
  15. return;
  16.  
  17. if ((strings [1] == "Buy" || strings [1] == "Sell")) {
  18. let serverData = S7_ServerData.Get ();
  19. if (!serverData || !serverData.shopData || !serverData.shopData.mainShop)
  20. return;
  21.  
  22. int amount = e.Args [1];
  23. double mod = 0.0;
  24. S7_SSItem item = NULL;
  25.  
  26. for (int i = 0; i < serverData.shopData.allItems.Size (); i++) {
  27. if (serverData.shopData.allItems [i].id == e.Args [0]) {
  28. let item = serverData.shopData.allItems [i];
  29. break;
  30. }
  31. }
  32. if (!item)
  33. return;
  34.  
  35. if (strings [1] == "Buy" && (item.itemType & IT_BuyItem))
  36. item.BuyItem (player, amount, mod);
  37. else if (strings [1] == "Sell" && (item.itemType & IT_SellItem))
  38. item.SellItem (player, amount, mod);
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement