Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function split(str, pat)
- local t = {} -- NOTE: use {n = 0} in Lua-5.0
- if str ~= nil then
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- else
- print("##ERROR failed to split ["..str.."] by:"..pat)
- end
- return t
- end
- local function getKey(name)
- name = string.upper(name)
- local nameToKeyConv = { LBUTTON = 1, RBUTTON = 2, CANCEL = 3, MBUTTON = 4, BACK = 8, TAB = 9, CLEAR = 12, RETURN = 13, SHIFT = 16, CONTROL = 17, MENU = 18, PAUSE = 19, CAPITAL = 20, ESCAPE = 27, SPACE = 32, PRIOR = 33, NEXT = 34, END = 35, HOME = 36, LEFT = 37, UP = 38, RIGHT = 39, DOWN = 40, SELECT = 41, PRINT = 42, EXECUTE = 43, SNAPSHOT = 44, INSERT = 45, DELETE = 46, HELP = 47, ["0"] = 48, ["1"] = 49, ["2"] = 50, ["3"] = 51, ["4"] = 52, ["5"] = 53, ["6"] = 54, ["7"] = 55, ["8"] = 56, ["9"] = 57, A = 65, B = 66, C = 67, D = 68, E = 69, F = 70, G = 71, H = 72, I = 73, J = 74, K = 75, L = 76, M = 77, N = 78, O = 79, P = 80, Q = 81, R = 82, S = 83, T = 84, U = 85, V = 86, W = 87, X = 88, Y = 89, Z = 90, LWIN = 91, RWIN = 92, APPS = 93, NUMPAD0 = 96, NUMPAD1 = 97, NUMPAD2 = 98, NUMPAD3 = 99, NUMPAD4 = 100, NUMPAD5 = 101, NUMPAD6 = 102, NUMPAD7 = 103, NUMPAD8 = 104, NUMPAD9 = 105, MULTIPLY = 106, ADD = 107, SEPARATOR = 108, SUBTRACT = 109, DECIMAL = 110, DIVIDE = 111, F1 = 112, F2 = 113, F3 = 114, F4 = 115, F5 = 116, F6 = 117, F7 = 118, F8 = 119, F9 = 120, F10 = 121, F11 = 122, F12 = 123, F13 = 124, F14 = 125, F15 = 126, F16 = 127, F17 = 128, F18 = 129, F19 = 130, F20 = 131, F21 = 132, F22 = 133, F23 = 134, F24 = 135, NUMLOCK = 144, SCROLL = 145, LSHIFT = 160, LCONTROL = 162, LMENU = 164, RSHIFT = 161, RCONTROL = 163, RMENU = 165}
- return nameToKeyConv[name]
- end
- Unlocks = {}
- Unlocks.on = false
- Unlocks.ALPHA = 100
- Unlocks.maxLevel = 30
- Unlocks.xpKill = 10
- Unlocks.lvlMod = 10
- Unlocks.lvlModAmt = 2
- Unlocks.lvlCostMod = 1
- Unlocks.startLevel = 0
- Unlocks.options = 3
- Unlocks.aiChance = 80
- Unlocks.keys = {
- toggle = "O",
- options = {
- [1] = "V",
- [2] = "B",
- [3] = "N",
- [4] = "M"
- }
- }
- Unlocks.weapons = {
- [1] = {
- "ammoLargeDouble",
- "flashbang",
- "sluggerPipe",
- "sphereGrenade",
- "sluggerRevolver"
- },
- [2] = {
- "klonk",
- "spikedMine",
- "spikeCrossbow",
- "sluggerSemi",
- "ammoLargeDouble"
- },
- [3] = {
- "sluggerSub",
- "matterPistol",
- "ammoLargeDouble",
- "plasmaPistol",
- "sluggerShotgun",
- },
- [4] = {
- "grenadeGun",
- "sluggerGun",
- "beamGun",
- "ammoLargeDouble",
- "gyrojetGun"
- },
- [5] = {
- "plasmaGun",
- "homingLauncer",
- "matterBlaster",
- "ammoLargeDouble",
- "plasmaAssault"
- }
- }
- local function getLines(dir)
- local lines = {}
- local file = io.open(dir)
- if file ~= nil then
- for line in file:lines() do lines[#lines + 1] = line end
- file:close()
- end
- return lines
- end
- local function cloneTable(table)
- local ntable = {}
- for k,v in pairs(table) do
- ntable[k] = v
- end
- return ntable
- end
- local function removeIndex(table, index)
- local ntable = {}
- for i=1,#table do
- if i ~= index then ntable[#ntable + 1] = table[i] end
- end
- return ntable
- end
- local function getGuns(lvl, nGuns)
- local tier = 1
- for i=1,#Unlocks.weapons do
- if (lvl >= (i-1)*5 and lvl < (i*5)) or (lvl > (i*5) and i == #Unlocks.weapons) then
- tier = i
- end
- end
- local tWeps = cloneTable(Unlocks.weapons[tier])
- local weps = {}
- if nGuns > #tWeps then nGuns = #tWeps end
- for i=1,nGuns do
- local index = math.random(#tWeps)
- weps[#weps + 1] = {tWeps[index], tier}
- tWeps = removeIndex(tWeps, index)
- end
- weps[#weps + 1] = {"CANCEL", 0}
- return weps
- end
- local function addWeapon(name, actor)
- local wep = Object.new(Object,name,actor.x,actor.y,actor.map)
- actor.map:addObject(wep)
- wep:propel(0,1)
- end
- local function pickWeapon(player, option)
- if player.unlockOptions ~= nil and player.xp_level ~= nil then
- local wep = player.unlockOptions[option]
- if wep ~= nil then
- local tWep = wep[1]
- if tWep ~= "CANCEL" then
- local cost = wep[2]*Unlocks.lvlCostMod
- local xpCost = (((cost*Unlocks.lvlModAmt)*Unlocks.lvlMod)+Unlocks.lvlMod)
- if player.xp_level >= cost and player.xp >= xpCost then
- player.xp_level = player.xp_level - cost
- player.xp = player.xp - xpCost
- addWeapon(tWep, player:getActor())
- if player:isAi() == false then
- print("Added weapon FOR HUMAN: "..tWep)
- else
- print("Added weapon FOR AI: "..tWep)
- end
- end
- end
- if player.xp_level == 0 then
- player.unlockOptions = nil
- else
- player.unlockOptions = getGuns(player.xp_level, Unlocks.options)
- end
- end
- end
- end
- local rPlayer = nil
- local dPlayers = {}
- local function contains(table, value)
- for k,v in pairs(table) do
- if v == value then return true end
- end
- return false
- end
- local function checkLevel(player)
- if player ~= nil and player.xp ~= nil and player.xp_level ~= nil then
- local ok = false
- for i=1,Unlocks.maxLevel do
- if player.xp >= ((i*Unlocks.lvlModAmt)*Unlocks.lvlMod)+Unlocks.lvlMod and player.xp_level < i then
- player.xp_level = i
- ok = true
- end
- end
- if ok and player.unlockOptions == nil then
- player.unlockOptions = getGuns(player.xp_level, Unlocks.options)
- if player:isAi() == true and player.unlockOptions ~= nil then
- if math.random(100) < Unlocks.aiChance then pickWeapon(player, math.random(#player.unlockOptions - 1)) end
- elseif (player:isAi() == false) and player.unlockOptions ~= nil then
- rPlayer = player
- end
- end
- end
- if (player:isAi() == false) then rPlayer = player end
- end
- local converter = {
- ["XP"] = video.createSpriteState("hud_know_destroyed","../hud.dat"),
- ["LVL"] = video.createSpriteState("hud_know_destroyed","../hud.dat"),
- ["NAME"] = "name",
- ["BOX"] = "box"
- }
- local function getImage(name)
- local id = converter[string.upper(name)]
- return id
- end
- local function getWeaponImage(wName)
- local icName = ITEMS[wName].iconName
- --print(wName..": "..icName)
- --local icon = video.createSpriteState(tostring(ITEMS[wName].iconName), "../hud.dat")
- icon = video.createSpriteState("ammoLargeDouble_icon", '../hud.dat')
- return icon
- end
- function UdrawBox(x, y, w, h, text, imageID, col, col2)
- if video ~= nil and Unlocks.on == true then
- if imageID ~= nil then
- video.renderSpriteStateFreeShape(imageID,
- x, y,
- x + w, y,
- x, y + h,
- x + w, y + h,
- col2[1] - Unlocks.ALPHA, col2[2], col2[3], col2[4])
- end
- if text ~= nil then
- video.renderText(text, x + 5, y, 0, "../boldFont.fnt", col[1] - Unlocks.ALPHA, col[2], col[3], col[4])
- end
- end
- end
- local YESYES = 0
- function myRender()
- if Unlocks.on == true and rPlayer ~= nil then
- local name = rPlayer:getName()
- if name == nil then name = "Player" end
- if name:gsub(" ", "") == "" then name = "Player" end
- if name == "<unknown>" then name = "Player" end
- local xp = rPlayer.xp
- if xp == nil then xp = 0 end
- local lvl = rPlayer.xp_level
- if lvl == nil then lvl = 0 end
- local options = rPlayer.unlockOptions
- UdrawBox(3, 0, 20, 20, name, nil, {255, 30, 150, 255}, {255, 50, 50, 50})
- UdrawBox(3, 14, 20, 20, xp, getImage("xp"), {255, 30, 150, 255}, {255, 50, 50, 50})
- UdrawBox(60, 14, 20, 20, lvl, getImage("lvl"), {255, 30, 150, 255}, {255, 50, 50, 50})
- if options ~= nil then
- for i=1,#options do
- local wep = options[i][1]
- if wep ~= "CANCEL" then
- id = video.createSpriteState(ITEMS[wep].iconName, '../hud.dat')
- UdrawBox(60+(i*47), 14, 20, 20, nil, id, {255, 30, 150, 255}, {255, 255, 255, 255})
- if YESYES < 5 then
- print(wep..": "..id)
- YESYES = YESYES + 1
- end
- end
- end
- end
- end
- end
- hook.add("frameRender", myRender)
- local function onKeyPress(key)
- local ok = true
- if Unlocks.on == true and rPlayer ~= nil then
- for i=1,#Unlocks.keys.options do
- local k = Unlocks.keys.options[i]
- if type(k) == "string" and tonumber(k) == nil then k = getKey(k) end
- if type(k) == "string" then k = tonumber(k) end
- if k == key then
- pickWeapon(rPlayer, i)
- print("Selected weapon")
- ok = false
- end
- end
- end
- local togk = Unlocks.keys.toggle
- if type(togk) == "string" and tonumber(togk) == nil then togk = getKey(togk) end
- if type(togk) == "string" then togk = tonumber(togk) end
- if not ok then
- elseif key == togk then
- local onOff = "on"
- if Unlocks.on == true then
- Unlocks.on = false
- for k,v in pairs(dPlayers) do
- v.xp = nil
- v.xp_level = nil
- v.unlockOptions = nil
- end
- dPlayers = {}
- onOff = "off"
- else
- Unlocks.on = true
- onOff = "on"
- end
- print("Toggled Unlocks ("..onOff..")")
- else
- --print("Unknown key")
- end
- end
- hook.add("keyPress", onKeyPress)
- local function strContains(line, str)
- for i=1,string.len(line) do
- if i < (string.len(line) - string.len(str) + 1) then
- local s = string:sub(i, (i+string.len(str))-1)
- if s == str then return true end
- end
- end
- return false
- end
- local function init()
- local lines = getLines("../controls/unlocks_config.txt")
- if #lines > 0 then
- for i=1,#lines do
- local line = lines[i]
- if line ~= "" and strContains(line, "==") then
- local data = split(line, "==")
- if data ~= nil then
- if #data > 1 then
- local key = string.lower(data[1])
- if key == "alpha" then
- local old = Unlocks.ALPHA
- Unlocks.ALPHA = tonumber(data[2])
- if Unlocks.ALPHA == nil then Unlocks.ALPHA = old end
- elseif key:sub(1, 5) == "tier_" then
- local splt = split(key, "_")
- local tier = tonumber(splt[2])
- if tier ~= nil then
- Unlocks.weapons[tier][#Unlocks.weapons[tier] + 1] = string:gsub(data[2], " ", "")
- end
- elseif key == "reset_tier" then
- local tier = tonumber(data[2])
- Unlocks.weapons[tier] = {}
- elseif key == "max_level" then
- local lvl = tonumber(data[2])
- Unlocks.maxlvl = lvl
- elseif key == "xp_kill" then
- local xp = tonumber(data[2])
- Unlocks.xpKill = xp
- elseif key == "lvl_mod" then
- local lvl = tonumber(data[2])
- Unlocks.lvlMod = lvl
- elseif key == "lvl_mod_amount" or key == "lvl_mod_amt" then
- local lvl = tonumber(data[2])
- Unlocks.lvlModAmt = lvl
- elseif key == "starting_lvl" then
- local lvl = tonumber(data[2])
- Unlocks.startlvl = lvl
- elseif key == "lvl_cost_mod" then
- local lvl = tonumber(data[2])
- Unlocks.lvlCostMod = lvl
- elseif key == "toggle_key" then
- local k = tonumber(data[2])
- Unlocks.keys.toggle = k
- elseif key == "ai_chance" then
- local chance = tonumber(data[2])
- Unlocks.aiChance = chance
- elseif key:sub(1, string.len("option_key_")) == "option_key_" then
- local op = tonumber(key:sub(string.len("option_key_")+1, -1))
- local k = tonumber(data[2])
- if op ~= nil then
- Unlocks.keys.options[op] = k
- end
- elseif key == "options" then
- local n = tonumber(data[2])
- Unlocks.options = n
- end
- end
- end
- end
- end
- end
- local addStat = Player.addStat
- function Player:addStat(stat,num)
- if not contains(dPlayers, self) then
- dPlayers[#dPlayers + 1] = self
- end
- if stat == "kills" and Unlocks.on == true then
- if self.xp == nil then self.xp = num*Unlocks.xpKill else
- self.xp = self.xp + num*Unlocks.xpKill end
- if self.xp_level == nil then self.xp_level = Unlocks.startLevel end
- end
- checkLevel(self)
- return addStat(self,stat,num)
- end
- oldInit = Mode.onInitedMapBehaviours
- function Mode:onInitedMapBehaviours(a,s,d,e,f)
- for k,v in pairs(dPlayers) do
- v.xp = nil
- v.xp_level = nil
- v.unlockOptions = nil
- end
- return oldInit(self,a,s,d,e,f)
- end
- end
- hook.add("gameInit",init)
- icon = video.createSpriteState("ammoLargeDouble_icon", '../hud.dat')
- print(icon)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement