Advertisement
th3w1zard1

AFKBeast

Jun 6th, 2014
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.01 KB | None | 0 0
  1. --Ultimate AFK-Handling Script
  2. --Created by Wizard, in 2012/2013
  3. --This script completely revamps AFK-handling in a revolutionary new way.
  4. --Version 1.01 (released July 30th 2014)
  5.  
  6. --This is how many minutes before a player will get set to the AFK mode.
  7. --The AFK mode means they're hidden, and put under the map so no one will see them.
  8. timeafkbeforeset = 0.75 -- minutes
  9.  
  10. --This is how many minutes before an afk player will be kicked from the server
  11. --REMINDER: This will ONLY kick if maxplayersbeforekick is reached.
  12. timeafkbeforekick = 2 -- minutes
  13.  
  14. --This determines how many people need to be in the server before the script will kick an afk.
  15. --The script will kick 1 afk, and it will kick the player with the LONGEST AFK TIME.
  16. maxplayersbeforekick = 16
  17.  
  18. --Set this to true if you're using zombies, false if not.
  19. zombies = false
  20.  
  21. --Admins can still be set to the AFK mode even if this is true.
  22. dont_kick_admins = true
  23.  
  24. --General messages, set to nil to disable them.
  25. afkkick_msg = "%s is afk and is now being kicked from the server!"
  26. afkset_msg = "%s is now afk!"
  27. afkunset_msg = "%s is no longer afk!"
  28.  
  29. --this was never finished, expect this in a later release!
  30. afk_portal_to_teamhog_race = true -- Set this to true to allow afks to be put into hogs of their teammates (RACE ONLY)
  31.  
  32. --don't touch anything below this point -> .
  33. CurrentAim = {}
  34. playerWasKilled = {}
  35. afk = {}
  36. afktime = {}
  37. currentplayers = 0
  38. isKicked = {}
  39. justSpawned = {}
  40. afkSpot = {}
  41. pdeaths = {}
  42. randomNames = {"Butcher", "Caboose", "Crazy", "Cupid", "Darling", "Dasher", "Disco", "Donut", "Dopey", "Ghost", "Goat", "Grumpy",
  43. "Hambone", "Hollywood", "Howard", "Jack", "Killer", "King", "Mopey", "Noodle", "Penguin", "Pirate", "Prancer", "Saucy", "Shadow",
  44. "Sleepy", "Snake", "Sneak", "Stompy", "Stumpy", "The Bear", "The Big L", "Tooth", "Walla Walla", "Weasel", "Wheezy", "Whicker",
  45. "Whisp", "Wilshire"}
  46. sharedhashes = {
  47.                 "f443106bd82fd6f3c22ba2df7c5e4094",
  48.                 "c702226e783ea7e091c0bb44c2d0ec64",
  49.                 "d72b3f33bfb7266a8d0f13b37c62fddb",
  50.                 "55d368354b5021e7dd5d3d1525a4ab82",
  51.                 "3d5cd27b3fa487b040043273fa00f51b",
  52.                 "b661a51d4ccf44f5da2869b0055563cb",
  53.                 "740da6bafb23c2fbdc5140b5d320edb1",
  54.                 "10440b462f6cbc3160c6280c2734f184",
  55.                 "7503dad2a08026fc4b6cfb32a940cfe0",
  56.                 "4486253cba68da6786359e7ff2c7b467",
  57.                 "f1d7c0018e1648d7d48f257dc35e9660",
  58.                 "40da66d41e9c79172a84eef745739521",
  59.                 "2863ab7e0e7371f9a6b3f0440c06c560",
  60.                 "34146dc35d583f2b34693a83469fac2a",
  61.                 "b315d022891afedf2e6bc7e5aaf2d357",
  62.                 "81f9c914b3402c2702a12dc1405247ee",
  63.                 "63bf3d5a51b292cd0702135f6f566bd1",
  64.                 "6891d0a75336a75f9d03bb5e51a53095",
  65.                 "325a53c37324e4adb484d7a9c6741314",
  66.                 "0e3c41078d06f7f502e4bb5bd886772a",
  67.                 "fc65cda372eeb75fc1a2e7d19e91a86f",
  68.                 "f35309a653ae6243dab90c203fa50000",
  69.                 "50bbef5ebf4e0393016d129a545bd09d",
  70.                 "a77ee0be91bd38a0635b65991bc4b686",
  71.                 "3126fab3615a94119d5fe9eead1e88c1",
  72.                 }
  73.  
  74. function GetRequiredVersion()
  75.     return 200
  76. end
  77.  
  78. function OnScriptLoad(processid, game, persistent)
  79.     if zombies then
  80.         zombie_team = getZombieTeam()
  81.     end
  82.     for i = 0,15 do
  83.         if getplayer(i) then
  84.             local index = getname(i)
  85.             afktime[index] = 0
  86.             currentplayers = currentplayers + 1
  87.             afkSpot[index] = {}
  88.         end
  89.     end
  90.     GetGameAddresses(game)
  91.     registertimer(500, "gameStartedCheck")
  92.     gametype = readbyte(gametype_base + 0x30)
  93.     if gametype == 1 then
  94.         gametype = "CTF"
  95.     elseif gametype == 2 then
  96.         gametype = "Slayer"
  97.     elseif gametype == 4 then
  98.         gametype = "KOTH"
  99.     end
  100.     afktimer = registertimer(500, "afkTimer")
  101.     handleafks = registertimer(1000, "handleAfks")
  102.     --using the hide method seemed to crash the server occasionally
  103.     --hiddentimer = registertimer(20, "hiddenTimer")
  104. end
  105.  
  106. function gameStartedCheck(id, count)
  107.     if not game_started then
  108.         setGameVariables()
  109.     end
  110.     return false
  111. end
  112.  
  113. function GetGameAddresses(game)
  114.     if game == "PC" then
  115.         ctf_globals = 0x639B98 -- Confirmed.
  116.         oddball_globals = 0x639E18 -- Confirmed.
  117.         slayer_globals = 0x63A0E8
  118.         name_base = 0x745D4A
  119.         flag_respawn_addr = 0x488A7E
  120.         specs_addr = 0x662D04
  121.         map_addr = 0x698F21
  122.         hashcheck_addr = 0x59c280
  123.         versioncheck_addr = 0x5152E7
  124.         map_pointer = 0x63525c
  125.         gametype_base = 0x671340
  126.         gametime_base = 0x671420
  127.         network_server_globals = 0x69B934 -- Confirmed.
  128.         machine_pointer = 0x745BA0
  129.         version_address = 0x5DF840
  130.         timelimit_address = 0x626630
  131.         profilepath = 0x6A0A99
  132.         special_chars = 0x517D6B -- special chars in svname patch
  133.         gametype_patch = 0x481F3C -- gametype patch
  134.         devmode_patch1 = 0x4A4DBF -- devmode
  135.         devmode_patch2 = 0x4A4E7F -- devmode
  136.         network_base = 0x745BA8
  137.     else
  138.         ctf_globals = 0x5BDBB8 -- Confirmed.
  139.         oddball_globals = 0x5BDE78 -- Confirmed.
  140.         slayer_globals = 0x5BE108
  141.         name_base = 0x6C7B6A
  142.         specs_addr = 0x5E6E63
  143.         map_addr = 0x61D151
  144.         hashcheck_addr = 0x530130
  145.         versioncheck_addr = 0x4CB587
  146.         map_pointer = 0x5B927C
  147.         gametype_base = 0x5F5498
  148.         gametime_base = 0x5F55BC
  149.         network_server_globals = 0x61FB64 -- Confirmed.
  150.         machine_pointer = 0x6C7980
  151.         version_address = 0x564B34
  152.         gametype_patch = 0x45E50C
  153.         devmode_patch1 = 0x47DF0C
  154.         devmode_patch2 = 0x47DFBC -- devmode
  155.         network_base = 0x6C7988
  156.     end
  157. end
  158.  
  159. function setGameVariables()
  160.     LoadTags()
  161.     teamplay = readbyte(gametype_base + 0x34)
  162.     if teamplay == 1 then
  163.         teamplay = true
  164.     else
  165.         teamplay = false
  166.     end
  167.     gametype_lives = readbyte(gametype_base + 0x50)
  168.     if gametype_lives == 0 then
  169.         gametype_lives = false
  170.     end
  171.     gametype_game = readdword(gametype_base + 0x30)
  172.     if gametype_game == 1 then
  173.         func = CtfClientUpdate
  174.         registertimer(200, "CtfTimer")
  175.         gametype = "CTF"
  176.     elseif gametype_game == 2 then
  177.         killinorder = readbyte(gametype_base + 0x7E)
  178.         if killinorder == 1 then
  179.             killinorder = true
  180.         else
  181.             killinorder = false
  182.         end
  183.         gametype = "Slayer"
  184.     elseif gametype_game == 3 then
  185.         --func = OddballClientUpdate
  186.         gametype = "Oddball"
  187.     elseif gametype_game == 4 then
  188.         --registertimer(200, "KothTimer")
  189.         gametype = "King"
  190.     elseif gametype_game == 5 then
  191.         race_type = readbyte(gametype_base + 0x7C)
  192.         if race_type == 1 or race_type == 2 then
  193.             --func = RaceClientUpdate
  194.             registertimer(200, "RaceTimer")
  195.         elseif race_type == 3 then
  196.             --func = RallyClientUpdate
  197.         end
  198.         gametype = "Race"
  199.         total_checkpoints = readdword(race_globals)
  200.     end
  201. end
  202.  
  203. function OnScriptUnload()
  204.     removetimer(afktimer)
  205.     removetimer(handleafks)
  206. end
  207.  
  208. function LoadTags()
  209.     -- Globals
  210.     global_distanceId = gettagid("jpt!", "globals\\distance")
  211.     global_fallingId = gettagid("jpt!", "globals\\falling")
  212. end
  213.  
  214. function OnNewGame(map)
  215.     if not afktimer then
  216.         afktimer = registertimer(500, "afkTimer")
  217.     end
  218.     game_started = true
  219.     setGameVariables()
  220.     ongameend = false
  221. end
  222.  
  223. function OnGameEnd(stage)
  224.     if stage == 1 then
  225.         removetimer(afktimer)
  226.         ongameend = true
  227.     end
  228. end
  229.  
  230.  
  231. function OnServerChat(player, mode, message)
  232.     if message:find("!afkstatus") then
  233.         player = tonumber(message:sub(12, 13))
  234.         privatesay(player, tostring(getname(player)) .. ": " .. tostring(playerIsAfk(player)))
  235.         return false
  236.     end
  237.     if tonumber(player) then
  238.         if player >= 0 and player <= 15 then
  239.             if getplayer(player) then
  240.                 local index = getname(player)
  241.                 afktime[index] = 0
  242.             end
  243.         end
  244.     end
  245. end
  246.  
  247.  
  248. --[[
  249. function OnServerCommandAttempt(player, command, password)
  250.  
  251.     --return true
  252. end
  253. --]]
  254.  
  255. --[[
  256. function OnServerCommand(player, command)
  257.  
  258.     --return true
  259. end
  260. --]]
  261.  
  262. --[[
  263. function OnNameRequest(hash, name)
  264.  
  265.     --return true, name
  266. end
  267. --]]
  268.  
  269. --[[
  270. function OnTeamDecision(team)
  271.  
  272.     --return team
  273. end
  274. --]]
  275.  
  276. function OnPlayerJoin(player)
  277.     if not ongameend then
  278.         local index = getname(player)
  279.         currentplayers = currentplayers + 1
  280.         afktime[index] = 0
  281.         CurrentAim[index] = {}
  282.         afkSpot[index] = {}
  283.     else
  284.         sayWizard("WTF! ONGAMEEND IS TRUE BRO")
  285.     end
  286. end
  287.  
  288. function OnPlayerLeave(player)
  289.     if not ongameend then
  290.         local index = getname(player)
  291.         currentplayers = currentplayers - 1
  292.         afktime[index] = 0
  293.         afk[index] = nil
  294.         CurrentAim[index] = nil
  295.         isKicked[player] = nil
  296.         afkSpot[index] = {}
  297.         playerWasKilled[player] = nil
  298.         justSpawned[player] = nil
  299.        
  300.         local hash = gethash(player)
  301.         local name = getname(player)
  302.         local ip = getip(player)
  303.         local ipport = getip(player) .. ":" .. getport(player)
  304.         for i = 1,#indexes do
  305.             if indexes[i] == hash or indexes[i] == name or indexes[i] == ip or indexes[i] == ipport then
  306.                 indexes[i] = nil
  307.             end
  308.         end
  309.     end
  310. end
  311.  
  312. function OnPlayerKill(killer, victim, mode)
  313.     if tonumber(victim) then
  314.         playerWasKilled[victim] = true
  315.         if justSpawned[victim] then
  316.             removetimer(justSpawned[victim])
  317.             justSpawned[victim] = nil
  318.         end
  319.     end
  320. end
  321.  
  322. --[[
  323. function OnKillMultiplier(player, multiplier)
  324.  
  325.  
  326. end
  327. --]]
  328.  
  329. --[[
  330. function OnPlayerSpawn(player)
  331.  
  332.  
  333. end
  334. --]]
  335.  
  336. function OnPlayerSpawnEnd(player)
  337.     justSpawned[player] = registertimer(800, "JustSpawned", player)
  338.     playerWasKilled[player] = nil
  339. end
  340.  
  341. function JustSpawned(id, count, player)
  342.     updatePlayerAim(player)
  343.     --if getname(player) then sayWizard(tostring(getname(player)) .. " has spawned! Possibly no longer afk!") end
  344.     if getplayer(player) then
  345.         local index = getname(player)
  346.         if afk[index] then
  347.             local m_objectId = getplayerobjectid(player)
  348.             if m_objectId and m_objectId ~= 0xFFFFFFFF then
  349.                 local m_object = getobject(m_objectId)
  350.                 if m_object then
  351.                     --comment all of below for hide method (remember to uncomment hidetimer at top)
  352.                     writebit(m_object + 0x10, 7, 0)
  353.                     local x,y,z = getobjectcoords(m_objectId)
  354.                     z = z or 69
  355.                     movobjectcoords(m_objectId, x, y, z-100)
  356.                     local m_object = getobject(m_objectId)
  357.                     afkSpot[index] = {x, y, z}
  358.                 end
  359.             end
  360.         end
  361.     end
  362.     justSpawned[player] = nil
  363.     return false
  364. end
  365.  
  366. function OnTeamChange(player, old_team, new_team, voluntary)
  367.     playerWasKilled[player] = true
  368.     --return true
  369. end
  370.  
  371. --[[
  372. function OnClientUpdate(player)
  373.  
  374.  
  375. end
  376. --]]
  377.  
  378. --[[
  379. function OnObjectInteraction(player, objId, mapId)
  380.  
  381.     --return true
  382. end
  383. --]]
  384.  
  385. --[[
  386. function OnWeaponReload(player, weapId)
  387.  
  388.     --return true
  389. end
  390. --]]
  391.  
  392. --[[
  393. function OnVehicleEntry(player, vehiId, seat, mapId, voluntary)
  394.  
  395.     --return true
  396. end
  397. --]]
  398.  
  399. --[[
  400. function OnVehicleEject(player, voluntary)
  401.  
  402.     --return true
  403. end
  404. --]]
  405.  
  406. function OnDamageLookup(receiving_obj, causing_obj, mapId, tagdata)
  407.     if mapId == global_distanceId or mapId == global_fallingId then
  408.         odl_multiplier(0.00001)
  409.     end
  410.     --return true
  411. end
  412.  
  413. --[[
  414. function OnDamageApplication(receiver, causer, mapId, location, backtap)
  415.  
  416.     --return true
  417. end
  418. --]]
  419.  
  420. --[[
  421. function OnWeaponAssignment(player, objId, slot, weapId)
  422.  
  423.     return true
  424. end
  425. --]]
  426.  
  427. --[[
  428. function OnObjectCreationAttempt(mapId, parentId, player)
  429.  
  430.     --return mapId
  431. end
  432. --]]
  433.  
  434. --[[
  435. function OnObjectCreation(objId)
  436.  
  437.  
  438. end
  439. --]]
  440.  
  441. --This timer will add the AFK times of all the players to a table
  442. --so it can be used by the other timers. This timer also unsets afk players.
  443. function afkTimer(id, count)
  444.     for i = 0,15 do
  445.         if getplayer(i) then
  446.             local index = getname(i)
  447.             if not playerWasKilled[i] and not justSpawned[i] then
  448.                 if playerIsAfk(i) then
  449.                     afktime[index] = afktime[index] + (1/120)
  450.                     --sayWizard(tostring(getname(i)) .. ": is not moving! AFKTIME: " .. tostring(afktime[index]))
  451.                 else
  452.                     --check if the player is set as afk
  453.                     --if they are, unafk them.
  454.                     --REM: THIS NEEDS TO BE IN AFKTIMER AND NOT HANDLEAFKS
  455.                     if afk[index] then
  456.                         afk[index] = nil
  457.                         unsetAfkPlayer(i)
  458.                     end
  459.                     afktime[index] = 0
  460.                     --sayWizard(tostring(getname(i)) .. " is moving!")
  461.                 end
  462.             end
  463.         end
  464.     end
  465.     return true
  466. end
  467.  
  468. --this timer is responsible for handling AFK players if they're AFK for a set amount of time
  469. function handleAfks(id, count)
  470.     local player = getLongestAfkPlayer()
  471.     if player[2] >= timeafkbeforekick then
  472.         if currentplayers >= maxplayersbeforekick and not kickingHappening then
  473.             if (not isadmin(player[1]) and dont_kick_admins) or not dont_kick_admins then
  474.                 if afkkick_msg then
  475.                     say(string.format(afkkick_msg, getname(player[1])))
  476.                 end
  477.                 svcmd("sv_kick " .. resolveplayer(player[1]))
  478.                 log_msg(3, "AFKBEAST IS NOW KICKING " .. tostring(resolveplayer(player[1])) .. " NAME: " .. tostring(getname(player[1])) .. ", DEBUG INFO FOLLOWS: Currentplayers: " .. currentplayers .. " Maxplayersbeforekick: " .. maxplayersbeforekick .. "KickHappening: " .. tostring(kickingHappening) .. "isKickedTable: " .. tostring(isKicked[player[1]]) .. " AFKTime: " .. tostring(player[2]))
  479.                 isKicked[player[1]] = true
  480.                 kickingHappening = true
  481.             end
  482.         end
  483.     end
  484.     for i = 0,15 do
  485.         if getplayer(i) then
  486.             if not playerWasKilled[i] and not justSpawned[i] then
  487.                 local index = getname(i)
  488.                 if afktime[index] >= timeafkbeforeset and not afk[index] then
  489.                     if gametype ~= "CTF" or (gametype == "CTF" and not isHoldingFlag(i)) then
  490.                         setAfkPlayer(i)
  491.                         --sayWizard("SETTING AFK PLAYER: " .. i .. " NOW")
  492.                         if afkset_msg then
  493.                             say(string.format(afkset_msg, getname(i)))
  494.                         end
  495.                     end
  496.                 else
  497.                     --say(tostring(afktime[index]) .. " NOT ENOUGH AFK TO SET")
  498.                 end
  499.             end
  500.         end
  501.     end
  502.     if zombies then checkIfAllZombiesAfk() end
  503.     return true
  504. end
  505.  
  506. function isHoldingFlag(player)
  507.     local redflag = readdword(ctf_globals)
  508.     local blueflag = readdword(ctf_globals + 0x4)
  509.     local m_objectId = getplayerobjectid(player)
  510.     if m_objectId and m_objectId ~= 0xFFFFFFFF then
  511.         local m_object = getobject(m_objectId)
  512.         if m_object then
  513.             local weapId = readdword(m_object + 0x118)
  514.             if weapId == redflag or weapId == blueflag then
  515.                 return true
  516.             end
  517.         end
  518.     end
  519.     return false
  520. end
  521.  
  522. --this timer is responsible for hiding afk players.
  523. --sometimes causes crash, therefore not used.
  524. function hiddenTimer(id, count)
  525.     if afk ~= {} then
  526.         for k,v in pairs(afk) do
  527.             local m_player = getplayer(k)
  528.             if m_player then
  529.                 --say("HIDING: " .. tostring(getname(k))) .. " Player #: " .. k)
  530.                 writefloat(m_player + 0xF8, 999)
  531.                 writefloat(m_player + 0xFC, 999)
  532.                 writefloat(m_player + 0x100, 999)
  533.             end
  534.         end
  535.     end
  536.     return true
  537. end
  538.  
  539. --this function will loop through all the players and return the player
  540. --that has been AFK the longest.
  541. function getLongestAfkPlayer()
  542.     local max = {0,0}
  543.     for k,v in pairs(afktime) do
  544.         if max[2] < afktime[k] and not afk[k] then
  545.             max = {k, v}
  546.         end
  547.     end
  548.     return max
  549. end
  550.  
  551. --This function will update the player's aim in the currentaim table.
  552. function updatePlayerAim(player)
  553.     local m_player = getplayer(player)
  554.     if m_player then
  555.         local index = getname(player)
  556.         local m_objectId = getplayerobjectid(player)
  557.         if m_objectId and m_objectId ~= 0xFFFFFFFF then
  558.             local m_object = getobject(m_objectId)
  559.             if m_object then
  560.                 local x_aim = readfloat(m_object + 0x230)
  561.                 local y_aim = readfloat(m_object + 0x234)
  562.                 local z_aim = readfloat(m_object + 0x238)
  563.                 CurrentAim[index] = {x_aim, y_aim, z_aim}
  564.             end
  565.         end
  566.     end
  567. end
  568.  
  569.  
  570. --This function will determine if the passed player is AFK
  571. function playerIsAfk(player)
  572.     local m_player = getplayer(player)
  573.     if m_player then
  574.         if not justSpawned[player] then
  575.             --if getname(player) then sayWizard("PLAYERISAFK") end
  576.             local index = getname(player)
  577.             local m_objectId = getplayerobjectid(player)
  578.             if m_objectId and m_objectId ~= 0xFFFFFFFF then
  579.                 local m_object = getobject(m_objectId)
  580.                 if m_object then
  581.                     local x_aim = readfloat(m_object + 0x230)
  582.                     local y_aim = readfloat(m_object + 0x234)
  583.                     local z_aim = readfloat(m_object + 0x238)
  584.                     if not CurrentAim[index] then
  585.                         CurrentAim[index] = {x_aim, y_aim, z_aim}
  586.                         --if getname(player) then sayWizard(getname(player) .. " this shouldn't be called when killed") end
  587.                         --if getname(player) then sayWizard(getname(player) .. ": CURRENT AIM CREATED") end
  588.                         return false
  589.                     else
  590.                         if (x_aim ~= CurrentAim[index][1]) or (y_aim ~= CurrentAim[index][2]) or (z_aim ~= CurrentAim[index][3]) then
  591.                             CurrentAim[index] = {x_aim, y_aim, z_aim}
  592.                             --if getname(player) then sayWizard(tostring(getname(player)) .. ": CURRENT AIM UPDATED IN PLAYERISAFK") end
  593.                             return false
  594.                         else
  595.                             --if getname(player) then sayWizard(tostring(getname(player)) .. " is afk (towiz)") end
  596.                             return true
  597.                         end
  598.                     end
  599.                 end
  600.             else
  601.                 --if getname(player) then sayWizard("M_OBJECTID IS NIL") end
  602.                 return false
  603.             end
  604.         else
  605.             --if getname(player) then sayWizard("JustSpawned") end
  606.             return true
  607.         end
  608.     else
  609.         --if getname(player) then sayWizard("M_PLAYER IS NIL IN PLAYERISAFK") end
  610.         return true
  611.     end
  612.     return false
  613. end
  614.  
  615.  
  616. function checkIfAfk(player)
  617.     local m_player = getplayer(player)
  618.     if m_player then
  619.         local index = getname(player)
  620.         if afk[index] then
  621.             return true
  622.         end
  623.     end
  624.     return false
  625. end
  626.  
  627. --This function will check if all the zombies are afk, if they are
  628. --then this function will change a random person's team
  629. function checkIfAllZombiesAfk()
  630.     local zombies = getZombies()
  631.     if #zombies >= 1 then
  632.         --this next section will determine if all the zombies are afk or not
  633.         local bool = true
  634.         for i = 1,#zombies do
  635.             if not checkIfAfk(zombies[i]) then
  636.                 bool = false
  637.                 break
  638.             end
  639.         end
  640.         --now we change a random person to zombie cuz all the zombies are currently afk
  641.         if bool then
  642.             local player = ChooseRandomPlayer(1)
  643.             --if getname(player) then say(tostring(getname(player)) .. " will be changed to zombie because all the zombies are afk!") end
  644.             --if getname(player) then sayWizard(tostring(#zombies)) end
  645.             changeteam(player, false)
  646.             kill(player)
  647.         else
  648.             --if getname(player) then sayWizard("NO ZOMBIES ARE AFK") end
  649.         end
  650.     end
  651. end
  652.  
  653. function sayWizard(message)
  654.     for i = 0,15 do
  655.         if getplayer(i) then
  656.             if gethash(i):find("56d5f") then
  657.                 privatesay(i, message)
  658.                 break
  659.             end
  660.         end
  661.     end
  662. end
  663.  
  664.  
  665.  
  666. -- this function searches through current players and selects a random one
  667. function ChooseRandomPlayer(excludeTeam)
  668.     local t = {}
  669.     -- loop through all 16 possible spots and add to table
  670.     for i = 0,15 do
  671.         -- check if the player exists
  672.         if getplayer(i) then
  673.             local team = getteam(i)
  674.             if team and team ~= excludeTeam then
  675.                 table.insert(t, i)
  676.             end
  677.         end
  678.     end
  679.     if #t > 0 then
  680.         -- generate a random number that we will use to select a player
  681.         local tableCount = #t
  682.         local r = math.random(1, tableCount)
  683.         return t[r]
  684.     else
  685.         return nil
  686.     end
  687. end
  688.  
  689.  
  690. --This function will set the player as AFK. It will put them under the map, and turn fall damage off for the player.
  691. function setAfkPlayer(player)
  692.     local index = getname(player)
  693.     updatePlayerAim(player)
  694.     local m_objectId = getplayerobjectid(player) or 0xFFFFFFFF
  695.     local m_object = getobject(m_objectId)
  696.     if m_object then
  697.         local killplayer
  698.         if gametype_lives then
  699.             local m_player = getplayer(player)
  700.             if m_player then
  701.                 local deaths = readshort(m_player+0xAE)
  702.                 pdeaths[player] = deaths
  703.                 writeshort(m_player+0xAE, gametype_lives-1)
  704.                 writeshort(stat_globals+player*0x30+0x14, gametype_lives-1)
  705.                 killplayer = true
  706.             end
  707.         end
  708.         if zombies then
  709.             if getteam(player) ~= zombie_team then
  710.                 --sayWizard("CHANGING TEAM")
  711.                 changeteam(player, false)
  712.                 killplayer = true
  713.             end
  714.         end
  715.         if not killplayer then
  716.             local x,y,z = getobjectcoords(m_objectId)
  717.             if tonumber(z) then
  718.                 movobjectcoords(m_objectId, x, y, z-100)
  719.             end
  720.             afkSpot[index] = {x, y, z}
  721.             writebit(m_object + 0x10, 0, 1)
  722.         else
  723.             kill(player)
  724.             afkSpot[index] = {}
  725.         end
  726.     end
  727.     afk[index] = true
  728. end
  729.  
  730.  
  731. --This function unsets an AFK player so they can return to the game.
  732. function unsetAfkPlayer(player)
  733.     local index = getname(player)
  734.     if afkunset_msg then
  735.         say(string.format(afkunset_msg, getname(player)))
  736.     end
  737.     afk[index] = nil
  738.     local m_objectId = getplayerobjectid(player)
  739.     if m_objectId and m_objectId ~= 0xFFFFFFFF then
  740.         local m_object = getobject(m_objectId)
  741.         if m_object then
  742.             movobjectcoords(m_objectId, afkSpot[index][1], afkSpot[index][2], afkSpot[index][3] + 2)
  743.             writebit(m_object + 0x10, 0, 0)
  744.             afkSpot[index] = {}
  745.         end
  746.     end
  747.     if gametype_lives then
  748.         local m_player = getplayer(player)
  749.         if m_player then
  750.             writeshort(m_player+0xAE, pdeaths[player]-1)
  751.             writeshort(stat_globals+player*0x30+0x14, pdeaths[player]-1)
  752.             writedword(m_player+0x2C, 0)
  753.             kill(player)
  754.         end
  755.     end
  756. end
  757.  
  758.  
  759. function getZombies()
  760.     local zombies = {}
  761.     for i = 0,15 do
  762.         local m_player = getplayer(i)
  763.         if m_player then
  764.             local team = readbyte(m_player + 0x20)
  765.             if team == zombie_team then
  766.                 table.insert(zombies, i)
  767.             end
  768.         end
  769.     end
  770.     --[[local msgz = ""
  771.     for i = 1,#zombies do
  772.         local name = getname(zombies[i])
  773.         if name then
  774.             msgz = msgz .. name .. " "
  775.         end
  776.     end
  777.     sayWizard(msgz)--]]
  778.     return zombies
  779. end
  780.  
  781.  
  782. function getZombieTeam()
  783.     return 1
  784. end
  785.  
  786. function hashtoplayer(hash)
  787.     for i = 0,15 do
  788.         local m_player = getplayer(i)
  789.         if m_player then
  790.             if gethash(i) == hash then return i end
  791.         end
  792.     end
  793. end
  794.  
  795. --REM: fix this function... doesn't seem to uniquely index right.. shame.. :/
  796. indexes = {}
  797.  
  798. function getindex(player, method)
  799.     local m_player = getplayer(player)
  800.     if m_player then
  801.         local name = getname(player)
  802.         local ip = getip(player)
  803.         local hash = gethash(player)
  804.         local ipport = getip(player) .. ":" .. getport(player)
  805.         for i = 1,#indexes do
  806.             if indexes[i] == ip then
  807.                 for k,v in pairs(_G) do
  808.                     if type(v) == "table" then
  809.                         for k2,v2 in pairs(v) do
  810.                             if k2 == ip then
  811.                                 indexes[i] = nil
  812.                                 v[k2] = nil
  813.                                 indexes[i] = v2
  814.                                 v[getindex(player, "hash")] = v2
  815.                             end
  816.                         end
  817.                     end
  818.                 end
  819.                 break
  820.             elseif indexes[i] == name or indexes[i] == hash or indexes[i] == ipport then
  821.                 return indexes[i]
  822.             end
  823.         end
  824.         if not method then
  825.             method = "name"
  826.         end
  827.         if method == "hash" then
  828.             for i = 1,#sharedhashes do
  829.                 if sharedhashes[i] == hash then
  830.                     --log_msg(2, "UNABLE TO FIND UNIQUE INDEX FOR PLAYER " .. resolveplayer(player) .. ". NAME: " .. name .. " IP: " .. ip .. " Hash: " .. hash)
  831.                     table.insert(indexes, ipport)
  832.                     return ipport
  833.                 end
  834.             end
  835.             table.insert(indexes, hash)
  836.             return hash
  837.         elseif method == "ip" then
  838.             for i = 0,15 do
  839.                 if getplayer(i) then
  840.                     local ip2 = getip(i)
  841.                     if ip2 == ip then
  842.                         return getindex(player, "hash")
  843.                     end
  844.                 end
  845.             end
  846.             table.insert(indexes, ip)
  847.             return ip
  848.         elseif method == "name" then
  849.             for i = 1,#randomNames do
  850.                 if randomNames[i] == name then
  851.                     return getindex(player, "ip")
  852.                 end
  853.             end
  854.             table.insert(indexes, name)
  855.             return name
  856.         end
  857.     end
  858. end
  859.  
  860. --Phasor's getrandomnumber and lua's math.random really suck.
  861.  
  862. math.randomseed(os.time())
  863. getsuckyrand = math.random
  864.  
  865. --Low and High are INCLUSIVE.
  866. function math.random(low, high)
  867.     low = tonumber(low) or raiseerror("Bad argument #1 to 'math.random' (number expected, got " .. tostring(type(low)) .. ")")
  868.     high = tonumber(high) or raiseerror("Bad argument #2 to 'math.random' (number expected, got " .. tostring(type(high)) .. ")")
  869.     getsuckyrand(low, high) getsuckyrand(low, high) getsuckyrand(low, high)  -- I really don't trust it... haha
  870.     return getsuckyrand(low, high)
  871. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement