Advertisement
HR_Shaft

Item Spawner II, for SAPP

May 24th, 2016
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.55 KB | None | 0 0
  1. -- Item Spawner II by H® Shaft
  2.  
  3. -- re-write of Item spawner by 002, to include and accomodate rotation of the object, and fixed WeaponPickup function
  4. -- added x,y,z,r coordinate retrieval: type "coord" to return your x,y,z,rotation values, records in sapp log also
  5.  
  6. -- These coordinates are the first race nav locations for each map, but - I didn't have the rotation value, so I put 0
  7. -- to retrieve coordinates, start the server on the map you want, go to the location you want, turn AND "FACE" in the rotation you want
  8. -- then, once you are where you want to be and facing the direction you want, type "coord" (no quotes) and it will show you
  9. -- on screen, and log into the sapp.log file the map name followed by X, Y, Z, Rotation, then you can add/edit these entries
  10. -- example: open the log, find bloodgulch (or map you were on) and copy the X, Y, Z, R and paste below into the item for that map
  11. -- you can have more than one entry per map in the items table, and more than one class type, more than one weapon, etc, etc
  12. -- a full list of tag names, sorted by class is at the bottom except vehicles/bipeds which should not be used in this script (but can)
  13.  
  14. -- Configuration:
  15. -- Format: {"class","tagname",x,y,z,rotation,mapname,respawntime} separating each entry by commas, except for last entry.
  16. -- Example: {"weap","weapons\\plasma_cannon\\plasma_cannon",13.633, 13.249, -0.606, 0,"beavercreek",90.0},  
  17.  
  18. items = {
  19.     {"weap","weapons\\plasma_cannon\\plasma_cannon",13.633, 13.249, -0.606, 0,"beavercreek",90.0},
  20.     {"weap","weapons\\plasma_cannon\\plasma_cannon",59.785, -121.995, 0.268, 0,"bloodgulch",30.0},
  21.     {"weap","weapons\\plasma_cannon\\plasma_cannon",16.896, -0.245, -2.280, 0,"boardingaction",90.0},
  22.     {"weap","weapons\\plasma_cannon\\plasma_cannon",0.064, -0.037, -0.855, 0,"carousel",90.0},
  23.     {"weap","weapons\\plasma_cannon\\plasma_cannon",0.898, 10.113, 0.747, 0,"chillout",90.0},
  24.     {"weap","weapons\\plasma_cannon\\plasma_cannon",-0.646, -1.527, 8.201, 0,"damnation",90.0},
  25.     {"weap","weapons\\plasma_cannon\\plasma_cannon",-0.800, 40.452, -6.000, 0,"dangercanyon",90.0},
  26.     {"weap","weapons\\plasma_cannon\\plasma_cannon",1.499, -55.629, 1.645, 0,"deathisland",90.0},
  27.     {"weap","weapons\\plasma_cannon\\plasma_cannon",42.076, -71.727, -12.711, 0,"gephyrophobia",90.0},
  28.     {"weap","weapons\\plasma_cannon\\plasma_cannon",20.244, 12.534, -7.949, 0,"hangemhigh",90.0},
  29.     {"weap","weapons\\plasma_cannon\\plasma_cannon",-26.061, 32.583, 9.008, 0,"icefields",90.0},
  30.     {"weap","weapons\\plasma_cannon\\plasma_cannon",0.461, -158.781, 13.574, 0,"infinity",90.0},
  31.     {"weap","weapons\\plasma_cannon\\plasma_cannon",-0.904, -14.556, 0.168, 0,"longest",90.0},
  32.     {"weap","weapons\\plasma_cannon\\plasma_cannon",9.959, 4.606, -0.407, 0,"prisoner",90.0},
  33.     {"weap","weapons\\plasma_cannon\\plasma_cannon",-3.753, -20.851, 0.903, 0,"putput",90.0},
  34.     {"weap","weapons\\plasma_cannon\\plasma_cannon",-3.937, -8.287, -1.379, 0,"ratrace",90.0},
  35.     {"weap","weapons\\plasma_cannon\\plasma_cannon",1.800, 54.512, -2.801, 0,"sidewinder",90.0},
  36.     {"weap","weapons\\plasma_cannon\\plasma_cannon",17.330, -1.847, -21.034, 0,"timberland",90.0},
  37.     {"weap","weapons\\plasma_cannon\\plasma_cannon",5.555, -3.075, -2.749, 0,"wizard",90.0}
  38. }
  39. -- End of configuration
  40.  
  41. api_version = "1.9.0.0"
  42. items_to_use = {}
  43.  
  44. function OnScriptLoad()
  45.     register_callback(cb["EVENT_GAME_START"], "GameInit")
  46.     register_callback(cb["EVENT_GAME_END"], "GameEnded")
  47.     register_callback(cb["EVENT_WEAPON_PICKUP"], "WeaponPickup")
  48.     register_callback(cb["EVENT_TICK"], "RespawnObjects")
  49.     register_callback(cb["EVENT_CHAT"], "OnPlayerChat")
  50.     GameInit()
  51. end
  52.  
  53. function GameInit()
  54.     items_to_use = {}
  55.     map = get_var(1,"$map")
  56.     for k,v in pairs(items) do
  57.         if(v[7] == map) then -- values: 1 = class, 2 = tagname, 3 = x, 4 = y, 5 = z, 6 = r, 7 = mapname, 8 = respawn time
  58.             items_to_use[1 + #items_to_use] = v
  59.         end
  60.     end
  61.     execute_command("sv_map_reset")
  62. end
  63.  
  64. function GameEnded()
  65.     items_to_use = {}
  66. end
  67.  
  68. function RespawnObjects()
  69.     if(table.getn(items_to_use) == 0) then return true end
  70.     local time = os.clock()
  71.     for k,v in pairs(items_to_use) do
  72.         if(v.item ~= nil) then
  73.             -- Check if item has despawned. If it has, we can no longer keep track of it.
  74.             if(v.item.object_id ~= nil) then
  75.                 if(get_object_memory(v.item.object_id) == 0) then
  76.                     v.item.object_id = nil
  77.                 end
  78.             end
  79.             -- Check if respawn timer has been exceeded.
  80.             if(time > v.item.destruction_time) then
  81.                 if(v.item.object_id ~= nil) then destroy_object(v.item.object_id) end
  82.                 v.item = nil
  83.             end
  84.         end
  85.         if(v.item == nil) then
  86.             v.item = {}
  87.             v.item.destruction_time = 0
  88.         end
  89.         -- Respawn deleted items:
  90.         if(time > v.item.destruction_time) then
  91.             v.item = {}
  92.             v.item.object_id = spawn_object(v[1],v[2],v[3],v[4],v[5],v[6])  --values 1 = class, 2 = tagname, 3 = x, 4 = y, 5 = z, 6 = r, 7 = mapname, 8 = respawn time
  93.             local item_object = get_object_memory(v.item.object_id)
  94.             if (item_object ~= 0) then
  95.                 if v[1] == "vehi" then
  96.                     if (read_dword(item_object + 0x5AC) ~= 0xFFFFFFFF) then -- if in use
  97.                         v.item.destruction_time = time + 300  -- allow vehicle use for 5 mins
  98.                     else
  99.                         write_dword(item_object + 0x5B0, 0xFFFF)
  100.                         v.item.destruction_time = time + v[8]
  101.                     end
  102.                 else   
  103.                     write_dword(item_object + 0x204, 0xFFFF) -- note: if this is applied to a vehicle/hog it will not be driveable/stays stationary, could be a good hack
  104.                     v.item.destruction_time = time + v[8]
  105.                 end
  106.             end
  107.         end    
  108.     end
  109.     return true
  110. end
  111.  
  112. function WeaponPickup(PlayerIndex,WeaponSlot,WeaponType)
  113.     -- changed: previously it would sometimes delete a players weapon, (if weapon was a spawned item)
  114.     -- as it did not reliably complete the loop via sapps "WeaponSlot" and 002's loop method
  115.     if (WeaponType == "1") then
  116.         local player_dyn = get_dynamic_player(PlayerIndex)
  117.         -- Iterate through all player weapons one-by-one, if a match is found, remove/nil the item from being tracked
  118.         for i=0,3 do
  119.             local object_id = read_dword(player_dyn + 0x2F8 + i * 0x4)
  120.             for k,v in pairs(items_to_use) do
  121.                 if(v.item ~= nil) then
  122.                     if(v.item.object_id == object_id) then
  123.                         v.item.object_id = nil
  124.                     end
  125.                 end
  126.             end        
  127.         end
  128.     end
  129. end
  130.  
  131. function OnPlayerChat(PlayerIndex, Message)
  132.     local response = nil
  133.     local name = get_var(PlayerIndex,"$name")
  134.     local Message = string.lower(Message)
  135.    
  136.     -- | retrieve your coordinates x,y,z and rotation (yaw)
  137.     if (Message == "coord") then
  138.         response = false
  139.         local player_object = get_dynamic_player(PlayerIndex)
  140.         local player_static = get_player(PlayerIndex)
  141.         local x,y,z = read_vector3d(player_object + 0x5C)
  142.         x = math.round(x, 2)
  143.         y = math.round(y, 2)
  144.         z = math.round(z, 2)
  145.         local rotation = read_float(player_static + 0x138)
  146.         rotation = math.round(rotation, 2)
  147.         local map_name = get_var(0,"$map")
  148.         local data = string.format("%s XYZR: %s, %s, %s, %s", tostring(map_name),tostring(x),tostring(y),tostring(z),tostring(rotation))
  149.         execute_command("log_note \""..data.."\"")
  150.         say(PlayerIndex, "Location written to logs under map: " .. map_name)   
  151.         say(PlayerIndex, "X: " .. x .. " Y: " .. y .. " Z: " .. z .. " R: " .. rotation)
  152.     end
  153.    
  154.     return response
  155. end
  156.  
  157. function math.round(num, idp)
  158.   return tonumber(string.format("%." .. (idp or 0) .. "f", num))
  159. end
  160.  
  161. function OnScriptUnload() end
  162.  
  163. function OnError(Message)
  164.     print(debug.traceback())
  165. end
  166.    
  167. -- Created by H® Shaft, original by 002
  168. -- Visit http://halorace.org/forum/index.php
  169.  
  170. -- tag name list by "class"
  171. -- Note: You must use two backslashes for each backslash in order for Lua to interpret it correctly.
  172.  
  173. -- "eqip" = equipment:
  174.  
  175. -- "powerups\\active camouflage"
  176. -- "powerups\\health pack"
  177. -- "powerups\\over shield"
  178. -- "weapons\\frag grenade\\frag grenade"
  179. -- "weapons\\plasma grenade\\plasma grenade"
  180.  
  181. -- "weap" = weapons:
  182.  
  183. -- "weapons\\assault rifle\\assault rifle"
  184. -- "weapons\\ball\\ball"
  185. -- "weapons\\flag\\flag"
  186. -- "weapons\\flamethrower\\flamethrower"
  187. -- "weapons\\gravity rifle\\gravity rifle"
  188. -- "weapons\\needler\\mp_needler"
  189. -- "weapons\\needler\\needler"
  190. -- "weapons\\pistol\\pistol"
  191. -- "weapons\\plasma pistol\\plasma pistol"
  192. -- "weapons\\plasma rifle\\plasma rifle"
  193. -- "weapons\\plasma_cannon\\plasma_cannon"
  194. -- "weapons\\rocket launcher\\rocket launcher"
  195. -- "weapons\\shotgun\\shotgun"
  196. -- "weapons\\sniper rifle\\sniper rifle"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement