Advertisement
rockbandcheeseman

Createobject Override

Dec 26th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.64 KB | None | 0 0
  1. -- Createobject override
  2.  
  3. phasor_createobject = createobject
  4. new_object_orientation = nil
  5.  
  6. spawns = {}
  7. objects = {}
  8.  
  9. registertimer(10, "ActiveObjectTimer")
  10.  
  11. function ActiveObjectTimer(id, count)
  12.  
  13.     for k,v in pairs(objects) do
  14.         if v.tagtype == "weap" then
  15.             -- Player holding weapon?
  16.             local carried
  17.             for i = 0,15 do
  18.                 if getplayer(i) then
  19.                     local m_player = getplayer(i)
  20.                     local objId = readdword(m_player, 0x34)
  21.                     local m_object = getobject(objId)
  22.                     if m_object then
  23.                         for x = 0,3 do
  24.                             local m_weapId = readdword(m_object, 0x2F8 + (x * 4))
  25.                             if m_weapId == k then
  26.                                 carried = true
  27.                                 break
  28.                             end
  29.                         end
  30.                        
  31.                         if carried then break end
  32.                     end
  33.                 end
  34.             end
  35.             -- Determine if it is active or not
  36.             if not carried then
  37.                 if objects[k].active then
  38.                     objects[k].active = false
  39.                     if objects[k].pickedup then
  40.                         local timerid = registertimer(spawns[objects[k].spawn].respawn_time * 1000, "DespawnTimer", k)
  41.                         objects[k].desptimer = timerid
  42.                     end
  43.                 end
  44.             else
  45.                 if not objects[k].active then
  46.                     objects[k].pickedup = true
  47.                     objects[k].active = true
  48.                     if objects[k].desptimer then
  49.                         removetimer(objects[k].desptimer)
  50.                     end
  51.                 end
  52.             end
  53.         elseif v.tagtype == "vehi" then
  54.             local active
  55.             for i = 0,15 do
  56.                 if gethash(i) then
  57.                     local m_player = getplayer(i)
  58.                     local objId = readdword(m_player, 0x34)
  59.                     local m_object = getobject(objId)
  60.                     if m_object then
  61.                         local m_vehicleId = readdword(m_object, 0x11C)
  62.                         if m_vehicleId == k then
  63.                             active = true
  64.                             break
  65.                         end
  66.                     end
  67.                 end
  68.             end
  69.            
  70.             if active then
  71.                 if not objects[k].active then
  72.                     objects[k].active = true
  73.                     removetimer(objects[k].desptimer)
  74.                     removetimer(spawns[objects[k].spawn].resptimer)
  75.                 end
  76.             else
  77.                 if objects[k].active then
  78.                     objects[k].active = false
  79.                     local desptimerid = registertimer(spawns[objects[k].spawn].respawn_time * 1000, "DespawnTimer", k)
  80.                     local resptimerid = registertimer(spawns[objects[k].spawn].respawn_time * 1000, "RespawnTimer", objects[k].spawn)
  81.                     objects[k].desptimer = desptimerid
  82.                     spawns[objects[k].spawn].resptimer = resptimerid
  83.                 end
  84.             end
  85.         end
  86.     end
  87.    
  88.     return true
  89. end
  90.  
  91. function createobject(mapId, parentId, respawn_time, respawn_bool, x, y, z, orientation)
  92.  
  93.     local objId
  94.    
  95.     -- Nil checks
  96.     x = x or 0
  97.     y = y or 0
  98.     z = z or 0
  99.     orientation = orientation or 0
  100.    
  101.     local tagname, tagtype = gettaginfo(mapId)
  102.     if respawn_time > 0 then
  103.         new_object_orientation = orientation
  104.         objId = phasor_createobject(mapId, parentId, 0, false, x, y, z)
  105.         if objId then
  106.             rotateobject(objId, orientation)
  107.             objects[objId] = {}
  108.             objects[objId].tagtype = tagtype
  109.             objects[objId].tagname = tagname
  110.             objects[objId].active = false
  111.             --local desptimerid = registertimer(respawn_time * 1000, "DespawnTimer", objId)
  112.             local resptimerid
  113.             if respawn_bool then
  114.                 resptimerid = registertimer(respawn_time * 1000, "RespawnTimer", #spawns + 1)
  115.             end
  116.             local temp = {}
  117.             temp.tagtype = tagtype
  118.             temp.tagname = tagname
  119.             temp.parentId = parentId
  120.             temp.respawn_time = respawn_time
  121.             temp.respawn_bool = true
  122.             temp.x = x
  123.             temp.y = y
  124.             temp.z = z
  125.             temp.orientation = orientation
  126.             temp.resptimer = resptimerid
  127.             table.insert(spawns, temp)
  128.             objects[objId].spawn = #spawns
  129.             --objects[objId].desptimer = desptimerid
  130.         else
  131.             hprintf("Invalid tag")
  132.         end
  133.     else
  134.         new_object_orientation = orientation
  135.         objId = phasor_createobject(mapId, parentId, 0, false, x, y, z)
  136.        
  137.         if not objId then
  138.             hprintf("Invalid mapId")
  139.         end
  140.     end
  141.  
  142.     return objId
  143. end
  144.  
  145. function respawnobject(key)
  146.  
  147.     if spawns[key] then
  148.         local exists
  149.         local m_object
  150.         for k,v in pairs(objects) do
  151.             if objects[k].spawn == key then
  152.                 m_object = getobject(k)
  153.                 if m_object then
  154.                     exists = k
  155.                     break
  156.                 end
  157.             end
  158.         end
  159.        
  160.         if not exists then
  161.             new_object_orientation = spawns[key].orientation
  162.             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)
  163.             rotateobject(objId, spawns[key].orientation)
  164.             --local timerid = registertimer(spawns[key].respawn_time * 1000, "DespawnTimer", objId)
  165.             objects[objId] = {}
  166.             objects[objId].tagtype = spawns[key].tagtype
  167.             objects[objId].tagname = spawns[key].tagname
  168.             objects[objId].active = false
  169.             objects[objId].spawn = key
  170.             --objects[objId].desptimer = timerid
  171.         else
  172.             if objects[exists].pickedup then
  173.                 new_object_orientation = spawns[key].orientation
  174.                 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)
  175.                 rotateobject(objId, spawns[key].orientation)
  176.                 --local timerid = registertimer(spawns[key].respawn_time * 1000, "DespawnTimer", objId)
  177.                 objects[objId] = {}
  178.                 objects[objId].tagtype = spawns[key].tagtype
  179.                 objects[objId].tagname = spawns[key].tagname
  180.                 objects[objId].active = false
  181.                 objects[objId].spawn = key
  182.                 --objects[objId].desptimer = timerid
  183.             else
  184.                 movobjcoords(exists, spawns[key].x, spawns[key].y, spawns[key].z)
  185.                 rotateobject(exists, spawns[key].orientation)
  186.                 writebit(m_object, 0x10, 2, 0)
  187.             end
  188.         end
  189.     end
  190. end
  191.  
  192. function rotateobject(objId, orientation)
  193.  
  194.     local m_object = getobject(objId)
  195.     if m_object then
  196.         local x_comp = -math.sin(orientation)
  197.         local y_comp = -math.cos(orientation)
  198.         writebit(m_object, 0x10, 2, 0)
  199.         writefloat(m_object, 0x74, x_comp)
  200.         writefloat(m_object, 0x78, y_comp)
  201.     end
  202. end
  203.  
  204. function getobjectorientation(objId)
  205.  
  206.     local m_object = getobject(objId)
  207.     local x_vector = readfloat(m_object, 0x74)
  208.     return -math.asin(x_vector)
  209. end
  210.  
  211. function RespawnTimer(id, count, spawn)
  212.  
  213.     respawnobject(spawn)
  214.     return 1
  215. end
  216.  
  217. function DespawnTimer(id, count, objId)
  218.  
  219.     if getobject(objId) then
  220.         destroyobject(objId)
  221.     end
  222.    
  223.     objects[objId] = nil
  224.    
  225.     return 0
  226. end
  227.  
  228. function GetRequiredVersion()
  229.  
  230.     return 10059
  231. end
  232.  
  233. function OnScriptLoad(process)
  234.  
  235.  
  236. end
  237.  
  238. function OnScriptUnload()
  239.  
  240.    
  241. end
  242.  
  243. function OnNewGame(map)
  244.  
  245.  
  246. end
  247.  
  248. function OnGameEnd(mode)
  249.  
  250.  
  251. end
  252.  
  253. function OnServerChat(player, chattype, message)
  254.  
  255.     return 1
  256. end
  257.  
  258. function OnServerCommand(player, command)
  259.  
  260.     return 1
  261. end
  262.  
  263. function OnTeamDecision(team)
  264.  
  265.     return team
  266. end
  267.  
  268. function OnPlayerJoin(player, team)
  269.  
  270.    
  271. end
  272.  
  273. function OnPlayerLeave(player, team)
  274.  
  275.  
  276. end
  277.  
  278. function OnPlayerKill(killer, victim, mode)
  279.  
  280.  
  281. end
  282.  
  283. function OnKillMultiplier(player, multiplier)
  284.  
  285.  
  286. end
  287.  
  288. function OnPlayerSpawn(player, objId)
  289.  
  290.     local mapId = gettagid("weap", "weapons\\sniper rifle\\sniper rifle")
  291.     createobject(mapId, 0, 10, true, 0, 0, 0.5, math.pi / 4)
  292. end
  293.  
  294. function OnPlayerSpawnEnd(player, objId)
  295.  
  296.    
  297. end
  298.  
  299. function OnTeamChange(relevant, player, cur_team, dest_team)
  300.  
  301.     return 1
  302. end
  303.  
  304. function OnObjectCreation(objId, player, tagname)
  305.  
  306.     if new_object_orientation then
  307.         rotateobject(objId, new_object_orientation)
  308.         new_object_orientation = nil
  309.     end
  310. end
  311.  
  312. function OnObjectInteraction(player, objId, tagtype, tagname)
  313.    
  314.     return 1
  315. end
  316.  
  317. function OnWeaponAssignment(player, objId, slot, tagname)
  318.    
  319.     return 0
  320. end
  321.  
  322. function OnWeaponReload(player, m_weapId)
  323.  
  324.     return 1
  325. end
  326.  
  327. function OnDamageLookup(receiver, causer, tagData, tagname)
  328.  
  329.  
  330. end
  331.  
  332. function OnVehicleEntry(relevant, player, m_vehicleId, tagname, seat)
  333.    
  334.     return 1
  335. end
  336.  
  337. function OnVehicleEject(player, forced)
  338.  
  339.     return 1
  340. end
  341.  
  342. function OnClientUpdate(player, objId)
  343.  
  344.  
  345. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement