local gun = {} local upgrade_base_cost = {} state = {} upgrade_level = {} local upgrade_base_amount = {} local upgrade_cost = {} local max_guns = 9 local highlighted = 1 local max_upgrades = 3 local allowed_weapons = {} local temp = 0 local gunid = 0 pressed = 0 money = 10000 --starting money player has to spend on upgrades local culmative_upgrade_costs = 1 --set to 1 if you want costs to increase after each upgrade function weapon_upgrader_rapidfire_init(e) --note costs are muliplied by the current upgrade level if culmative_upgrade_costs is set to 1 upgrade_base_cost["damage"] = 100 --how much it costs to upgrade damage per level upgrade_base_cost["accuracy"] = 50 --how much it costs to upgrade accuracy per level upgrade_base_cost["clip size"] = 180 --how much it costs to upgrade clip size per level upgrade_base_amount["damage"] = 1 --how much damage to add per level upgrade_base_amount["accuracy"] = 5 --how much accuracy to add per level upgrade_base_amount["clip size"] = 20 --how many bullets to add to clip size per level (no ammo is added) --name of allowed weapons here (can find these by walking up to character with desired weapon held) allowed_weapons[1] = "tommy_gun" allowed_weapons[2] = "uzi" allowed_weapons[3] = "" state[e] = "greet" upgrade_level["damage"] = {} upgrade_level["accuracy"] = {} upgrade_level["clip size"] = {} upgrade_cost["damage"] = 0 upgrade_cost["accuracy"] = 0 upgrade_cost["clip size"] = 0 end function weapon_upgrader_rapidfire_main(e) if GetPlayerDistance(e) < 300 then RotateToPlayer(e) elseif GetPlayerDistance(e) < 600 then RotateToPlayerSlowly(e,1) end if state[e] == "greet" then if PlayerLooking(e,200,5) == 1 then if g_PlayerGunName ~= "" then temp = string.find(g_PlayerGunName, "\\") if temp == nil then temp = 0 end new_gun_name = string.sub(g_PlayerGunName,temp+1) temp = 0 Prompt("Sorry, I can't upgrade that "..new_gun_name) repeat temp = temp+1 if allowed_weapons[temp] == nil then return end until new_gun_name == allowed_weapons[temp] Prompt("Hey there, would you like me to upgrade that "..new_gun_name.."?") if g_KeyPressE == 1 and pressed == 0 then pressed = 1 state[e] = "upgrade menu" gunid = g_PlayerGunID SetPlayerWeapons(0) FreezePlayer() highlighted = 1 end else Prompt("Hey there, I can upgrade your weapon if you bring me one") end end elseif state[e] == "upgrade menu" then TextCenterOnX(50,85,4,"Upgrading "..new_gun_name) TextCenterOnX(50,90,3,"(W or S to cycle menu, E to select , press Q to exit)") if highlighted == 1 then Panel(30,30,70,40) TextCenterOnX(50,33,4,"[1] DAMAGE") upgrading = "damage" else TextCenterOnX(50,33,4,"[1] DAMAGE") Panel(30,30,70,40) end if highlighted == 2 then Panel(30,45,70,55) TextCenterOnX(50,48,4,"[2] ACCURACY") upgrading = "accuracy" else TextCenterOnX(50,48,4,"[2] ACCURACY") Panel(30,45,70,55) end if highlighted == 3 then Panel(30,60,70,70) TextCenterOnX(50,63,4,"[3] CLIP SIZE") upgrading = "clip size" else TextCenterOnX(50,63,4,"[3] CLIP SIZE") Panel(30,60,70,70) end if g_KeyPressW == 1 and pressed == 0 then pressed = 1 if highlighted > 1 then highlighted = highlighted - 1 else highlighted = max_upgrades end end if g_KeyPressS == 1 and pressed == 0 then pressed = 1 if highlighted < max_upgrades then highlighted = highlighted + 1 else highlighted = 1 end end if g_Scancode == 16 and pressed == 0 then pressed = 1 UnFreezePlayer() state[e] = "greet" SetPlayerWeapons(1) ChangePlayerWeaponID(gunid) end if g_KeyPressE == 1 and pressed == 0 then pressed = 1 --upgrading = highlighted state[e] = "upgrading" end elseif state[e] == "upgrading" then Panel(30,45,70,55) if upgrading == "damage" then TextCenterOnX(50,48,4,"Current Damage = "..GetWeaponDamage(gunid,0)) end if upgrading == "accuracy" then TextCenterOnX(50,48,4,"Current ACCURACY = "..GetWeaponAccuracy(gunid,0)) end if upgrading == "clip size" then TextCenterOnX(50,48,4,"Current Clip size = "..GetWeaponReloadQuantity(gunid,0)) end if upgrade_level[upgrading][gunid] == nil then upgrade_level[upgrading][gunid] = 1 end if culmative_upgrade_costs == 1 then upgrade_cost[upgrading] = upgrade_level[upgrading][gunid]*upgrade_base_cost[upgrading] else upgrade_cost[upgrading] = upgrade_base_cost[upgrading] end Panel(30,60,70,70) TextCenterOnX(50,63,4,"Upgrade level = "..upgrade_level[upgrading][gunid].." , Upgrade cost = "..upgrade_cost[upgrading]) TextCenterOnX(50,80,4,"Money = "..money) TextCenterOnX(50,85,4,"Upgrading "..new_gun_name.." damage") TextCenterOnX(50,90,3,"(Press E to confirm or Q to go back)") if g_KeyPressE == 1 and pressed == 0 then pressed = 1 if money >= upgrade_cost[upgrading] then PlaySound(e,1) money = money - upgrade_cost[upgrading] upgrade_level[upgrading][gunid] = upgrade_level[upgrading][gunid]+1 if upgrading == "damage" then SetWeaponDamage(gunid,0,GetWeaponDamage(gunid,0)+upgrade_base_amount[upgrading]) elseif upgrading == "accuracy" then SetWeaponAccuracy(gunid,0,GetWeaponAccuracy(gunid,0)+upgrade_base_amount[upgrading]) elseif upgrading == "clip size" then SetWeaponReloadQuantity(gunid,0,GetWeaponReloadQuantity(gunid,0)+upgrade_base_amount[upgrading]) end end end if g_Scancode == 16 and pressed == 0 then pressed = 1 --UnFreezePlayer() state[e] = "upgrade menu" --SetPlayerWeapons(1) --ChangePlayerWeaponID(gunid) end end --state if g_Scancode == 0 then pressed = 0 end end function weapon_upgrader_rapidfire_exit(e) end function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return 0 end else return 0 end end end