Advertisement
KirillMysnik

wcs shop - srcds plugin

Apr 15th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. from commands.say import SayCommand
  2. from players.entity import Player
  3. from plugins.info import PluginInfo
  4.  
  5. from motdplayer import Page
  6.  
  7.  
  8. info = PluginInfo(__name__)
  9.  
  10.  
  11. class ShopPage(Page):
  12.     plugin_id = "wcs"
  13.     page_id = "shop"
  14.  
  15.     def on_data_received(self, data):
  16.         player = # тут получаешь своего игрока с помощью self.index
  17.         if data['action'] == "get-items":
  18.             item_data = []
  19.  
  20.             for item in player.item_hero.items.values():
  21.                 item_data.append({
  22.                     'id': item.id,
  23.                     'name': item.name,
  24.                     'icon': item.icon,
  25.                     'cost': item.cost,
  26.                 })
  27.  
  28.             self.send_data({
  29.                 'action': "items-delivery",
  30.                 'availableItems': item_data,  # тут информация о доступных предметах
  31.             })
  32.             return
  33.  
  34.         if data['action'] == "buy-item":
  35.             item_id = data['itemId']
  36.             if item_id not in player.item_hero.items:
  37.                 return
  38.             item = player.item_hero.items[item_id]
  39.             item.level += 1
  40.             player.item_hero.coins -= item.cost
  41.             return
  42.  
  43.  
  44. @SayCommand('!shop')
  45. def say_shop(command, index, team_only):
  46.     ShopPage.send(index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement