Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- F2_KEY, F3_KEY, F4_KEY = 1, 2, 3
- sugarStick = {}
- sugarStick.menus = {
- [F2_KEY] = {
- title = "Weapon Shop",
- items = {
- {"AK-47","$2500",function(id)
- if player(id,"money")>=2500 then
- parse("equip "..id.." 30")
- parse("setmoney "..id.." "..player(id,"money")-2500)
- else
- msg2(id,"You don't have enough money!")
- end
- end},
- {"AWP","$3000",function(id)
- if player(id,"money")>=3000 then
- parse("equip "..id.." 35")
- parse("setmoney "..id.." "..player(id,"money")-3000)
- else
- msg2(id,"You don't have enough money!")
- end
- end},
- {"M4A1","$2600",function(id)
- if player(id,"money")>=2600 then
- parse("equip "..id.." 32")
- parse("setmoney "..id.." "..player(id,"money")-2600)
- else
- msg2(id,"You don't have enough money!")
- end
- end},
- {"Message","$100",function(id)
- if player(id,"money")>=100 then
- msg("ELLO!@C")
- parse("setmoney "..id.." "..player(id,"money")-100)
- else
- msg2(id,"You don't have enough money!")
- end
- end}
- },
- }
- }
- --[[
- function sugarStick.addMenuEntry(menuID, buttonName, buttonDescription, func)
- if sugarStick.menus[ menuID ] then
- if type(buttonName) == type(buttonDescription) and type(func) == "function" then
- sugarStick.menus[ menuID ].items[ #sugarStick.menus[ menuID ].items + 1 ] = {buttonName, buttonDescription, func}
- else
- print("©255100100[Multiserveraction] addMenuEntry parameters are wrong!")
- end
- else
- print("©255100100[Multiserveraction] addMenuEntry: menu '".. menuID .."' doesn't exist!")
- end
- end
- function sugarStick.removeMenuEntry(menuID, buttonName, buttonDescription, func)
- if sugarStick.menus[ menuID ] then
- if type(buttonName) == type(buttonDescription) and type(func) == "function" then
- table.remove
- else
- print("©255100100[Multiserveraction] removeMenuEntry parameters are wrong!")
- end
- else
- print("©255100100[Multiserveraction] removeMenuEntry: menu '".. menuID .."' doesn't exist!")
- end
- end
- sugarStick.original_addhook = addhook
- function addhook(hook, strfunc, priority) -- priority used to determine a key. Constants: F2_KEY, F3_KEY, F4_KEY
- local key
- if hook == "multiserveraction" then
- if type(priority) == "number" then
- if priority == F2_KEY or priority == F3_KEY or priority == F4_KEY then
- print("©100100255[Multiserveraction] Received addhook for function ".. func .."! The serveraction key is:" .. priority)
- key = priority
- else
- print("©255100100[Multiserveraction] Received addhook for function ".. func .." but the used key is invalid!")
- print("©255100100... defaulting this script's trigger key to F2!")
- key = F2_KEY
- end
- else
- print("©255100100[Multiserveraction] Received addhook for function ".. func .." but the key is not specified!")
- print("©255100100... defaulting this script's trigger key to F2!")
- key = F2_KEY
- end
- elseif hook == "serveraction" then
- print("©255100100Multiserveraction is installed and some script just requested to add a 'serveraction' hook!")
- print("©255100100... defaulting this script's trigger key to F2!")
- key = F2_KEY
- else
- sugarStick.original_addhook(hook, strfunc, priority)
- return
- end
- end
- sugarStick.original_addhook("serveraction", "sugarStick.serveraction")
- function sugarStick.serveraction(id, actionkey)
- local items = #sugarStick.menus[ actionkey ].items -- how many scripts registered this serveraction key?
- if items > 1 then
- sugarStick.unimenu(id, true, actionkey, 1)
- elseif items == 1 then
- sugarStick.menus.items[1][3]() -- 1 = first entry, 3 = function key
- else -- 0 items
- msg2(id, "©255100100No menu assigned with this server key!@C")
- end
- end]]
- 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])
- sugarStick.pmenu = {} -- pmenu [table] - a table containing the last opened menu of each player (1 layer - pmenu[id])
- addhook("join", "sugarStick.join")
- function sugarStick.join(id)
- sugarStick.spages[id] = {} -- moved from .unimenu which was only created once for all players with a specific ID
- end
- --[[
- • id - player ID to open the menu to. number
- • construct - construct the menu anew or use the cached version? boolean
- • m - menu to show. table/number/string
- • p - page of the menu to show. number
- ]]
- function sugarStick.unimenu(id, construct, m, p)
- if m ~= "current" then
- if construct then
- local custom, paget
- local pmenu, spages, menus = sugarStick.pmenu, sugarStick.spages, sugarStick.menus
- sugarStick.pmenu[id] = m
- if type(m) == "table" then
- custom = true
- paget = math.ceil(#m.items/7)
- else
- custom = false
- paget = math.ceil(#menus[m].items/7)
- end
- for i = 1, paget do
- if not custom then
- spages[id][i] = menus[m].title .." Page " .. i .. "@b,"
- else
- spages[id][i] = m.title .. " Page " .. i .. "@b,"
- end
- for ii = 1, 7 do
- local sid = ii+(7*(i-1))
- if not custom then
- if menus[m].items[sid] then
- spages[id][i] = spages[id][i] .. menus[m].items[sid][1] .. "|" .. menus[m].items[sid][2] .. ","
- else
- spages[id][i] = spages[id][i] .. ","
- end
- else
- if m.items[sid] then
- spages[id][i] = spages[id][i] .. m.items[sid][1] .. "|" .. m.items[sid][2] .. ","
- else
- spages[id][i] = spages[id][i] .. ","
- end
- end
- end
- if i < paget then
- spages[id][i] = spages[id][i] .. "Next"
- end
- if i>1 then
- spages[id][i] = spages[id][i] .. ",Back"
- end
- sugarStick.pmenu, sugarStick.spages, sugarStick.menus = pmenu, spages, menus
- end
- end
- end
- menu(id,sugarStick.spages[id][p])
- end
- addhook("menu","sugarStick.unimenuhook")
- function sugarStick.unimenuhook(id, menu, sel)
- local p = tonumber(menu:sub(-1))
- if sel < 8 and sel > 0 then
- local s = sel+(7*(p-1))
- if type(sugarStick.pmenu[id]) == "table" then
- sugarStick.pmenu[id].items[s][3](id)
- else
- sugarStick.menus[sugarStick.pmenu[id]].items[s][3](id)
- end
- else
- if sel == 8 then
- sugarStick.unimenu(id, true, "current", p+1)
- elseif sel == 9 then
- sugarStick.unimenu(id, true, "current", p-1)
- end
- end
- end
- addhook("say", "testsay")
- function testsay(id, txt)
- if txt == "!f2" then
- sugarStick.unimenu(1, true, F2_KEY, 1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement