Advertisement
th3w1zard1

test

May 5th, 2012
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.84 KB | None | 0 0
  1. -- GravityGun
  2.  
  3. gravity_boolean = {}
  4. gravity_object = {}
  5. playerkill = {}
  6. dist = {}
  7.  
  8. streamfire = false
  9.  
  10. function GetRequiredVersion()
  11.  
  12. return 10057
  13. end
  14.  
  15. function OnScriptLoad(process)
  16.  
  17. for i = 1, 16 do
  18. gravity_boolean[i] = true
  19. playerkill[i] = {}
  20. end
  21. end
  22.  
  23. function OnScriptUnload()
  24.  
  25.  
  26. end
  27.  
  28. function OnNewGame(map)
  29.  
  30.  
  31. end
  32.  
  33. function OnGameEnd(mode)
  34.  
  35.  
  36. end
  37.  
  38. function OnServerChat(player, chattype, message)
  39.  
  40. return 1
  41. end
  42.  
  43. function OnServerCommand(player, command)
  44.  
  45. return 1
  46. end
  47.  
  48. function OnTeamDecision(team)
  49.  
  50. return team
  51. end
  52.  
  53. function OnPlayerJoin(player, team)
  54.  
  55.  
  56. end
  57.  
  58. function OnPlayerLeave(player, team)
  59.  
  60. local objId = gravity_object[resolveplayer(player)]
  61. local m_object = getobject(objId)
  62. writebit(m_object, 0x10, 2, 0) -- Allow vehicle velocity to sync
  63. gravity_object[resolveplayer(player)] = nil
  64. playerkill[resolveplayer(player)] = {}
  65. dist[resolveplayer(player)] = 4
  66. end
  67.  
  68. function OnPlayerKill(killer, victim, mode)
  69.  
  70. local objId = gravity_object[resolveplayer(victim)]
  71. local m_object = getobject(objId)
  72. writebit(m_object, 0x10, 2, 0)
  73. gravity_object[resolveplayer(victim)] = nil
  74. dist[resolveplayer(victim)] = 4
  75. end
  76.  
  77. function OnKillMultiplier(player, multiplier)
  78.  
  79.  
  80. end
  81.  
  82. function OnPlayerSpawn(player, m_objId)
  83.  
  84.  
  85. end
  86.  
  87. function OnPlayerSpawnEnd(player, m_objId)
  88.  
  89.  
  90. end
  91.  
  92. function OnTeamChange(relevant, player, cur_team, dest_team)
  93.  
  94.  
  95. return 1
  96. end
  97.  
  98. function OnObjectCreation(m_objId, player, tagName)
  99.  
  100.  
  101. end
  102.  
  103. function OnObjectInteraction(player, m_objId, tagType, tagName)
  104.  
  105. return 1
  106. end
  107.  
  108. function OnWeaponAssignment(player, m_objId, slot, tagName)
  109.  
  110. local weapon = 0
  111.  
  112. if slot >= 0 then
  113. weapon = lookuptag("weap", "weapons\\plasma rifle\\plasma rifle")
  114. end
  115.  
  116. return weapon
  117. end
  118.  
  119. function OnWeaponReload(player, m_weapId)
  120.  
  121. return 1
  122. end
  123.  
  124. function OnDamageLookup(receiver, causer, tagData, tagName)
  125.  
  126. local player = objecttoplayer(causer)
  127. if string.find(tagName, "plasma rifle") ~= nil then
  128. local tagType, r_tagName = getobjecttag(receiver)
  129. if tagType == "vehi" then
  130. local id = resolveplayer(player)
  131. if gravity_boolean[id] == true then
  132. local m_object = getobject(causer)
  133. local r_object = getobject(receiver)
  134. if gravity_object[id] == nil then
  135. local index = intable(gravity_object, receiver)
  136. if index ~= nil then
  137. gravity_object[index] = nil
  138. end
  139. gravity_object[id] = receiver
  140. playerisvehicle(player, receiver)
  141. writebit(r_object, 0x10, 2, 0)
  142. local m_player = getplayer(player)
  143. local xy_aim = readfloat(m_player, 0x138)
  144. local z_aim = readfloat(m_player, 0x13C)
  145. dist[id] = 4
  146. local x = readfloat(m_object, 0x5C)
  147. local y = readfloat(m_object, 0x60)
  148. local z = readfloat(m_object, 0x64)
  149. writefloat(r_object, 0x5C, x + dist[id] * math.cos(xy_aim))
  150. writefloat(r_object, 0x60, y + dist[id] * math.sin(xy_aim))
  151. writefloat(r_object, 0x64, z + dist[id] * math.sin(z_aim) + 0.5)
  152. writefloat(r_object, 0x68, 0)
  153. writefloat(r_object, 0x6C, 0)
  154. writefloat(r_object, 0x70, 0)
  155. local angular_velocity_x = readfloat(r_object, 0x8C)
  156. local angular_velocity_y = readfloat(r_object, 0x90)
  157. local angular_velocity_z = readfloat(r_object, 0x94)
  158. writefloat(r_object, 0x8C, .2)
  159. writefloat(r_object, 0x90, .3)
  160. writefloat(r_object, 0x94, .05)
  161. else
  162. gravity_object[id] = nil
  163. dist[id] = nil
  164. writebit(r_object, 0x10, 2, 0)
  165. local x_aim = readfloat(m_object, 0x230)
  166. local y_aim = readfloat(m_object, 0x234)
  167. local z_aim = readfloat(m_object, 0x238)
  168. local vel = 1
  169. writefloat(r_object, 0x68, vel * math.sin(x_aim))
  170. writefloat(r_object, 0x6C, vel * math.sin(y_aim))
  171. writefloat(r_object, 0x70, vel * math.sin(z_aim))
  172. end
  173. end
  174. end
  175. --[[elseif string.find(tagName, "vehicle") ~= nil then
  176. local tagType, r_tagName = getobjecttag(receiver)
  177. if string.find(r_tagName, "cyborg") ~= nil then
  178. local index = nil
  179. for i = 1, 16 do
  180. index = intable(playerkill[i], causer)
  181. if index ~= nil then
  182. break
  183. end
  184. end
  185. local playerId = rresolveplayer(index)
  186. say(getname(playerId))
  187. local m_player = getplayer(playerId)
  188. if m_player ~= nil then
  189. local m_objId = readdword(m_player, 0x34)
  190. local m_object = getobject(m_objId)
  191. if m_object ~= nil then
  192. hprintf("test")
  193. local x = readfloat(m_object, 0x5C)
  194. local y = readfloat(m_object, 0x60)
  195. local z = readfloat(m_object, 0x64)
  196. hprintf(causer)
  197. hprintf(playerkill[playerId][resolveplayer(playerId)])
  198. entervehicle(playerId, causer, 0)
  199. --movobjcoords(m_object, x, y, z)
  200. end
  201. end
  202. end--]]
  203. end
  204. end
  205.  
  206. function OnVehicleEntry(relevant, player, m_vehicleId, tagName, seat)
  207.  
  208. return 1
  209. end
  210.  
  211. function OnVehicleEject(player, forced)
  212.  
  213. return 1
  214. end
  215.  
  216. function OnClientUpdate(player, m_objId)
  217.  
  218. local m_object = getobject(m_objId)
  219. local shooting = readbit(m_object, 0x209, 4) -- 1 when button for firing primary weapon is pressed, otherwise 0
  220. local flashlight = readbit(m_object, 0x208, 3)
  221. local action = readbit(m_object, 0x209, 1)
  222. local unknown = readbit(m_object, 0x208, 2)
  223. local unknown2 = readbit(m_object, 0x209, 7)
  224. if unknown ~= 0 then
  225. say(tostring(unknown))
  226. end
  227. if action ~= 0 then
  228. if dist[resolveplayer(player)] == nil then
  229. dist[resolveplayer(player)] = 4
  230. end
  231. dist[resolveplayer(player)] = dist[resolveplayer(player)] - 0.2
  232. end
  233. if flashlight ~= 0 then
  234. if dist[resolveplayer(player)] == nil then
  235. dist[resolveplayer(player)] = 4
  236. end
  237. dist[resolveplayer(player)] = dist[resolveplayer(player)] + 1
  238. end
  239.  
  240. if shooting == 1 then
  241. local m_weapId = readdword(m_object, 0x118)
  242. local tagType, weap_tag = getobjecttag(m_weapId)
  243. local allow = OnWeaponFire(player, m_objId, m_weapId, weap_tag)
  244. streamfire = true
  245. if allow == 0 then
  246. writebit(m_object, 0x209, 4, 0) -- Do not allow weapon to be fired (does not sync with client)
  247. end
  248. else
  249. streamfire = false
  250. end
  251.  
  252. local id = resolveplayer(player)
  253. if gravity_object[id] ~= nil then
  254. local x_aim = readfloat(m_object, 0x230)
  255. local y_aim = readfloat(m_object, 0x234)
  256. local z_aim = readfloat(m_object, 0x238)
  257. local x = readfloat(m_object, 0x5C)
  258. local y = readfloat(m_object, 0x60)
  259. local z = readfloat(m_object, 0x64)
  260. local obj_struct = getobject(gravity_object[id])
  261. if dist[id] == nil then
  262. dist[id] = 4
  263. end
  264. writefloat(obj_struct, 0x5C, x + dist[id] * math.sin(x_aim))
  265. writefloat(obj_struct, 0x60, y + dist[id] * math.sin(y_aim))
  266. writefloat(obj_struct, 0x64, z + dist[id] * math.sin(z_aim) + 0.5)
  267. writefloat(obj_struct, 0x68, 0)
  268. writefloat(obj_struct, 0x6C, 0)
  269. writefloat(obj_struct, 0x70, 0.01285)
  270. end
  271. end
  272.  
  273. function OnWeaponFire(player, m_objId, m_weapId, weap_tag)
  274.  
  275. if streamfire == false then
  276. if weap_tag == "weapons\\gravity rifle\\gravity rifle" then
  277. local m_object = getobject(m_objId)
  278. if m_object ~= nil then
  279. local x = readfloat(m_object, 0x5C)
  280. local y = readfloat(m_object, 0x60)
  281. local z = readfloat(m_object, 0x64)
  282. local x_aim = readfloat(m_object, 0x230)
  283. local y_aim = readfloat(m_object, 0x234)
  284. local z_aim = readfloat(m_object, 0x238)
  285. local p_objId = createobject("proj", "weapons\\rocket launcher\\rocket", m_objId, 0, false, x, y, z)
  286. local p_object = getobject(p_objId)
  287. local parent_id = readword(p_object, 0x11C)
  288. writeword(p_object, 0x11C, m_objId)
  289. local vel = 5
  290. writefloat(p_object, 0x68, vel * math.sin(x_aim))
  291. writefloat(p_object, 0x6C, vel * math.sin(y_aim))
  292. writefloat(p_object, 0x70, vel * math.sin(z_aim) + 0.3)
  293. end
  294. end
  295. end
  296.  
  297. return 1
  298. end
  299.  
  300. function playerisvehicle(player, vehi_objId)
  301.  
  302. playerkill[resolveplayer(player)][#playerkill[resolveplayer(player)] + 1] = vehi_objId
  303. registertimer(20, "PlayerIsVehicleTimer", player, vehi_objId)
  304. end
  305.  
  306. function PlayerIsVehicleTimer(id, count, player, vehi_objId)
  307.  
  308. local playerId = resolveplayer(player)
  309. local m_player = getplayer(player)
  310. local m_objId = readdword(m_player, 0x34)
  311. local m_object = getobject(m_objId)
  312. local levitated = intable(gravity_object, vehi_objId)
  313.  
  314. if levitated == nil then
  315. local v_object = getobject(vehi_objId)
  316. local x_vel = readfloat(v_object, 0x68)
  317. local y_vel = readfloat(v_object, 0x6C)
  318. local z_vel = readfloat(v_object, 0x70)
  319. local total_vel = math.sqrt(x_vel ^ 2 + y_vel ^ 2 + z_vel ^ 2)
  320. if total_vel == 0 then
  321. local index = intable(playerkill[playerId], vehi_objId)
  322. playerkill[playerId][index] = nil
  323. return 0
  324. end
  325. else
  326. if levitated ~= playerId then
  327. local index = intable(playerkill[playerId], vehi_objId)
  328. playerkill[playerId][index] = nil
  329. return 0
  330. end
  331. end
  332.  
  333. return 1
  334. end
  335.  
  336. function intable(array, entry)
  337.  
  338. local index = nil
  339.  
  340. for i = 1, #array do
  341. if entry == array[i] then
  342. index = i
  343. break
  344. end
  345. end
  346.  
  347. return index
  348. end
  349.  
  350. -- Function created by Chalonic
  351. function getobjecttag(m_objId)
  352.  
  353. local m_object = getobject(m_objId)
  354. local object_map_id = readdword(m_object, 0x0)
  355.  
  356. local map_pointer = 0x460678
  357. local map_base = readdword(map_pointer, 0x0)
  358. local map_tag_count = todec(endian(map_base, 0xC, 0x3))
  359. local tag_table_base = map_base + 0x28
  360. local tag_table_size = 0x20
  361.  
  362. for i = 0, (map_tag_count - 1) do
  363. local tag_id = todec(endian(tag_table_base, 0xC + (tag_table_size * i), 0x3))
  364.  
  365. if tag_id == object_map_id then
  366. local tag_class = readstring(tag_table_base, (tag_table_size * i), 0x3, 1)
  367. local tag_name_address = endian(tag_table_base, 0x10 + (tag_table_size * i), 0x3)
  368. local tag_name = readtagname("0x" .. tag_name_address)
  369.  
  370. return tag_class, tag_name
  371. end
  372. end
  373. end
  374.  
  375. -- The following functions were created by Smiley
  376.  
  377. function readstring(address, offset, length, endian)
  378.  
  379. local char_table = {}
  380. local string = ""
  381. for i=0,length do
  382. if readbyte(address, (offset + (0x1 * i))) ~= 0 then
  383. table.insert(char_table, string.char(readbyte(address, (offset + (0x1 * i)))))
  384. end
  385. end
  386. for k,v in pairs(char_table) do
  387. if endian == 1 then
  388. string = v .. string
  389. else
  390. string = string .. v
  391. end
  392. end
  393.  
  394. return string
  395. end
  396.  
  397. function readtagname(address)
  398.  
  399. local char_table = {}
  400. local i = 0
  401. local string = ""
  402. while readbyte(address, (0x1 * i)) ~= 0 do
  403. table.insert(char_table, string.char(readbyte(address, (0x1 * i))))
  404. i = i + 1
  405. end
  406. for k,v in pairs(char_table) do
  407. string = string .. v
  408. end
  409.  
  410. return string
  411. end
  412.  
  413. function endian(address, offset, length)
  414.  
  415. local data_table = {}
  416. local data = ""
  417. for i=0,length do
  418. local hex = string.format("%X", readbyte(address, offset + (0x1 * i)))
  419. if tonumber(hex, 16) < 16 then
  420. hex = 0 .. hex
  421. end
  422. table.insert(data_table, hex)
  423. end
  424. for k,v in pairs(data_table) do
  425. data = v .. data
  426. end
  427.  
  428. return data
  429. end
  430.  
  431. function todec(number)
  432.  
  433. return tonumber(number, 16)
  434. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement