Advertisement
HR_Shaft

Random Weapons for Revolution for Phasor v2+

Jan 17th, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.64 KB | None | 0 0
  1. --[[ ###  Random Weapons for Revolution ###]]--
  2. --[[ ###    by H® Shaft for Phasor v2   ###]]--
  3.  
  4. -- gametype MUST have weapons set to generic
  5. -- specifically for revolution maps by Nex *ONLY* find various maps in thread: http://opencarnage.net/index.php?/topic/2239-halo-revolution/
  6.  
  7. team_play = false
  8. game_started = false
  9. weapons = {}
  10. mybattery = {}
  11. needler_clip = 40
  12. shotgun_clip = 12
  13. assault_clip = 60
  14. nlaunch_clip = 5
  15. pistol_clip = 12
  16. rocket_clip = 2
  17. sniper_clip = 4
  18. carbine_clip = 18
  19. rocket_ammo = 4
  20.  
  21. function GetRequiredVersion()
  22.     return 200
  23. end
  24.  
  25. function OnScriptLoad(process, game, persistent)
  26.     if game == true or game == "PC" then
  27.         GAME = "PC"
  28.         gametype_base = 0x671340
  29.         map_name = readstring(0x698F21)
  30.     else
  31.         GAME = "CE"
  32.         gametype_base = 0x5F5498
  33.         map_name = readstring(0x61D151)
  34.     end
  35.     for i=0,15 do
  36.         if getplayer(i) then
  37.             mybattery[i] = 0
  38.             weapons[i] = {}
  39.         end
  40.     end    
  41.     gametype = readbyte(gametype_base + 0x30)
  42.     team_play = getteamplay()  
  43. end
  44.  
  45. function OnNewGame(map)
  46.     if GAME == "PC" then
  47.         gametype_base = 0x671340
  48.         map_name = readstring(0x698F21)
  49.     elseif GAME == "CE" then
  50.         gametype_base = 0x5F5498
  51.         map_name = readstring(0x61D151)
  52.     end
  53.     for i=0,15 do
  54.         if getplayer(i) then
  55.             mybattery[i] = 0
  56.             weapons[i] = {}
  57.         end
  58.     end
  59.     game_started = true
  60.     gametype = readbyte(gametype_base + 0x30)
  61.     team_play = getteamplay()
  62. end
  63.  
  64. function getteamplay()
  65.     if readbyte(gametype_base + 0x34) == 1 then
  66.         return true
  67.     else
  68.         return false
  69.     end
  70. end
  71.  
  72. function OnPlayerJoin(player)
  73.     if getplayer(player) then
  74.         mybattery[player] = 0
  75.         weapons[player] = nil
  76.         welcome = registertimer(9000, "Welcome", player)
  77.     end
  78. end
  79.  
  80. function ApplyHP(id, count, player)
  81.     if count == 1 then
  82.         if player and game_started then
  83.             local name = getname(player)   
  84.             local m_playerObjId = getplayerobjectid(player)
  85.             if m_playerObjId ~= nil then
  86.                 local m_object = getobject(m_playerObjId)
  87.                 local obj_health = readfloat(m_object + 0xE0)
  88.                 if obj_health < 1 then
  89.                     writefloat(m_object + 0xE0, 1)
  90.                     sendconsoletext(player, "Bonus: Your health has been restored.", 5, 0)
  91.                 end
  92.             end
  93.         end
  94.     end
  95.     return false
  96. end
  97.  
  98. function Welcome(id, count, player)
  99.     if count == 1 then
  100.         if getplayer(player) then
  101.             sendconsoletext(player, "Welcome to Random Weapons for Revolution!", 10, 0)
  102.             sendconsoletext(player, "Each time you spawn, you will be given a random weapon.", 10, 0)
  103.         end
  104.     end
  105.     return false   
  106. end
  107.  
  108. function OnPlayerKill(killer, victim, mode)
  109.     local response = nil
  110.     if getplayer(victim) then
  111.         weapons[victim] = nil
  112.         mybattery[victim] = 0
  113.         if mode == 0 then          
  114.             response = false
  115.         else
  116.             response = true
  117.         end    
  118.     end
  119.     return response
  120. end
  121.  
  122. function OnPlayerLeave(player)
  123.     if getplayer(player) then
  124.         weapons[player] = nil
  125.         mybattery[player] = nil
  126.     end
  127. end
  128.  
  129. function OnTeamChange(player, old_team, new_team, relevant)
  130.     if getplayer(player) then
  131.         weapons[player] = nil
  132.         mybattery[player] = 1
  133.     end
  134.     return nil
  135. end
  136.  
  137. function OnPlayerSpawnEnd(player, m_objectId)
  138.     if getplayer(player) then
  139.         weapons[player] = nil
  140.         mybattery[player] = 0
  141.         ChangeFFAColor(player)
  142.         local m_objectId = getplayerobjectid(player)       
  143.         if m_objectId then
  144.             gameweap = registertimer(0, "AssignGameWeapons", player)
  145.         end
  146.     end
  147. end
  148.  
  149. function ChangeFFAColor(player)
  150.     if getplayer(player) then
  151.         local m_objectId = getplayerobjectid(player)
  152.         if m_objectId then
  153.             local m_object = getobject(m_objectId)
  154.             if m_object then
  155.                 local m_player = getplayer(player)
  156.                 local color = getrandomnumber(1, 18)
  157.                 writeword(m_player + 0x60, color)
  158.             end
  159.         end
  160.     end
  161. end
  162.  
  163. function AssignGameWeapons(id, count, player)
  164.     if getplayer(player) and game_started then
  165.         local m_objectId = getplayerobjectid(player)
  166.         local m_object = getobject(m_objectId)
  167.         local clip = 0
  168.         local ammo = 9999
  169.         local battery = 0
  170.        
  171.         if m_objectId then
  172.             for i = 0,3 do
  173.                 local weapID = readdword(getobject(m_objectId), 0x2F8 + i*4)
  174.                 if weapID ~= 0xFFFFFFFF then
  175.                     destroyobject(weapID)
  176.                 end
  177.             end
  178.        
  179.             local randomweap = getrandomnumber(1, 11)
  180.             local randomclip = getrandomnumber(1, 20)      
  181.        
  182.             if randomweap == 1 then
  183.                 weapons[player] = "revolution\\weapons\\plasma pistol\\plasma pistol" -- Plasma Pistol - 1
  184.                 sendconsoletext(player, "Plasma Pistol", 5, 0)
  185.                
  186.             elseif randomweap == 2 then
  187.                 if randomclip > 19 then
  188.                     clip = 9999
  189.                     sendconsoletext(player, "Bottomless Clip: No Reload!", 5, 0)
  190.                 else   
  191.                     clip = needler_clip
  192.                 end        
  193.                 weapons[player] = "revolution\\weapons\\needler\\needler" -- Needler - 2
  194.                 sendconsoletext(player, "Needler", 5, 0)
  195.  
  196.             elseif randomweap == 3 then
  197.                 if randomclip > 19 then
  198.                     clip = 9999
  199.                     sendconsoletext(player, "Bottomless Clip: No Reload!", 5, 0)
  200.                 else   
  201.                     clip = shotgun_clip
  202.                 end
  203.                 weapons[player] = "revolution\\weapons\\shotgun\\revolution shotgun" -- Shotgun - 3
  204.                 sendconsoletext(player, "Shotgun", 5, 0)
  205.                
  206.             elseif randomweap == 4 then
  207.                 weapons[player] = "revolution\\weapons\\plasma rifle\\plasma rifle" -- Plasma Rifle - 4
  208.                 sendconsoletext(player, "Plasma Rifle", 5, 0)
  209.                
  210.             elseif randomweap == 5 then
  211.                 if randomclip > 19 then
  212.                     clip = 9999
  213.                     sendconsoletext(player, "Bottomless Clip: No Reload!", 5, 0)
  214.                 else   
  215.                     clip = assault_clip
  216.                 end        
  217.                 weapons[player] = "revolution\\weapons\\assault rifle\\revolution assault rifle" -- Assault Rifle - 5
  218.                 sendconsoletext(player, "Assault Rifle", 5, 0)
  219.                
  220.             elseif randomweap == 6 then
  221.                 if randomclip > 19 then
  222.                     clip = 9999
  223.                     sendconsoletext(player, "Bottomless Clip: No Reload!", 5, 0)
  224.                 else   
  225.                     clip = nlaunch_clip
  226.                 end
  227.                 weapons[player] = "revolution\\weapons\\grenade launcher\\nade_launcher" -- Nade Launcher - 6
  228.                 sendconsoletext(player, "Nade Launcher", 5, 0)
  229.                
  230.             elseif randomweap == 7 then
  231.                 if randomclip > 19 then
  232.                     clip = 9999
  233.                     sendconsoletext(player, "Bottomless Clip: No Reload!", 5, 0)
  234.                 else   
  235.                     clip = pistol_clip
  236.                 end
  237.                 weapons[player] = "revolution\\weapons\\pistol\\rev pistol" -- Pistol - 7
  238.                 sendconsoletext(player, "Pistol", 5, 0)
  239.                
  240.             elseif randomweap == 8 then
  241.                 if randomclip > 19 then
  242.                     clip = 9999
  243.                     sendconsoletext(player, "Bottomless Clip: No Reload!", 5, 0)
  244.                 else   
  245.                     clip = rocket_clip
  246.                 end
  247.                 weapons[player] = "revolution\\weapons\\rocket launcher\\rocket launcher" -- Rocket Launcher - 8
  248.                 sendconsoletext(player, "Rocket Launcher", 5, 0)
  249.                
  250.             elseif randomweap == 9 then
  251.                 if randomclip > 19 then
  252.                     clip = 9999
  253.                     sendconsoletext(player, "Bottomless Clip: No Reload!", 5, 0)
  254.                 else   
  255.                     clip = sniper_clip
  256.                 end
  257.                 weapons[player] = "revolution\\weapons\\sniper\\revolution sniper" -- Sniper Rifle - 9
  258.                 sendconsoletext(player, "Sniper Rifle", 5, 0)
  259.                
  260.             elseif randomweap == 10 then
  261.                 weapons[player] = "revolution\\weapons\\plasma cannon\\plasma_cannon" -- Plasma Cannon - 10
  262.                 sendconsoletext(player, "Plasma Cannon", 5, 0)
  263.                
  264.             elseif randomweap == 11 then
  265.                 if randomclip > 19 then
  266.                     clip = 9999
  267.                     sendconsoletext(player, "Bottomless Clip: No Reload!", 5, 0)
  268.                 else   
  269.                     clip = bruteshot_clip
  270.                 end
  271.                 weapons[player] = "revolution\\weapons\\carbine\\carbine" -- Carbine -11
  272.                 sendconsoletext(player, "Carbine", 5, 0)               
  273.             end
  274.            
  275.             local m_weaponId = createobject(gettagid("weap", weapons[player]), 0, 10, false, 0, 0, 0)
  276.             assignweapon(player, m_weaponId)
  277.             local m_weapon = getobject(m_weaponId)
  278.            
  279.             if randomweap == 1 or randomweap == 4 or randomweap == 10 then
  280.                 if m_weapon then
  281.                     writefloat(m_weapon + 0x240, battery)
  282.                     updateammo(m_weaponId)
  283.                     infbattery = registertimer(1000, "InfBattery", {m_weapon, player})
  284.                     mybattery[player] = 1
  285.                 end            
  286.             elseif randomclip <= 19 then
  287.                 if m_weapon then
  288.                     if randomweap == 8 then ammo = rocket_ammo clip = rocket_clip end -- rocket launcher
  289.                     writeword(m_weapon + 0x2B6, ammo)
  290.                     if randomweap ~= 11 then
  291.                         writeword(m_weapon + 0x2B8, clip) -- carbine has no clip?
  292.                     end
  293.                     updateammo(m_weaponId)
  294.                 end
  295.             else       
  296.                 if m_weapon then
  297.                     if randomweap == 8 then ammo = rocket_ammo clip = rocket_clip end
  298.                     writeword(m_weapon + 0x2B6, ammo)
  299.                     writeword(m_weapon + 0x2B8, clip)
  300.                     updateammo(m_weaponId)
  301.                 end
  302.             end
  303.             local random_nade = getrandomnumber(1, 7)
  304.             if m_object then
  305.                 writebyte(m_object, 0x31E, 0)
  306.                 writebyte(m_object, 0x31F, 0)
  307.                 if random_nade == 1 then
  308.                     writebyte(m_object, 0x31E, 2)
  309.                     writebyte(m_object, 0x31F, 2)
  310.                     sendconsoletext(player, "Grenades: 2 of each.", 5, 0)
  311.                 elseif random_nade == 2 then
  312.                     writebyte(m_object, 0x31E, 1)
  313.                     writebyte(m_object, 0x31F, 1)
  314.                     sendconsoletext(player, "Grenades: 1 of each.", 5, 0)
  315.                 elseif random_nade == 3 then   
  316.                     writebyte(m_object, 0x31E, 1)
  317.                     writebyte(m_object, 0x31F, 0)
  318.                     sendconsoletext(player, "Grenades: 1 frag.", 5, 0)
  319.                 elseif random_nade == 4 then
  320.                     writebyte(m_object, 0x31E, 0)
  321.                     writebyte(m_object, 0x31F, 1)
  322.                     sendconsoletext(player, "Grenades: 1 Plasma.", 5, 0)
  323.                 elseif random_nade == 5 then
  324.                     writebyte(m_object, 0x31E, 2)
  325.                     writebyte(m_object, 0x31F, 0)
  326.                     sendconsoletext(player, "Grenades: 2 Frags.", 5, 0)
  327.                 elseif random_nade == 6 then
  328.                     writebyte(m_object, 0x31E, 0)
  329.                     writebyte(m_object, 0x31F, 2)
  330.                     sendconsoletext(player, "Grenades: 2 Plasma.", 5, 0)
  331.                 elseif random_nade == 7 then
  332.                     writebyte(m_object, 0x31E, 0)
  333.                     writebyte(m_object, 0x31F, 0)
  334.                 else
  335.                     writebyte(m_object, 0x31E, 0)
  336.                     writebyte(m_object, 0x31F, 0)              
  337.                 end    
  338.             end
  339.             local random_camo = getrandomnumber(1, 30)
  340.             local id = resolveplayer(player)
  341.             if random_camo > 29 then
  342.                 svcmd("sv_invis " .. id)
  343.                 sendconsoletext(player, "You are Invisible!", 5, 0)
  344.             end
  345.             local random_os = getrandomnumber(1, 30)
  346.             if random_os > 29 then
  347.                 if readfloat(m_object + 0xE4) <= 1 then
  348.                     local x,y,z = getobjectcoords(m_objectId)
  349.                     local os = createobject(gettagid("eqip", "powerups\\over shield"), 0, 0, false, x, y, z+0.5)
  350.                     if os ~= nil then writefloat(getobject(os) + 0x70, -2) end
  351.                 else
  352.                     writefloat(m_object + 0xE4, 3)
  353.                 end
  354.                 sendconsoletext(player, "You have an Overshield!", 5, 0)
  355.             end            
  356.             if gametype ~= 5 then
  357.                 local random_speed = getrandomnumber(1, 30)
  358.                 if random_speed >= 29 then
  359.                     setspeed(player, 1.5)
  360.                     sendconsoletext(player, "150% Speed!", 5, 0)
  361.                 elseif random_speed >= 1 and random_speed < 3 then 
  362.                     setspeed(player, 1.25)
  363.                     sendconsoletext(player, "125% Speed!", 5, 0)               
  364.                 end
  365.             end
  366.         end
  367.     end
  368.     return false
  369. end
  370.  
  371. function OnWeaponReload(player, weapon)
  372.     local reload = nil
  373.         if getplayer(player) then
  374.             local m_player = getplayer(player)
  375.             local m_objectId = readdword(m_player + 0x34)
  376.             local m_object = getobject(m_objectId)
  377.             if m_object then
  378.                 local m_weaponId = readdword(m_object + 0x118)
  379.                 if m_weaponId then
  380.                     local m_weapon = getobject(m_weaponId)         
  381.                     if m_weapon then
  382.                         local weapname = gettaginfo(readdword(m_weapon))
  383.                         if weapname == "revolution\\weapons\\needler\\needler" then
  384.                             writeword(getobject(weapon) + 0x2B8, needler_clip)
  385.                             updateammo(weapon)
  386.                             reload = false
  387.                         elseif weapname == "revolution\\weapons\\grenade launcher\\nade_launcher" then
  388.                             writeword(getobject(weapon) + 0x2B8, nlaunch_clip)
  389.                             updateammo(weapon)
  390.                             reload = false 
  391.                         else
  392.                             reload = true
  393.                         end
  394.                     end    
  395.                 end
  396.             end
  397.         end
  398.     return reload
  399. end
  400.  
  401. function InfBattery(id, count, arg)
  402.     local m_weapon = arg[1]
  403.     local player = arg[2]
  404.     if m_weapon and game_started then
  405.         if readfloat(m_weapon + 0x240) == 1 and mybattery[player] == 1 then
  406.             destroyplayerweaps(player)
  407.             replaceplasmaweap = registertimer(0, "ReplacePlasmaWeap", {player, m_weapon})
  408.             mybattery[player] = 0
  409.         end
  410.     end
  411.     return true
  412. end
  413.  
  414. function ReplacePlasmaWeap(id, count, arg)
  415.     local player = arg[1]
  416.     local m_weapon = arg[2]
  417.     if count == 1 then
  418.         if player and game_started then
  419.             local m_weaponId = createobject(gettagid("weap", weapons[player]), 0, 10, false, 0, 0, 0)
  420.             assignweapon(player, m_weaponId)
  421.             privatesay(player, "Battery recharged.")
  422.         end
  423.         mybattery[player] = 0
  424.     end
  425.     return false
  426. end
  427.  
  428. function getweaponobjectid(player, slot)
  429.     local m_objectId = getplayerobjectid(player)
  430.     if m_objectId then return readdword(getobject(m_objectId) + 0x2F8 + slot*4) end
  431. end
  432.  
  433. function destroyplayerweaps(player)
  434.     for i=0,3 do
  435.         local weap_id = getweaponobjectid(player, i)
  436.         if weap_id ~= 0xFFFFFFFF then destroyobject(weap_id) end
  437.     end
  438. end
  439.  
  440. function OnObjectCreationAttempt(mapId, parentId, player)
  441.     local response = nil
  442.     local name, type = gettaginfo(mapId)
  443.     if game_started then
  444.         -- block
  445.         if mapId == gettagid("eqip", "revolution\\weapons\\frag grenade\\frag grenade") or -- frags
  446.             mapId == gettagid("eqip", "revolution\\weapons\\plasma grenade\\plasma grenade") then -- plasma
  447.             response = false
  448.         end        
  449.     elseif not game_started then
  450.         -- allow
  451.         if mapId == gettagid("bipd", "revolution\\biped\\cyborg") then -- m biped          
  452.             response = true
  453.         end
  454.         -- block
  455.         if mapId == gettagid("eqip", "revolution\\weapons\\frag grenade\\frag grenade") or -- frags
  456.             mapId == gettagid("eqip", "revolution\\weapons\\plasma grenade\\plasma grenade") then -- plasma
  457.             response = false
  458.         end        
  459.     else
  460.         response = false
  461.     end
  462.     return response    
  463. end
  464.  
  465. function OnDamageLookup(receiving, causing, tagid)
  466.     -- looks up and sets damage variables
  467.     if receiving and causing and receiving ~= causing then
  468.         local tagname, tagtype = gettaginfo(tagid)
  469.         local melee = string.find(tagname, "melee")
  470.         local ppistol = string.find(tagname, "cmt\\weapons\\covenant\\plasma_pistol\\bolt\\bolt")
  471.         local needler1 = string.find(tagname, "revolution\\weapons\\needler\\impact damage")
  472.         local needler2 = string.find(tagname, "weapons\\needler\\shock wave")
  473.         local plasrifle = string.find(tagname, "cmt\\weapons\\covenant\\plasma_rifle\\bolt")
  474.         -- increase damage of melee to instant kill, increase plasma pistol, needler and plasma rifle to balance game play
  475.         if c_player and r_player then
  476.             if melee then odl_multiplier(9999) end
  477.             if ppistol then odl_multiplier(1.85) end
  478.             if needler1 or needler2 then odl_multiplier(1.75) end
  479.             if plasrifle then odl_multiplier(1.35) end
  480.         end
  481.     end
  482.     return nil
  483. end
  484.  
  485. function OnObjectInteraction(player, objId, mapId)
  486.     local Pass = nil
  487.     local name, type = gettaginfo(mapId)
  488.     if type == "weap" then
  489.         if gametype == 1 or gametype == 3 then
  490.             if name == "revolution\\weapons\\flag\\flag" or name == "revolution\\weapons\\ball\\ball" then
  491.                 Pass = true
  492.             elseif weapons[player] ~= nil then
  493.                 if name ~= weapons[player] then
  494.                     Pass = false
  495.                 end
  496.             end
  497.         else
  498.             if weapons[player] ~= nil then
  499.                 if name ~= weapons[player] then
  500.                     Pass = false
  501.                 end
  502.             end
  503.         end
  504.     elseif type == "eqip" then
  505.         if name == "revolution\\weapons\\frag grenade\\frag grenade" or name == "revolution\\weapons\\plasma grenade\\plasma grenade" then
  506.             Pass = false
  507.         end
  508.     end
  509.     return Pass
  510. end
  511.  
  512. function OnGameEnd(stage)
  513.     if stage == 1 then
  514.         game_started = false   
  515.         if gameweap then
  516.             gameweap = nil
  517.         end
  518.         if infbattery then
  519.             infbattery = nil
  520.         end
  521.         if replaceplasmaweap then
  522.             replaceplasmaweap = nil
  523.         end    
  524.     elseif stage == 3 then
  525.         for i = 0, 15 do
  526.             if getplayer(i) then
  527.                 privatesay(i, "Thank you for playing Random Weapons for Revolution!")
  528.                 privatesay(i, "by H\174 Shaft")
  529.             end
  530.         end    
  531.     end    
  532. end
  533.  
  534.  
  535. -- Start sendconsoletext overloaded by Nugget
  536. console = {}
  537. console.__index = console
  538. consoletimer = registertimer(100, "ConsoleTimer")
  539. phasor_sendconsoletext = sendconsoletext
  540.  
  541. function sendconsoletext(player, message, time, order, align, height, func)
  542.     if player then
  543.         console[player] = console[player] or {}
  544.         local temp = {}
  545.         temp.player = player
  546.         temp.id = nextid(player, order)
  547.         temp.message = message or ""
  548.         temp.time = time or 0.7
  549.         temp.remain = temp.time
  550.         temp.align = align or "left"
  551.         temp.height = height or 0
  552.         if type(func) == "function" then
  553.             temp.func = func
  554.         elseif type(func) == "string" then
  555.             temp.func = _G[func]
  556.         end
  557.         console[player][temp.id] = temp
  558.         setmetatable(console[player][temp.id], console)
  559.         return console[player][temp.id]
  560.     end
  561. end
  562.  
  563. function nextid(player, order)
  564.     if not order then
  565.         local x = 0
  566.         for k,v in pairs(console[player]) do
  567.             if k > x + 1 then
  568.                 return x + 1
  569.             end
  570.             x = x + 1
  571.         end
  572.         return x + 1
  573.     else
  574.         local original = order
  575.         while console[player][order] do
  576.             order = order + 0.001
  577.             if order == original + 0.999 then break end
  578.         end
  579.         return order
  580.     end
  581. end
  582.  
  583. function getmessage(player, order)
  584.     if console[player] then
  585.         if order then
  586.             return console[player][order]
  587.         end
  588.     end
  589. end
  590.  
  591. function getmessages(player)
  592.     return console[player]
  593. end
  594.  
  595. function getmessageblock(player, order)
  596.     local temp = {}
  597.     for k,v in opairs(console[player]) do
  598.         if k >= order and k < order + 1 then
  599.             table.insert(temp, console[player][k])
  600.         end
  601.     end
  602.     return temp
  603. end
  604.  
  605. function console:getmessage()
  606.     return self.message
  607. end
  608.  
  609. function console:append(message, reset)
  610.     if console[self.player] then
  611.         if console[self.player][self.id] then
  612.             if getplayer(self.player) then
  613.                 if reset then
  614.                     if reset == true then
  615.                         console[self.player][self.id].remain = console[self.player][self.id].time
  616.                     elseif tonumber(reset) then
  617.                         console[self.player][self.id].time = tonumber(reset)
  618.                         console[self.player][self.id].remain = tonumber(reset)
  619.                     end
  620.                 end
  621.                 console[self.player][self.id].message = message or ""
  622.                 return true
  623.             end
  624.         end
  625.     end
  626. end
  627.  
  628. function console:shift(order)
  629.     local temp = console[self.player][self.id]
  630.     console[self.player][self.id] = console[self.player][order]
  631.     console[self.player][order] = temp
  632. end
  633.  
  634. function console:pause(time)
  635.     console[self.player][self.id].pausetime = time or 5
  636. end
  637.  
  638. function console:delete()
  639.     console[self.player][self.id] = nil
  640. end
  641.  
  642. function ConsoleTimer(id, count)
  643.     for i,_ in opairs(console) do
  644.         if tonumber(i) then
  645.             if getplayer(i) then
  646.                 for k,v in opairs(console[i]) do
  647.                     if console[i][k].pausetime then
  648.                         console[i][k].pausetime = console[i][k].pausetime - 0.1
  649.                         if console[i][k].pausetime <= 0 then
  650.                             console[i][k].pausetime = nil
  651.                         end
  652.                     else
  653.                         if console[i][k].func then
  654.                             if not console[i][k].func(i) then
  655.                                 console[i][k] = nil
  656.                             end
  657.                         end
  658.                         if console[i][k] then
  659.                             console[i][k].remain = console[i][k].remain - 0.1
  660.                             if console[i][k].remain <= 0 then
  661.                                 console[i][k] = nil
  662.                             end
  663.                         end
  664.                     end
  665.                 end
  666.                 if table.len(console[i]) > 0 then
  667.                     local paused = 0
  668.                     for k,v in pairs(console[i]) do
  669.                         if console[i][k].pausetime then
  670.                             paused = paused + 1
  671.                         end
  672.                     end
  673.                     if paused < table.len(console[i]) then
  674.                         local str = ""
  675.                         for i = 0,30 do
  676.                             str = str .. " \n"
  677.                         end
  678.                         phasor_sendconsoletext(i, str)
  679.                         for k,v in opairs(console[i]) do
  680.                             if not console[i][k].pausetime then
  681.                                 if console[i][k].align == "right" or console[i][k].align == "center" then
  682.                                     phasor_sendconsoletext(i, consolecenter(string.sub(console[i][k].message, 1, 78)))
  683.                                 else
  684.                                     phasor_sendconsoletext(i, string.sub(console[i][k].message, 1, 78))
  685.                                 end
  686.                             end
  687.                         end
  688.                     end
  689.                 end
  690.             else
  691.                 console[i] = nil
  692.             end
  693.         end
  694.     end
  695.    
  696.     return true
  697. end
  698.  
  699. function consolecenter(text)
  700.     if text then
  701.         local len = string.len(text)
  702.         for i = len + 1, 78 do
  703.             text = " " .. text
  704.         end
  705.         return text
  706.     end
  707. end
  708.  
  709. function opairs(t)
  710.     local keys = {}
  711.     for k,v in pairs(t) do
  712.         table.insert(keys, k)
  713.     end    
  714.     table.sort(keys,
  715.     function(a,b)
  716.         if type(a) == "number" and type(b) == "number" then
  717.             return a < b
  718.         end
  719.         an = string.lower(tostring(a))
  720.         bn = string.lower(tostring(b))
  721.         if an ~= bn then
  722.             return an < bn
  723.         else
  724.             return tostring(a) < tostring(b)
  725.         end
  726.     end)
  727.     local count = 1
  728.     return function()
  729.         if table.unpack(keys) then
  730.             local key = keys[count]
  731.             local value = t[key]
  732.             count = count + 1
  733.             return key,value
  734.         end
  735.     end
  736. end
  737.  
  738. function table.len(t)
  739.     local count = 0
  740.     for k,v in pairs(t) do
  741.         count = count + 1
  742.     end
  743.     return count
  744. end
  745. -- Stop sendconsoletext overloaded
  746.  
  747. -- Created by H® Shaft.
  748. -- Thanks to Oxide, AelitePrime, Nugget & Wizard - and 002!
  749. -- Visit http://halorace.org/forum/index.php?topic=514.0 or
  750. -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement