Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Custom Weapon Spawns
- weaps = {}
- -- Weapon set (you can add more slots if you so choose; it should still work)
- weaps[0] = "weapons\\needler\\mp_needler"
- weaps[1] = "weapons\\flamethrower\\flamethrower"
- weaps[2] = nil
- weaps[3] = nil
- auto_grenade_types = true -- If this value is true, grenades players spawn with and grenades placed around the map will be determined by the theme of weapons listed above. If it is false, grenades will be placed as defined by the gametype running.
- --[[
- List of valid weapon tags
- Weapon Name Tag Name
- Assault Rifle: "weapons\\assault rifle\\assault rifle"
- Flamethrower: "weapons\\flamethrower\\flamethrower"
- Needler: "weapons\\needler\\mp_needler"
- Pistol: "weapons\\pistol\\pistol"
- Plasma Pistol: "weapons\\plasma pistol\\plasma pistol"
- Plasma Rifle: "weapons\\plasma rifle\\plasma rifle"
- Fuel Rod Gun: "weapons\\plasma_cannon\\plasma_cannon"
- Rocket Launcher: "weapons\\rocket launcher\\rocket launcher"
- Shotgun: "weapons\\shotgun\\shotgun"
- Sniper Rifle: "weapons\\sniper rifle\\sniper rifle"
- --]]
- function GetRequiredVersion()
- return 10058
- end
- function OnScriptLoad(process)
- end
- function OnScriptUnload()
- end
- function OnNewGame(map)
- end
- function OnGameEnd(mode)
- end
- function OnServerChat(player, chattype, message)
- return 1
- end
- function OnServerCommand(player, command)
- return 1
- end
- function OnTeamDecision(team)
- return team
- end
- function OnPlayerJoin(player, team)
- end
- function OnPlayerLeave(player, team)
- end
- function OnPlayerKill(killer, victim, mode)
- end
- function OnKillMultiplier(player, multiplier)
- end
- function OnPlayerSpawn(player, m_objId)
- if auto_grenade_types then
- if infinite_grenades == 0 then
- local m_object = getobject(m_objId)
- if weaps[0] then
- if table.find(attributes[weaps[0]], "Human") then
- writebyte(m_object, 0x31E, 2)
- writebyte(m_object, 0x31F, 0)
- else
- writebyte(m_object, 0x31E, 0)
- writebyte(m_object, 0x31F, 2)
- end
- end
- end
- end
- end
- function OnPlayerSpawnEnd(player, m_objId)
- end
- function OnTeamChange(relevant, player, cur_team, dest_team)
- return 1
- end
- function OnObjectCreation(m_objId, player, tagName)
- if new_object_orientation then
- rotateobject(m_objId, new_object_orientation)
- new_object_orientation = nil
- end
- local tagType, tagName = getobjecttag(m_objId)
- if tagType == "weap" then
- if attributes[tagName] then
- if not table.find(weaps, tagName) then
- local x, y, z = getobjectcoords(m_objId)
- movobjcoords(m_objId, 0, 0, -100)
- local newtagName = similar(tagName)
- local orientation = getobjectorientation(m_objId)
- createobject("weap", newtagName, 0, 45, true, x, y, z, orientation)
- end
- end
- end
- if auto_grenade_types then
- if grenadetype == 0 then
- if tagType == "eqip" then
- if tagName == "weapons\\plasma grenade\\plasma grenade" then
- local x, y, z = getobjectcoords(m_objId)
- movobjcoords(m_objId, 0, 0, -100)
- local orientation = getobjectorientation(m_objId)
- createobject("eqip", "weapons\\frag grenade\\frag grenade", 0, 45, true, x, y, z, orientation)
- end
- end
- elseif grenadetype == 1 then
- if tagType == "eqip" then
- if tagName == "weapons\\frag grenade\\frag grenade" then
- local x, y, z = getobjectcoords(m_objId)
- movobjcoords(m_objId, 0, 0, -100)
- local orientation = getobjectorientation(m_objId)
- createobject("eqip", "weapons\\plasma grenade\\plasma grenade", 0, 45, true, x, y, z, orientation)
- end
- end
- end
- end
- end
- function OnObjectInteraction(player, m_objId, tagType, tagName)
- return 1
- end
- function OnWeaponAssignment(player, m_objId, slot, tagName)
- if weaps[slot] then
- return lookuptag("weap", weaps[slot])
- else
- return lookuptag("weap", weaps[slot - 1])
- end
- return 0
- end
- function OnWeaponReload(player, m_weapId)
- return 1
- end
- function OnDamageLookup(receiver, causer, tagData, tagName)
- end
- function OnVehicleEntry(relevant, player, m_vehicleId, tagName, seat)
- return 1
- end
- function OnVehicleEject(player, forced)
- return 1
- end
- function OnClientUpdate(player, m_objId)
- end
- -- Createobject override
- phasor_createobject = createobject
- new_object_orientation = nil
- spawns = {}
- objects = {}
- registertimer(10, "ActiveObjectTimer")
- function ActiveObjectTimer(id, count)
- for k,v in pairs(objects) do
- if v.tagType == "weap" then
- -- Player holding weapon?
- local carried
- for i = 0,15 do
- if gethash(i) then
- local m_player = getplayer(i)
- local m_objId = readdword(m_player, 0x34)
- local m_object = getobject(m_objId)
- if m_object then
- for x = 0,3 do
- local m_weapId = readdword(m_object, 0x2F8 + (x * 4))
- if m_weapId == k then
- carried = true
- break
- end
- end
- if carried then break end
- end
- end
- end
- -- Determine if it is active or not
- if not carried then
- if objects[k].active then
- objects[k].active = false
- local timerid = registertimer(spawns[objects[k].spawn].respawn_time * 1000, "DespawnTimer", k)
- objects[k].desptimer = timerid
- end
- else
- if not objects[k].active then
- objects[k].active = true
- removetimer(objects[k].desptimer)
- end
- end
- elseif v.tagType == "vehi" then
- local active
- for i = 0,15 do
- if gethash(i) then
- local m_player = getplayer(i)
- local m_objId = readdword(m_player, 0x34)
- local m_object = getobject(m_objId)
- if m_object then
- local m_vehicleId = readdword(m_object, 0x11C)
- if m_vehicleId == k then
- active = true
- break
- end
- end
- end
- end
- if active then
- if not objects[k].active then
- objects[k].active = true
- removetimer(objects[k].desptimer)
- removetimer(spawns[objects[k].spawn].resptimer)
- end
- else
- if objects[k].active then
- objects[k].active = false
- local desptimerid = registertimer(spawns[objects[k].spawn].respawn_time * 1000, "DespawnTimer", k)
- local resptimerid = registertimer(spawns[objects[k].spawn].respawn_time * 1000, "RespawnTimer", objects[k].spawn)
- objects[k].desptimer = desptimerid
- spawns[objects[k].spawn].resptimer = resptimerid
- end
- end
- end
- end
- return 1
- end
- function createobject(tagType, tagName, parentId, respawn_time, respawn_bool, x, y, z, orientation)
- local m_objId
- -- Nil checks
- x = x or 0
- y = y or 0
- z = z or 0
- orientation = orientation or 0
- if respawn_time > 0 then
- new_object_orientation = orientation
- m_objId = phasor_createobject(tagType, tagName, parentId, 0, false, x, y, z)
- if m_objId then
- rotateobject(m_objId, orientation)
- objects[m_objId] = {}
- objects[m_objId].tagType = tagType
- objects[m_objId].tagName = tagName
- objects[m_objId].active = false
- local desptimerid = registertimer(respawn_time * 1000, "DespawnTimer", m_objId)
- local resptimerid
- if respawn_bool then
- resptimerid = registertimer(respawn_time * 1000, "RespawnTimer", #spawns + 1)
- end
- local temp = {}
- temp.tagType = tagType
- temp.tagName = tagName
- temp.parentId = parentId
- temp.respawn_time = respawn_time
- temp.respawn_bool = true
- temp.x = x
- temp.y = y
- temp.z = z
- temp.orientation = orientation
- temp.resptimer = resptimerid
- table.insert(spawns, temp)
- objects[m_objId].spawn = #spawns
- objects[m_objId].desptimer = desptimerid
- else
- hprintf("Invalid tag")
- end
- else
- new_object_orientation = orientation
- m_objId = phasor_createobject(tagType, tagName, parentId, 0, false, x, y, z)
- if not m_objId then
- hprintf("Invalid tag")
- end
- end
- return m_objId
- end
- function respawnobject(key)
- if spawns[key] then
- new_object_orientation = spawns[key].orientation
- local m_objId = phasor_createobject(spawns[key].tagType, spawns[key].tagName, spawns[key].parentId, spawns[key].respawn_time, spawns[key].respawn_bool, spawns[key].x, spawns[key].y, spawns[key].z)
- rotateobject(m_objId, spawns[key].orientation)
- local timerid = registertimer(spawns[key].respawn_time * 1000, "DespawnTimer", m_objId)
- objects[m_objId] = {}
- objects[m_objId].tagType = spawns[key].tagType
- objects[m_objId].tagName = spawns[key].tagName
- objects[m_objId].active = false
- objects[m_objId].spawn = key
- objects[m_objId].desptimer = timerid
- end
- end
- function rotateobject(m_objId, orientation)
- local m_object = getobject(m_objId)
- if m_object then
- local x_comp = -math.sin(orientation)
- local y_comp = -math.cos(orientation)
- writebit(m_object, 0x10, 2, 0)
- writefloat(m_object, 0x74, x_comp)
- writefloat(m_object, 0x78, y_comp)
- end
- end
- function getobjectorientation(m_objId)
- local m_object = getobject(m_objId)
- local x_vector = readfloat(m_object, 0x74)
- return -math.asin(x_vector)
- end
- function RespawnTimer(id, count, spawn)
- respawnobject(spawn)
- return 1
- end
- function DespawnTimer(id, count, m_objId)
- if getobject(m_objId) then
- destroyobject(m_objId)
- objects[m_objId] = nil
- end
- return 0
- end
- function getobjecttag(m_objId)
- local m_object = getobject(m_objId)
- local object_map_id = readdword(m_object, 0x0)
- local map_pointer = 0x460678
- local map_base = readdword(map_pointer, 0x0)
- local map_tag_count = todec(endian(map_base, 0xC, 0x3))
- local tag_table_base = map_base + 0x28
- local tag_table_size = 0x20
- for i = 0, (map_tag_count - 1) do
- local tag_id = todec(endian(tag_table_base, 0xC + (tag_table_size * i), 0x3))
- if tag_id == object_map_id then
- local tag_class = readstring(tag_table_base, (tag_table_size * i), 0x3, 1)
- local tag_name_address = endian(tag_table_base, 0x10 + (tag_table_size * i), 0x3)
- local tag_name = readtagname("0x" .. tag_name_address)
- return tag_class, tag_name
- end
- end
- end
- function readstring(address, offset, length, endian)
- local char_table = {}
- local string = ""
- for i=0,length do
- if readbyte(address, (offset + (0x1 * i))) ~= 0 then
- table.insert(char_table, string.char(readbyte(address, (offset + (0x1 * i)))))
- end
- end
- for k,v in pairs(char_table) do
- if endian == 1 then
- string = v .. string
- else
- string = string .. v
- end
- end
- return string
- end
- function readtagname(address)
- local char_table = {}
- local i = 0
- local string = ""
- while readbyte(address, (0x1 * i)) ~= 0 do
- table.insert(char_table, string.char(readbyte(address, (0x1 * i))))
- i = i + 1
- end
- for k,v in pairs(char_table) do
- string = string .. v
- end
- return string
- end
- function endian(address, offset, length)
- local data_table = {}
- local data = ""
- for i=0,length do
- local hex = string.format("%X", readbyte(address, offset + (0x1 * i)))
- if tonumber(hex, 16) < 16 then
- hex = 0 .. hex
- end
- table.insert(data_table, hex)
- end
- for k,v in pairs(data_table) do
- data = v .. data
- end
- return data
- end
- function tohex(number)
- return string.format("%X", number)
- end
- function todec(number)
- return tonumber(number, 16)
- end
- function opairs(t)
- local keys = {}
- for k,v in pairs(t) do
- table.insert(keys, k)
- end
- table.sort(keys,
- function(a,b)
- if type(a) == "number" and type(b) == "number" then
- return a < b
- end
- an = string.lower(tostring(a))
- bn = string.lower(tostring(b))
- if an ~= bn then
- return an < bn
- else
- return tostring(a) < tostring(b)
- end
- end)
- local count = 1
- return function()
- if unpack(keys) then
- local key = keys[count]
- local value = t[key]
- count = count + 1
- return key,value
- end
- end
- end
- function table.find(t, val)
- for k,v in pairs(t) do
- if v == val then
- return k
- end
- end
- end
- math.inf = 1 / 0
- attributes = {}
- attributes["weapons\\assault rifle\\assault rifle"] = {"Short-Range", "Rifle", "Human"}
- attributes["weapons\\pistol\\pistol"] = {"Mid-Range", "Accurate", "Human"}
- attributes["weapons\\shotgun\\shotgun"] = {"Short-Range", "Inaccurate", "Human"}
- attributes["weapons\\sniper rifle\\sniper rifle"] = {"Long-Range", "Accurate", "Human"}
- attributes["weapons\\flamethrower\\flamethrower"] = {"Short-Range", "Heavy", "Human"}
- attributes["weapons\\rocket launcher\\rocket launcher"] = {"Mid-Range", "Heavy", "Human"}
- attributes["weapons\\plasma pistol\\plasma pistol"] = {"Mid-Range", "Accurate", "Covenant"}
- attributes["weapons\\plasma rifle\\plasma rifle"] = {"Mid-Range", "Rifle", "Covenant"}
- attributes["weapons\\needler\\mp_needler"] = {"Mid-Range", "Inaccurate", "Covenant"}
- attributes["weapons\\plasma_cannon\\plasma_cannon"] = {"Mid-Range", "Heavy", "Covenant"}
- function similar(tagName)
- local max = -math.inf
- local newtag = ""
- for k,v in opairs(weaps) do
- local count = 0
- for _,a in ipairs(attributes[tagName]) do
- if table.find(attributes[v], a) then
- count = count + 1
- end
- end
- if count > max then
- newtag = v
- max = count
- end
- end
- return newtag
- end
- function getgrenadetype()
- local human, covenant
- for k,v in pairs(weaps) do
- if table.find(attributes[v], "Human") then
- human = true
- else
- covenant = true
- end
- end
- -- Human and Covenant = 2; Covenant = 1; Human = 0
- if human and covenant then
- return 2
- elseif not human and covenant then
- return 1
- else
- return 0
- end
- end
- function formatbinary(num, digits)
- local binary = convertbase(num, 2)
- while string.len(binary) < digits do
- binary = "0" .. binary
- end
- return binary
- end
- function convertbase(input, base)
- if not base or base == 10 then return tostring(input) end
- local digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- local answer = {}
- repeat
- local digit = (input % base) + 1
- input = math.floor(input / base)
- table.insert(answer, 1, string.sub(digits, digit, digit))
- until input == 0
- return table.concat(answer, "")
- end
- grenadetype = getgrenadetype()
- parameters = formatbinary(readbyte(0x671340, 0x38), 8)
- infinite_grenades = tonumber(string.sub(parameters, 6, 6))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement