Advertisement
VADemon

I don't want to debug this code anymore

Jul 5th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.38 KB | None | 0 0
  1. F2_KEY, F3_KEY, F4_KEY = 1, 2, 3
  2.  
  3. sugarStick = {}
  4.  
  5. sugarStick.menus = {
  6.     [F2_KEY] = {
  7.         title = "Weapon Shop",
  8.         items = {
  9.             {"AK-47","$2500",function(id)
  10.                 if player(id,"money")>=2500 then
  11.                     parse("equip "..id.." 30")
  12.                     parse("setmoney "..id.." "..player(id,"money")-2500)
  13.                 else
  14.                     msg2(id,"You don't have enough money!")
  15.                 end
  16.             end},
  17.             {"AWP","$3000",function(id)
  18.                 if player(id,"money")>=3000 then
  19.                     parse("equip "..id.." 35")
  20.                     parse("setmoney "..id.." "..player(id,"money")-3000)
  21.                 else
  22.                     msg2(id,"You don't have enough money!")
  23.                 end
  24.             end},
  25.             {"M4A1","$2600",function(id)
  26.                 if player(id,"money")>=2600 then
  27.                     parse("equip "..id.." 32")
  28.                     parse("setmoney "..id.." "..player(id,"money")-2600)
  29.                 else
  30.                     msg2(id,"You don't have enough money!")
  31.                 end
  32.             end},
  33.             {"Message","$100",function(id)
  34.                 if player(id,"money")>=100 then
  35.                     msg("ELLO!@C")
  36.                     parse("setmoney "..id.." "..player(id,"money")-100)
  37.                 else
  38.                     msg2(id,"You don't have enough money!")
  39.                 end
  40.             end}
  41.         },
  42.     }
  43. }
  44. --[[
  45. function sugarStick.addMenuEntry(menuID, buttonName, buttonDescription, func)
  46.     if sugarStick.menus[ menuID ] then
  47.         if type(buttonName) == type(buttonDescription) and type(func) == "function" then
  48.             sugarStick.menus[ menuID ].items[ #sugarStick.menus[ menuID ].items + 1 ] = {buttonName, buttonDescription, func}
  49.         else
  50.             print("©255100100[Multiserveraction] addMenuEntry parameters are wrong!")
  51.         end
  52.     else
  53.         print("©255100100[Multiserveraction] addMenuEntry: menu '".. menuID .."' doesn't exist!")
  54.     end
  55. end
  56.  
  57. function sugarStick.removeMenuEntry(menuID, buttonName, buttonDescription, func)
  58.     if sugarStick.menus[ menuID ] then
  59.         if type(buttonName) == type(buttonDescription) and type(func) == "function" then
  60.             table.remove
  61.         else
  62.             print("©255100100[Multiserveraction] removeMenuEntry parameters are wrong!")
  63.         end
  64.     else
  65.         print("©255100100[Multiserveraction] removeMenuEntry: menu '".. menuID .."' doesn't exist!")
  66.     end
  67. end
  68.  
  69. sugarStick.original_addhook = addhook
  70.  
  71. function addhook(hook, strfunc, priority)   -- priority used to determine a key. Constants: F2_KEY, F3_KEY, F4_KEY
  72.     local key
  73.     if hook == "multiserveraction" then
  74.         if type(priority) == "number" then
  75.             if priority == F2_KEY or priority == F3_KEY or priority == F4_KEY then
  76.                 print("©100100255[Multiserveraction] Received addhook for function ".. func .."! The serveraction key is:" .. priority)
  77.                 key = priority
  78.             else
  79.                 print("©255100100[Multiserveraction] Received addhook for function ".. func .." but the used key is invalid!")
  80.                 print("©255100100... defaulting this script's trigger key to F2!")
  81.                 key = F2_KEY
  82.             end        
  83.         else
  84.             print("©255100100[Multiserveraction] Received addhook for function ".. func .." but the key is not specified!")
  85.             print("©255100100... defaulting this script's trigger key to F2!")
  86.             key = F2_KEY
  87.         end    
  88.     elseif hook == "serveraction" then
  89.         print("©255100100Multiserveraction is installed and some script just requested to add a 'serveraction' hook!")
  90.         print("©255100100... defaulting this script's trigger key to F2!")
  91.         key = F2_KEY
  92.     else
  93.         sugarStick.original_addhook(hook, strfunc, priority)
  94.         return
  95.     end
  96.    
  97.    
  98.    
  99. end
  100.  
  101. sugarStick.original_addhook("serveraction", "sugarStick.serveraction")
  102. function sugarStick.serveraction(id, actionkey)
  103.     local items = #sugarStick.menus[ actionkey ].items  -- how many scripts registered this serveraction key?
  104.    
  105.     if items > 1 then
  106.         sugarStick.unimenu(id, true, actionkey, 1)
  107.     elseif items == 1 then
  108.         sugarStick.menus.items[1][3]()  -- 1 = first entry, 3 = function key
  109.     else    -- 0 items
  110.         msg2(id, "©255100100No menu assigned with this server key!@C")
  111.     end
  112. end]]
  113.  
  114. sugarStick.spages = {{}}    -- spages [table]   - a table containing actual menu strings for each page of the menu opened by a player (2 layers - spages[id][page])
  115. sugarStick.pmenu = {}       -- pmenu [table]    - a table containing the last opened menu of each player (1 layer - pmenu[id])
  116.  
  117. addhook("join", "sugarStick.join")
  118. function sugarStick.join(id)
  119.     sugarStick.spages[id] = {}  -- moved from .unimenu which was only created once for all players with a specific ID
  120. end
  121.  
  122. --[[
  123. • id - player ID to open the menu to. number
  124. • construct - construct the menu anew or use the cached version? boolean
  125. • m - menu to show. table/number/string
  126. • p - page of the menu to show. number
  127. ]]
  128. function sugarStick.unimenu(id, construct, m, p)
  129.     if m ~= "current" then
  130.         if construct then
  131.             local custom, paget
  132.             local pmenu, spages, menus = sugarStick.pmenu, sugarStick.spages, sugarStick.menus
  133.             sugarStick.pmenu[id] = m
  134.            
  135.             if type(m) == "table" then
  136.                 custom = true
  137.                 paget = math.ceil(#m.items/7)
  138.             else
  139.                 custom = false
  140.                 paget = math.ceil(#menus[m].items/7)
  141.             end
  142.            
  143.             for i = 1, paget do
  144.                 if not custom then
  145.                     spages[id][i] = menus[m].title .." Page " .. i .. "@b,"
  146.                 else
  147.                     spages[id][i] = m.title .. " Page " .. i .. "@b,"
  148.                 end
  149.                 for ii = 1, 7 do
  150.                     local sid = ii+(7*(i-1))
  151.                     if not custom then
  152.                         if menus[m].items[sid] then
  153.                             spages[id][i] = spages[id][i] .. menus[m].items[sid][1] .. "|" .. menus[m].items[sid][2] .. ","
  154.                         else
  155.                             spages[id][i] = spages[id][i] .. ","
  156.                         end
  157.                     else
  158.                         if m.items[sid] then
  159.                             spages[id][i] = spages[id][i] .. m.items[sid][1] .. "|" .. m.items[sid][2] .. ","
  160.                         else
  161.                             spages[id][i] = spages[id][i] .. ","
  162.                         end
  163.                     end
  164.                 end
  165.                 if i < paget then
  166.                     spages[id][i] = spages[id][i] .. "Next"
  167.                 end
  168.                 if i>1 then
  169.                     spages[id][i] = spages[id][i] .. ",Back"
  170.                 end
  171.                
  172.                 sugarStick.pmenu, sugarStick.spages, sugarStick.menus = pmenu, spages, menus
  173.             end
  174.         end
  175.     end
  176.     menu(id,sugarStick.spages[id][p])
  177. end
  178.  
  179. addhook("menu","sugarStick.unimenuhook")
  180. function sugarStick.unimenuhook(id, menu, sel)
  181.     local p = tonumber(menu:sub(-1))
  182.     if sel < 8 and sel > 0 then
  183.         local s = sel+(7*(p-1))
  184.         if type(sugarStick.pmenu[id]) == "table" then
  185.             sugarStick.pmenu[id].items[s][3](id)
  186.         else
  187.             sugarStick.menus[sugarStick.pmenu[id]].items[s][3](id)
  188.         end
  189.     else
  190.         if sel == 8 then
  191.             sugarStick.unimenu(id, true, "current", p+1)
  192.         elseif sel == 9 then
  193.             sugarStick.unimenu(id, true, "current", p-1)
  194.         end
  195.     end
  196. end
  197.  
  198. addhook("say", "testsay")
  199. function testsay(id, txt)
  200.     if txt == "!f2" then
  201.         sugarStick.unimenu(1, true, F2_KEY, 1)
  202.     end
  203. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement