Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GravityGun
- gravity_boolean = {}
- gravity_object = {}
- playerkill = {}
- dist = {}
- streamfire = false
- function GetRequiredVersion()
- return 10057
- end
- function OnScriptLoad(process)
- for i = 1, 16 do
- gravity_boolean[i] = true
- playerkill[i] = {}
- end
- 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)
- local objId = gravity_object[resolveplayer(player)]
- local m_object = getobject(objId)
- writebit(m_object, 0x10, 2, 0) -- Allow vehicle velocity to sync
- gravity_object[resolveplayer(player)] = nil
- playerkill[resolveplayer(player)] = {}
- dist[resolveplayer(player)] = 4
- end
- function OnPlayerKill(killer, victim, mode)
- local objId = gravity_object[resolveplayer(victim)]
- local m_object = getobject(objId)
- writebit(m_object, 0x10, 2, 0)
- gravity_object[resolveplayer(victim)] = nil
- dist[resolveplayer(victim)] = 4
- end
- function OnKillMultiplier(player, multiplier)
- end
- function OnPlayerSpawn(player, m_objId)
- end
- function OnPlayerSpawnEnd(player, m_objId)
- end
- function OnTeamChange(relevant, player, cur_team, dest_team)
- return 1
- end
- function OnObjectCreation(m_objId, player, tagName)
- end
- function OnObjectInteraction(player, m_objId, tagType, tagName)
- return 1
- end
- function OnWeaponAssignment(player, m_objId, slot, tagName)
- local weapon = 0
- if slot >= 0 then
- weapon = lookuptag("weap", "weapons\\plasma rifle\\plasma rifle")
- end
- return weapon
- end
- function OnWeaponReload(player, m_weapId)
- return 1
- end
- function OnDamageLookup(receiver, causer, tagData, tagName)
- local player = objecttoplayer(causer)
- if string.find(tagName, "plasma rifle") ~= nil then
- local tagType, r_tagName = getobjecttag(receiver)
- if tagType == "vehi" then
- local id = resolveplayer(player)
- if gravity_boolean[id] == true then
- local m_object = getobject(causer)
- local r_object = getobject(receiver)
- if gravity_object[id] == nil then
- local index = intable(gravity_object, receiver)
- if index ~= nil then
- gravity_object[index] = nil
- end
- gravity_object[id] = receiver
- playerisvehicle(player, receiver)
- writebit(r_object, 0x10, 2, 0)
- local m_player = getplayer(player)
- local xy_aim = readfloat(m_player, 0x138)
- local z_aim = readfloat(m_player, 0x13C)
- dist[id] = 4
- local x = readfloat(m_object, 0x5C)
- local y = readfloat(m_object, 0x60)
- local z = readfloat(m_object, 0x64)
- writefloat(r_object, 0x5C, x + dist[id] * math.cos(xy_aim))
- writefloat(r_object, 0x60, y + dist[id] * math.sin(xy_aim))
- writefloat(r_object, 0x64, z + dist[id] * math.sin(z_aim) + 0.5)
- writefloat(r_object, 0x68, 0)
- writefloat(r_object, 0x6C, 0)
- writefloat(r_object, 0x70, 0)
- local angular_velocity_x = readfloat(r_object, 0x8C)
- local angular_velocity_y = readfloat(r_object, 0x90)
- local angular_velocity_z = readfloat(r_object, 0x94)
- writefloat(r_object, 0x8C, .2)
- writefloat(r_object, 0x90, .3)
- writefloat(r_object, 0x94, .05)
- else
- gravity_object[id] = nil
- dist[id] = nil
- writebit(r_object, 0x10, 2, 0)
- local x_aim = readfloat(m_object, 0x230)
- local y_aim = readfloat(m_object, 0x234)
- local z_aim = readfloat(m_object, 0x238)
- local vel = 1
- writefloat(r_object, 0x68, vel * math.sin(x_aim))
- writefloat(r_object, 0x6C, vel * math.sin(y_aim))
- writefloat(r_object, 0x70, vel * math.sin(z_aim))
- end
- end
- end
- --[[elseif string.find(tagName, "vehicle") ~= nil then
- local tagType, r_tagName = getobjecttag(receiver)
- if string.find(r_tagName, "cyborg") ~= nil then
- local index = nil
- for i = 1, 16 do
- index = intable(playerkill[i], causer)
- if index ~= nil then
- break
- end
- end
- local playerId = rresolveplayer(index)
- say(getname(playerId))
- local m_player = getplayer(playerId)
- if m_player ~= nil then
- local m_objId = readdword(m_player, 0x34)
- local m_object = getobject(m_objId)
- if m_object ~= nil then
- hprintf("test")
- local x = readfloat(m_object, 0x5C)
- local y = readfloat(m_object, 0x60)
- local z = readfloat(m_object, 0x64)
- hprintf(causer)
- hprintf(playerkill[playerId][resolveplayer(playerId)])
- entervehicle(playerId, causer, 0)
- --movobjcoords(m_object, x, y, z)
- end
- end
- end--]]
- end
- end
- function OnVehicleEntry(relevant, player, m_vehicleId, tagName, seat)
- return 1
- end
- function OnVehicleEject(player, forced)
- return 1
- end
- function OnClientUpdate(player, m_objId)
- local m_object = getobject(m_objId)
- local shooting = readbit(m_object, 0x209, 4) -- 1 when button for firing primary weapon is pressed, otherwise 0
- local flashlight = readbit(m_object, 0x208, 3)
- local action = readbit(m_object, 0x209, 1)
- local unknown = readbit(m_object, 0x208, 2)
- local unknown2 = readbit(m_object, 0x209, 7)
- if unknown ~= 0 then
- say(tostring(unknown))
- end
- if action ~= 0 then
- if dist[resolveplayer(player)] == nil then
- dist[resolveplayer(player)] = 4
- end
- dist[resolveplayer(player)] = dist[resolveplayer(player)] - 0.2
- end
- if flashlight ~= 0 then
- if dist[resolveplayer(player)] == nil then
- dist[resolveplayer(player)] = 4
- end
- dist[resolveplayer(player)] = dist[resolveplayer(player)] + 1
- end
- if shooting == 1 then
- local m_weapId = readdword(m_object, 0x118)
- local tagType, weap_tag = getobjecttag(m_weapId)
- local allow = OnWeaponFire(player, m_objId, m_weapId, weap_tag)
- streamfire = true
- if allow == 0 then
- writebit(m_object, 0x209, 4, 0) -- Do not allow weapon to be fired (does not sync with client)
- end
- else
- streamfire = false
- end
- local id = resolveplayer(player)
- if gravity_object[id] ~= nil then
- local x_aim = readfloat(m_object, 0x230)
- local y_aim = readfloat(m_object, 0x234)
- local z_aim = readfloat(m_object, 0x238)
- local x = readfloat(m_object, 0x5C)
- local y = readfloat(m_object, 0x60)
- local z = readfloat(m_object, 0x64)
- local obj_struct = getobject(gravity_object[id])
- if dist[id] == nil then
- dist[id] = 4
- end
- writefloat(obj_struct, 0x5C, x + dist[id] * math.sin(x_aim))
- writefloat(obj_struct, 0x60, y + dist[id] * math.sin(y_aim))
- writefloat(obj_struct, 0x64, z + dist[id] * math.sin(z_aim) + 0.5)
- writefloat(obj_struct, 0x68, 0)
- writefloat(obj_struct, 0x6C, 0)
- writefloat(obj_struct, 0x70, 0.01285)
- end
- end
- function OnWeaponFire(player, m_objId, m_weapId, weap_tag)
- if streamfire == false then
- if weap_tag == "weapons\\gravity rifle\\gravity rifle" then
- local m_object = getobject(m_objId)
- if m_object ~= nil then
- local x = readfloat(m_object, 0x5C)
- local y = readfloat(m_object, 0x60)
- local z = readfloat(m_object, 0x64)
- local x_aim = readfloat(m_object, 0x230)
- local y_aim = readfloat(m_object, 0x234)
- local z_aim = readfloat(m_object, 0x238)
- local p_objId = createobject("proj", "weapons\\rocket launcher\\rocket", m_objId, 0, false, x, y, z)
- local p_object = getobject(p_objId)
- local parent_id = readword(p_object, 0x11C)
- writeword(p_object, 0x11C, m_objId)
- local vel = 5
- writefloat(p_object, 0x68, vel * math.sin(x_aim))
- writefloat(p_object, 0x6C, vel * math.sin(y_aim))
- writefloat(p_object, 0x70, vel * math.sin(z_aim) + 0.3)
- end
- end
- end
- return 1
- end
- function playerisvehicle(player, vehi_objId)
- playerkill[resolveplayer(player)][#playerkill[resolveplayer(player)] + 1] = vehi_objId
- registertimer(20, "PlayerIsVehicleTimer", player, vehi_objId)
- end
- function PlayerIsVehicleTimer(id, count, player, vehi_objId)
- local playerId = resolveplayer(player)
- local m_player = getplayer(player)
- local m_objId = readdword(m_player, 0x34)
- local m_object = getobject(m_objId)
- local levitated = intable(gravity_object, vehi_objId)
- if levitated == nil then
- local v_object = getobject(vehi_objId)
- local x_vel = readfloat(v_object, 0x68)
- local y_vel = readfloat(v_object, 0x6C)
- local z_vel = readfloat(v_object, 0x70)
- local total_vel = math.sqrt(x_vel ^ 2 + y_vel ^ 2 + z_vel ^ 2)
- if total_vel == 0 then
- local index = intable(playerkill[playerId], vehi_objId)
- playerkill[playerId][index] = nil
- return 0
- end
- else
- if levitated ~= playerId then
- local index = intable(playerkill[playerId], vehi_objId)
- playerkill[playerId][index] = nil
- return 0
- end
- end
- return 1
- end
- function intable(array, entry)
- local index = nil
- for i = 1, #array do
- if entry == array[i] then
- index = i
- break
- end
- end
- return index
- end
- -- Function created by Chalonic
- 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
- -- The following functions were created by Smiley
- 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 todec(number)
- return tonumber(number, 16)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement