Advertisement
rockbandcheeseman

GravityRifle

Jun 25th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.72 KB | None | 0 0
  1.  
  2. -- Gravity Rifle
  3.  
  4. gravity = {}
  5. vehicles = {}
  6. activetime = {}
  7.  
  8. function GetRequiredVersion()
  9.  
  10.     return 10059
  11. end
  12.  
  13. function OnScriptLoad(processId)
  14.  
  15.  
  16. end
  17.  
  18. --[[
  19. function OnScriptUnload()
  20.  
  21.  
  22. end
  23. --]]
  24.  
  25. --[[
  26. function OnNewGame(map)
  27.  
  28.  
  29. end
  30. --]]
  31.  
  32. --[[
  33. function OnGameEnd(stage)
  34.  
  35.  
  36. end
  37. --]]
  38.  
  39. --[[
  40. function OnServerChat(player, type, message)
  41.    
  42.     --return true
  43. end
  44. --]]
  45.  
  46. --[[
  47. function OnServerCommand(player, command)
  48.  
  49.     --return true
  50. end
  51. --]]
  52.  
  53. --[[
  54. function OnBanCheck(hash, ip)
  55.    
  56.     --return true
  57. end
  58. --]]
  59.  
  60. --[[
  61. function OnPlayerJoin(player)
  62.  
  63.  
  64. end
  65. --]]
  66.  
  67. function OnPlayerLeave(player)
  68.  
  69.     gravity[player] = nil
  70. end
  71.  
  72. function OnPlayerKill(killer, victim, mode)
  73.  
  74.     gravity[victim] = nil
  75. end
  76.  
  77. --[[
  78. function OnKillMultiplier(player, multiplier)
  79.  
  80.  
  81. end
  82. --]]
  83.  
  84. --[[
  85. function OnPlayerSpawn(player)
  86.  
  87.  
  88. end
  89. --]]
  90.  
  91. --[[
  92. function OnPlayerSpawnEnd(player)
  93.  
  94.  
  95. end
  96. --]]
  97.  
  98. function OnWeaponAssignment(player, objId, slot, weapId)
  99.    
  100.     return gettagid("weap", "weapons\\plasma rifle\\plasma rifle")
  101. end
  102.  
  103. --[[
  104. function OnObjectCreationAttempt(mapId, parentId, player)
  105.    
  106.     --return true
  107. end
  108. --]]
  109.  
  110. --[[
  111. function OnObjectCreation(objId)
  112.  
  113.  
  114. end
  115. --]]
  116.  
  117. --[[
  118. function OnObjectInteraction(player, objId, mapId)
  119.    
  120.    
  121. end
  122. --]]
  123.  
  124. --[[
  125. function OnTeamDecision(team)
  126.    
  127.     --return team
  128. end
  129. --]]
  130.  
  131. --[[
  132. function OnTeamChange(player, old_team, new_team, voluntary)
  133.    
  134.     --return true
  135. end
  136. --]]
  137.  
  138. function OnDamageLookup(receiver, causer, tagdata, mapId)
  139.    
  140.     local tagname = gettaginfo(mapId)
  141.    
  142.     if tagname == "weapons\\plasma rifle\\bolt" then
  143.         local player = objecttoplayer(causer)
  144.         if player then
  145.             local m_causer = getobject(causer)
  146.             local m_receiver = getobject(receiver)
  147.             if m_receiver and m_causer then
  148.                 local mapId = readdword(m_receiver)
  149.                 local tagname, tagtype = gettaginfo(mapId)
  150.                 if tagtype == "vehi" then
  151.                     if gravity[player] then
  152.                         gravity[player] = nil
  153.                         writebit(m_receiver, 0x10, 2, 0)
  154.                         local x_aim = readfloat(m_causer, 0x230)
  155.                         local y_aim = readfloat(m_causer, 0x234)
  156.                         local z_aim = readfloat(m_causer, 0x238)
  157.                         local vel = 1
  158.                         writefloat(m_receiver, 0x68, vel * math.sin(x_aim))
  159.                         writefloat(m_receiver, 0x6C, vel * math.sin(y_aim))
  160.                         writefloat(m_receiver, 0x70, vel * math.sin(z_aim))
  161.                         registertimer(10, "ActiveVehicle", {receiver, player})
  162.                     else
  163.                         local bool
  164.                        
  165.                         for p,r in pairs(gravity) do
  166.                             if r == receiver then
  167.                                 bool = true
  168.                             end
  169.                         end
  170.                        
  171.                         if not bool then
  172.                             gravity[player] = receiver
  173.                             vehicles[receiver] = player
  174.                             writebit(m_receiver, 0x10, 2, 0)
  175.                             local m_player = getplayer(player)
  176.                             local xy_aim = readfloat(m_player, 0x138)
  177.                             local z_aim = readfloat(m_player, 0x13C)
  178.                             local dist = 4
  179.                             local x = readfloat(m_causer, 0x5C)
  180.                             local y = readfloat(m_causer, 0x60)
  181.                             local z = readfloat(m_causer, 0x64)
  182.                             writefloat(m_receiver, 0x5C, x + dist * math.cos(xy_aim))
  183.                             writefloat(m_receiver, 0x60, y + dist * math.sin(xy_aim))
  184.                             writefloat(m_receiver, 0x64, z + dist * math.sin(z_aim) + 0.5)
  185.                             writefloat(m_receiver, 0x68, 0)
  186.                             writefloat(m_receiver, 0x6C, 0)
  187.                             writefloat(m_receiver, 0x70, 0)
  188.                             local angular_velocity_x = readfloat(m_receiver, 0x8C)
  189.                             local angular_velocity_y = readfloat(m_receiver, 0x90)
  190.                             local angular_velocity_z = readfloat(m_receiver, 0x94)
  191.                             writefloat(m_receiver, 0x8C, .2)
  192.                             writefloat(m_receiver, 0x90, .3)
  193.                             writefloat(m_receiver, 0x94, .05)
  194.                         end
  195.                     end
  196.                 end
  197.             end
  198.         end
  199.    
  200.     elseif tagname == "globals\\vehicle_collision" then
  201.    
  202.         if vehicles[causer] then
  203.             local m_player = getplayer(vehicles[causer])
  204.             if m_player then
  205.                 local objId = readdword(m_player, 0x34)
  206.                 local m_receiver = getobject(receiver)
  207.                 writedword(m_receiver, 0x438, objId)
  208.                 say("true")
  209.             end
  210.         end
  211.     end
  212. end
  213.  
  214. function ActiveVehicle(id, count, info)
  215.  
  216.     local vehiId = info[1]
  217.     local player = info[2]
  218.     local m_vehicle = getobject(vehiId)
  219.     if m_vehicle then
  220.         if vehicles[vehiId] == player then
  221.             if getplayer(player) then
  222.                 local vx = readfloat(m_vehicle, 0x68)
  223.                 local vy = readfloat(m_vehicle, 0x6C)
  224.                 local vz = readfloat(m_vehicle, 0x70)
  225.                 local velocity = math.sqrt(vx ^ 2 + vy ^ 2 + vz ^ 2)
  226.                 if velocity == 0 then
  227.                     activetime[vehiId] = activetime[vehiId] or 100 - 1
  228.                     if activetime[vehiId] <= 0 then
  229.                         vehicles[vehiId] = nil
  230.                         return false
  231.                     end
  232.                 end
  233.             end
  234.         else
  235.             return false
  236.         end
  237.     end
  238.    
  239.     return true
  240. end
  241.  
  242. function objecttoplayer(objId)
  243.  
  244.     for i = 0,15 do
  245.         local m_player = getplayer(i)
  246.         if m_player then
  247.             if readdword(m_player, 0x34) == objId then
  248.                 return i
  249.             end
  250.         end
  251.     end
  252. end
  253.  
  254. --[[
  255. function OnVehicleEntry(player, m_vehiId, seat, mapId, voluntary)
  256.    
  257.    
  258. end
  259. --]]
  260.  
  261. --[[
  262. function OnVehicleEject(player, voluntary)
  263.  
  264.     --return true
  265. end
  266. --]]
  267.  
  268. function OnClientUpdate(player)
  269.  
  270.     local vehiId = gravity[player]
  271.     if vehiId then
  272.         local m_player = getplayer(player)
  273.         local objId = readdword(m_player, 0x34)
  274.         local m_object = getobject(objId)
  275.         local m_vehicle = getobject(vehiId)
  276.         local x_aim = readfloat(m_object, 0x230)
  277.         local y_aim = readfloat(m_object, 0x234)
  278.         local z_aim = readfloat(m_object, 0x238)
  279.         local x = readfloat(m_object, 0x5C)
  280.         local y = readfloat(m_object, 0x60)
  281.         local z = readfloat(m_object, 0x64)
  282.         local dist = 4
  283.         writefloat(m_vehicle, 0x5C, x + dist * math.sin(x_aim))
  284.         writefloat(m_vehicle, 0x60, y + dist * math.sin(y_aim))
  285.         writefloat(m_vehicle, 0x64, z + dist * math.sin(z_aim) + 0.5)
  286.         writefloat(m_vehicle, 0x68, 0)
  287.         writefloat(m_vehicle, 0x6C, 0)
  288.         writefloat(m_vehicle, 0x70, 0.01285)
  289.     end
  290. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement