Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 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 getplayer(i) then
- local m_player = getplayer(i)
- local objId = readdword(m_player, 0x34)
- local m_object = getobject(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
- if objects[k].pickedup then
- local timerid = registertimer(spawns[objects[k].spawn].respawn_time * 1000, "DespawnTimer", k)
- objects[k].desptimer = timerid
- end
- end
- else
- if not objects[k].active then
- objects[k].pickedup = true
- objects[k].active = true
- if objects[k].desptimer then
- removetimer(objects[k].desptimer)
- end
- end
- end
- elseif v.tagtype == "vehi" then
- local active
- for i = 0,15 do
- if gethash(i) then
- local m_player = getplayer(i)
- local objId = readdword(m_player, 0x34)
- local m_object = getobject(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 true
- end
- function createobject(mapId, parentId, respawn_time, respawn_bool, x, y, z, orientation)
- local objId
- -- Nil checks
- x = x or 0
- y = y or 0
- z = z or 0
- orientation = orientation or 0
- local tagname, tagtype = gettaginfo(mapId)
- if respawn_time > 0 then
- new_object_orientation = orientation
- objId = phasor_createobject(mapId, parentId, 0, false, x, y, z)
- if objId then
- rotateobject(objId, orientation)
- objects[objId] = {}
- objects[objId].tagtype = tagtype
- objects[objId].tagname = tagname
- objects[objId].active = false
- --local desptimerid = registertimer(respawn_time * 1000, "DespawnTimer", 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[objId].spawn = #spawns
- --objects[objId].desptimer = desptimerid
- else
- hprintf("Invalid tag")
- end
- else
- new_object_orientation = orientation
- objId = phasor_createobject(mapId, parentId, 0, false, x, y, z)
- if not objId then
- hprintf("Invalid mapId")
- end
- end
- return objId
- end
- function respawnobject(key)
- if spawns[key] then
- local exists
- local m_object
- for k,v in pairs(objects) do
- if objects[k].spawn == key then
- m_object = getobject(k)
- if m_object then
- exists = k
- break
- end
- end
- end
- if not exists then
- new_object_orientation = spawns[key].orientation
- local 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(objId, spawns[key].orientation)
- --local timerid = registertimer(spawns[key].respawn_time * 1000, "DespawnTimer", objId)
- objects[objId] = {}
- objects[objId].tagtype = spawns[key].tagtype
- objects[objId].tagname = spawns[key].tagname
- objects[objId].active = false
- objects[objId].spawn = key
- --objects[objId].desptimer = timerid
- else
- if objects[exists].pickedup then
- new_object_orientation = spawns[key].orientation
- local 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(objId, spawns[key].orientation)
- --local timerid = registertimer(spawns[key].respawn_time * 1000, "DespawnTimer", objId)
- objects[objId] = {}
- objects[objId].tagtype = spawns[key].tagtype
- objects[objId].tagname = spawns[key].tagname
- objects[objId].active = false
- objects[objId].spawn = key
- --objects[objId].desptimer = timerid
- else
- movobjcoords(exists, spawns[key].x, spawns[key].y, spawns[key].z)
- rotateobject(exists, spawns[key].orientation)
- writebit(m_object, 0x10, 2, 0)
- end
- end
- end
- end
- function rotateobject(objId, orientation)
- local m_object = getobject(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(objId)
- local m_object = getobject(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, objId)
- if getobject(objId) then
- destroyobject(objId)
- end
- objects[objId] = nil
- return 0
- end
- function GetRequiredVersion()
- return 10059
- 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, objId)
- local mapId = gettagid("weap", "weapons\\sniper rifle\\sniper rifle")
- createobject(mapId, 0, 10, true, 0, 0, 0.5, math.pi / 4)
- end
- function OnPlayerSpawnEnd(player, objId)
- end
- function OnTeamChange(relevant, player, cur_team, dest_team)
- return 1
- end
- function OnObjectCreation(objId, player, tagname)
- if new_object_orientation then
- rotateobject(objId, new_object_orientation)
- new_object_orientation = nil
- end
- end
- function OnObjectInteraction(player, objId, tagtype, tagname)
- return 1
- end
- function OnWeaponAssignment(player, objId, slot, tagname)
- 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, objId)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement