Advertisement
HR_Shaft

Return Coordinates, Weapon & Vehicle for Phasor v2

Mar 30th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.81 KB | None | 0 0
  1. --[[ ###  Return Coordinates, Weapon & Vehicle  ###]]--
  2. --[[ ###        by H® Shaft for Phasor v2       ###]]--
  3. --[[ ###      consoletext overload by Nugget    ###]]--
  4.  
  5.  
  6. -- Scripting tool, not a game play script
  7.  
  8. -- Type: 'coord'  - returns your x,y,z coordinates in or out of a vehicle
  9. -- Type: 'hogname' - returns the tagname of the vehicle you are in - useful for CE maps. Note: Protected CE maps will return '<protected>'
  10. -- Type: 'weapon' - returns the tagname of the weapon you are holding - useful for CE maps. Note: Protected CE maps will return '<protected>'
  11.  
  12.  
  13. function GetRequiredVersion()
  14.     return 200
  15. end
  16.  
  17. function OnScriptLoad(process, game, persistent)
  18.  
  19. end
  20.  
  21. function OnServerChat(player, type, message)
  22.     local response = nil
  23.     if player then
  24.    
  25.         --will tell you the tagname of the vehicle you are in: primarily for CE
  26.         if string.lower(message) == "hogname" and isinvehicle(player) then
  27.             if isinvehicle(player) then
  28.                 local m_player = getplayer(player)
  29.                 local m_objectId = readdword(m_player + 0x34)
  30.                 local m_object = getobject(m_objectId)
  31.                 if m_object then
  32.                     local m_vehicleId = readdword(m_object + 0x11C)
  33.                     local m_vehicle = getobject(m_vehicleId)
  34.                     local vehname = gettaginfo(readdword(m_vehicle))
  35.                     sendconsoletext(player, "Vehicle tag name: " .. vehname, 15, 0)
  36.                     -- tag returned would be: vehicles/warthog/mp_warthog  then scripted as:  vehicles//warthog//mp_warthog
  37.                 end
  38.             end
  39.             return true
  40.         end
  41.        
  42.         -- returns your coordinates in or out of vehicle: x, y, z
  43.         if string.lower(message) == "coord" then
  44.             local m_playerObjId = getplayerobjectid(player)
  45.             if m_playerObjId then
  46.                 if isinvehicle(player) then
  47.                     local m_vehicleId = readdword(getobject(m_playerObjId) + 0x11C)
  48.                     m_objectId = m_vehicleId
  49.                 elseif m_playerObjId then
  50.                     m_objectId = m_playerObjId
  51.                 end
  52.                 if m_objectId then
  53.                     local x,y,z = getobjectcoords(m_objectId)          
  54.                     sendconsoletext(player, "X: " .. x .. " Y: " .. y .. " Z: " .. z, 15, 0)
  55.                 end
  56.             end
  57.             return true
  58.         end
  59.        
  60.         --will tell you the tagname of the primary weapon you are holding: primarily for CE
  61.         if string.lower(message) == "weapon" and not isinvehicle(player) then
  62.             local m_player = getplayer(player)
  63.             local m_objectId = readdword(m_player + 0x34)
  64.             local m_object = getobject(m_objectId)
  65.             if m_object then
  66.                 local m_weaponId = readdword(m_object + 0x118)
  67.                 if m_weaponId then
  68.                     local m_weapon = getobject(m_weaponId)         
  69.                     local weapname = gettaginfo(readdword(m_weapon))
  70.                     if m_weapon then
  71.                         sendconsoletext(player, "Weapon tag name: " .. weapname, 15, 0)
  72.                         -- tag returned would be: weapons/pistol/pistol  then scripted as:  weapons//pistol//pistol
  73.                     end    
  74.                 end
  75.             end
  76.             return true
  77.         end
  78.        
  79.     end
  80. end
  81.  
  82. -- Start sendconsoletext overloaded by Nugget
  83. console = {}
  84. console.__index = console
  85. consoletimer = registertimer(100, "ConsoleTimer")
  86. phasor_sendconsoletext = sendconsoletext
  87.  
  88. function sendconsoletext(player, message, time, order, align, height, func)
  89.     if player then
  90.         console[player] = console[player] or {}
  91.         local temp = {}
  92.         temp.player = player
  93.         temp.id = nextid(player, order)
  94.         temp.message = message or ""
  95.         temp.time = time or 0.7
  96.         temp.remain = temp.time
  97.         temp.align = align or "left"
  98.         temp.height = height or 0
  99.         if type(func) == "function" then
  100.             temp.func = func
  101.         elseif type(func) == "string" then
  102.             temp.func = _G[func]
  103.         end
  104.         console[player][temp.id] = temp
  105.         setmetatable(console[player][temp.id], console)
  106.         return console[player][temp.id]
  107.     end
  108. end
  109.  
  110. function nextid(player, order)
  111.     if not order then
  112.         local x = 0
  113.         for k,v in pairs(console[player]) do
  114.             if k > x + 1 then
  115.                 return x + 1
  116.             end
  117.            
  118.             x = x + 1
  119.         end
  120.         return x + 1
  121.     else
  122.         local original = order
  123.         while console[player][order] do
  124.             order = order + 0.001
  125.             if order == original + 0.999 then break end
  126.         end
  127.         return order
  128.     end
  129. end
  130.  
  131. function getmessage(player, order)
  132.     if console[player] then
  133.         if order then
  134.             return console[player][order]
  135.         end
  136.     end
  137. end
  138.  
  139. function getmessages(player)
  140.     return console[player]
  141. end
  142.  
  143. function getmessageblock(player, order)
  144.     local temp = {}
  145.     for k,v in opairs(console[player]) do
  146.         if k >= order and k < order + 1 then
  147.             table.insert(temp, console[player][k])
  148.         end
  149.     end
  150.     return temp
  151. end
  152.  
  153. function console:getmessage()
  154.     return self.message
  155. end
  156.  
  157. function console:append(message, reset)
  158.     if console[self.player] then
  159.         if console[self.player][self.id] then
  160.             if getplayer(self.player) then
  161.                 if reset then
  162.                     if reset == true then
  163.                         console[self.player][self.id].remain = console[self.player][self.id].time
  164.                     elseif tonumber(reset) then
  165.                         console[self.player][self.id].time = tonumber(reset)
  166.                         console[self.player][self.id].remain = tonumber(reset)
  167.                     end
  168.                 end
  169.                
  170.                 console[self.player][self.id].message = message or ""
  171.                 return true
  172.             end
  173.         end
  174.     end
  175. end
  176.  
  177. function console:shift(order)
  178.     local temp = console[self.player][self.id]
  179.     console[self.player][self.id] = console[self.player][order]
  180.     console[self.player][order] = temp
  181. end
  182.  
  183. function console:pause(time)
  184.     console[self.player][self.id].pausetime = time or 5
  185. end
  186.  
  187. function console:delete()
  188.     console[self.player][self.id] = nil
  189. end
  190.  
  191. function ConsoleTimer(id, count)
  192.     for i,_ in opairs(console) do
  193.         if tonumber(i) then
  194.             if getplayer(i) then
  195.                 for k,v in opairs(console[i]) do
  196.                     if console[i][k].pausetime then
  197.                         console[i][k].pausetime = console[i][k].pausetime - 0.1
  198.                         if console[i][k].pausetime <= 0 then
  199.                             console[i][k].pausetime = nil
  200.                         end
  201.                     else
  202.                         if console[i][k].func then
  203.                             if not console[i][k].func(i) then
  204.                                 console[i][k] = nil
  205.                             end
  206.                         end
  207.                         if console[i][k] then
  208.                             console[i][k].remain = console[i][k].remain - 0.1
  209.                             if console[i][k].remain <= 0 then
  210.                                 console[i][k] = nil
  211.                             end
  212.                         end
  213.                     end
  214.                 end
  215.                 if table.len(console[i]) > 0 then
  216.                     local paused = 0
  217.                     for k,v in pairs(console[i]) do
  218.                         if console[i][k].pausetime then
  219.                             paused = paused + 1
  220.                         end
  221.                     end
  222.                     if paused < table.len(console[i]) then
  223.                         local str = ""
  224.                         for i = 0,30 do
  225.                             str = str .. " \n"
  226.                         end
  227.                         phasor_sendconsoletext(i, str)
  228.                         for k,v in opairs(console[i]) do
  229.                             if not console[i][k].pausetime then
  230.                                 if console[i][k].align == "right" or console[i][k].align == "center" then
  231.                                     phasor_sendconsoletext(i, consolecenter(string.sub(console[i][k].message, 1, 78)))
  232.                                 else
  233.                                     phasor_sendconsoletext(i, string.sub(console[i][k].message, 1, 78))
  234.                                 end
  235.                             end
  236.                         end
  237.                     end
  238.                 end
  239.             else
  240.                 console[i] = nil
  241.             end
  242.         end
  243.     end
  244.     return true
  245. end
  246.  
  247. function consolecenter(text)
  248.     if text then
  249.         local len = string.len(text)
  250.         for i = len + 1, 78 do
  251.             text = " " .. text
  252.         end
  253.         return text
  254.     end
  255. end
  256.  
  257. function opairs(t)
  258.     local keys = {}
  259.     for k,v in pairs(t) do
  260.         table.insert(keys, k)
  261.     end    
  262.     table.sort(keys,
  263.     function(a,b)
  264.         if type(a) == "number" and type(b) == "number" then
  265.             return a < b
  266.         end
  267.         an = string.lower(tostring(a))
  268.         bn = string.lower(tostring(b))
  269.         if an ~= bn then
  270.             return an < bn
  271.         else
  272.             return tostring(a) < tostring(b)
  273.         end
  274.     end)
  275.     local count = 1
  276.     return function()
  277.         if table.unpack(keys) then
  278.             local key = keys[count]
  279.             local value = t[key]
  280.             count = count + 1
  281.             return key,value
  282.         end
  283.     end
  284. end
  285.  
  286. function table.len(t)
  287.     local count = 0
  288.     for k,v in pairs(t) do
  289.         count = count + 1
  290.     end
  291.     return count
  292. end
  293. -- Stop sendconsoletext overloaded
  294.  
  295. -- Created by H® Shaft thank you to Oxide, AelitePrime, Nugget & Wizard.
  296. -- Visit http://halorace.org/forum/index.php?topic=514.0 or
  297. -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement