Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 14th, 2012  |  syntax: Lua  |  size: 12.86 KB  |  hits: 40  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. --[[ =CE= Chris's Essentials Script
  2. Script by: =CE= Chris
  3.  
  4. Version History:
  5. 0.1: Initial Creation
  6.  
  7. ]]
  8.  
  9.  
  10. --- Settings ---
  11. haloVersion = "CE"                              -- Halo PC or Halo CE. (PC, CE)
  12. useDatabase = false                             -- Use a mysql database for admins and clan roster. (true, false)
  13. welcomeMessage = "Welcome to the server!"       -- Welcome message for players. nil for none, \n to seperate multiple messages. (nil, "string")
  14. restoreScores = true                            -- Resume player scores when they quit and rejoin in the same round. (true, false)
  15. showDetails = true                              -- Show more detailed info in console when loading up the script. (true, false)
  16. privateChat = true                              -- Enable private chat with @.  (true, false)
  17. antiImposter = true                             -- Enable anti-imposter for clans. (true, false)
  18. useLog = true                                   -- Enable custom log file. (true, false)
  19. -- Anti-Imposter Settings --
  20. tagLength = 4                                   -- Length of your clan's tag. (real)
  21. clanTags = {"-EX-", "=EX=", "«EX»"}             -- For multiple types of tags. (table)
  22. impAction = "sv_kick"                           -- Command to run when an imposter is found. (string)
  23. -- Database Settings --
  24. sourcename = ""                                 -- Database source name.  (string)
  25. username = ""                                   -- Database username.  (string)
  26. password = ""                                   -- Datbase password.  (string)
  27. hostname = ""                                   -- Database hostname.  (string)
  28. port = 0                                        -- Database port.  (real)
  29. adminTable = "admins"                           -- Admin table name.  (string)
  30. clanTable = "members"                           -- Clan roster table name.  (string)
  31. -- File Settings --
  32. membersFile = "members.txt"                     -- Clan roster text file name.  (string)
  33. logFile = "log.log"                             -- Log file name.  (string)
  34. ----------------
  35.  
  36. --- Internal Stuff (Don't touch!) ---
  37. global_admins = {}
  38. global_members = {}
  39. global_gametype = nil
  40. global_players = {}
  41. -------------------------------------
  42.  
  43. if useDatabase then
  44.     require('luasql.mysql')
  45. end
  46.  
  47. function GetRequiredVersion()
  48.     return 10057
  49. end
  50.  
  51. function OnScriptLoad(process)
  52.     hprintf("Script by: =CE= Chris\nXfire: chrisk123999")
  53.     if useDatabase then
  54.         hprintf("Loading admins...")
  55.         local env = assert (luasql.mysql())
  56.         local con = assert (env:connect(sourcename,username,password,hostname,port))
  57.         local i = 0
  58.         for name, hash, access in rows (con, "SELECT * FROM `" .. adminTable .. "`") do
  59.             local temp_table = {id, name, hash, access}
  60.             global_admins[i] = temp_table
  61.             i = i + 1
  62.             if showDetails then
  63.                 hprintf("Name: " .. name .. " Hash: " .. hash .. " Access: " .. access)
  64.             end
  65.             hprintf(#global_admins .. " admins loaded.")
  66.         end
  67.         if antiImposter then
  68.             hprintf("Loading clan members...")
  69.             i = 0
  70.             for name, hash in rows (con, "SELECT * FROM `" .. clanTable .. "`") do
  71.                 global_members[i] = hash
  72.                 i = i + 1
  73.                 if showDetails then
  74.                     hprintf("Name: " .. name .. " Hash: " .. hash)
  75.                 end
  76.                 hprintf(#global_members .. " clan members loaded.")
  77.             end
  78.         end
  79.         con:close()
  80.         env:close()
  81.     else
  82.         if antiImposter then
  83.             hprintf("Loading clan members...")
  84.             local file = io.open(membersFile)
  85.             if file ~= nil then
  86.                 local memberString = file:read("*a")
  87.                 local count = gettokencount(memberString, "\n") -1
  88.                 for i=0, count do
  89.                     local mHash = gettoken(memberString, "\n", i)
  90.                     global_members[i] = mHash
  91.                     if showDetails then
  92.                         hprintf("Hash: " .. mHash)
  93.                     end
  94.                 end
  95.                 hprintf(#global_members .. " clan members loaded.")
  96.             else
  97.                 hprintf(membersFile .. " doesn't exist!")
  98.             end
  99.         end
  100.     end
  101.     local gametype_base = 0x671340
  102.     if haloVersion == "CE" then
  103.         gametype_base =  0x5F5498
  104.     end
  105.     global_gametype = readbyte(gametype_base, 0x30)
  106. end
  107.  
  108. function OnScriptUnload()
  109. end
  110.  
  111. function OnNewGame(map)
  112.     if useLog then
  113.         aLog("[Info] New game on " .. map)
  114.     end
  115. end
  116.  
  117. function OnGameEnd(mode)
  118. end
  119.  
  120. function OnServerChat(player, chattype, message)
  121.     local C_Allow = true
  122.     if string.sub(message, 1, 1) == "\\" then
  123.         C_Allow = false
  124.         if C_Command == "about" then
  125.             privatesay(player, "=CE= Chris's Phasor Essentials Script\nXfire: chrisk123999")
  126.         end
  127.     elseif string.sub(message, 1, 1) == "/" then
  128.         if isadmin(player) or isDatabaseAdmin(player) then
  129.             privatesay(player, svcmd(string.sub(message, 2), player) )
  130.         else
  131.             privatesay(player, "You're not allowed to do that!")
  132.         end
  133.     elseif string.sub(message, 1, 1) == "@" and privateChat then
  134.         C_Allow = false
  135.         local toPlayer = string.sub(gettoken(message, " ", 0), 2)
  136.         if toPlayer >= 0 and toPlayer <= 15 then
  137.             local C_Name = getname(player)
  138.             if toPlayer >= 0 and toPlayer <= 9 then
  139.                 privatesay(toPlayer, C_Name .. " says: " .. string.sub(message, 3) )
  140.             else
  141.                 privatesay(toPlayer, C_Name .. " says: " .. string.sub(message, 4) )
  142.             end
  143.         else
  144.             privatesay(player, "Invalid player.")
  145.         end
  146.    
  147.     end
  148.     if useLog then
  149.         aLog("[Chat] " .. getname(player) .. ":" .. message)
  150.     end
  151.     return C_Allow
  152. end
  153.  
  154. function OnServerCommand(player, command)
  155.     if useLog then
  156.         if player == -1 then
  157.             aLog("[Command] Console: " .. command)
  158.         else
  159.             aLog("[Command] " .. getname(player) .. ": " .. command)
  160.         end
  161.     end
  162. end
  163.  
  164. function OnTeamDecision(cur_team)
  165.     return cur_team
  166. end
  167.  
  168. function OnPlayerJoin(player, team)
  169.     local name = getname(player)
  170.     if useLog then
  171.         aLog("[Info] " .. name .. " joined the game.")
  172.     end
  173.     local tag = string.sub(name, 1, tagLength)
  174.     if matchedTag(tag) then
  175.         local hash = gethash(player)
  176.         local inClan = false
  177.         for i=0, #member_list do
  178.             if member_list[i] == hash then
  179.                 inclan = true
  180.                 break
  181.             end
  182.         end
  183.         if inclan == false then
  184.             svcmd(impAction .. " " .. resolveplayer(player) )
  185.             if useLog then
  186.                 aLog("[Action] Imposter detected.  Using name: " .. name)
  187.             end
  188.         end
  189.     end
  190.     local player_hash = gethash(player)
  191.     if player_hash ~= nil then
  192.         if global_players[player_hash] == nil then
  193.             global_players[player_hash] = { hash=player_hash}
  194.         else
  195.             local player_struct = getplayer(player)
  196.             local score = nil
  197.             if global_gametype == 1 then -- CTF
  198.                 score = stat_read(player_hash, "ctf_score")
  199.                 if score ~= nil then
  200.                     writeword(player_struct, 0xC8, score)
  201.                 end
  202.             elseif global_gametype == 2 then -- Slayer
  203.                 score = stat_read(player_hash, "slayer_score")
  204.                 if score ~= nil then
  205.                     writedword(0x63A128, 0x4 * player, score)
  206.                 end
  207.             elseif global_gametype == 3 then -- Oddball
  208.                 score = stat_read(player_hash, "oddball_score")
  209.                 if score ~= nil then
  210.                     writedword(0x639E9C, 0x4 * player, score)
  211.                 end
  212.             elseif global_gametype == 4 then -- KOTH
  213.                 score = stat_read(player_hash, "koth_score")
  214.                 if score ~= nil then
  215.                     writeword(player_struct, 0x0C4, score)
  216.                 end
  217.             elseif global_gametype == 5 then -- Race
  218.                 score = stat_read(player_hash, "race_score")
  219.                 if score ~= nil then
  220.                     writeword(player_struct, 0xC6, score)
  221.                 end
  222.             end
  223.             local kills = stat_read(player_hash, "kills")
  224.             if kills ~= nil then
  225.                 writeword(player_struct, 0x9C, kills)
  226.             end
  227.             local assists = stat_read(player_hash, "assists")
  228.             if assits ~= nil then
  229.                 writeword(player_struct, 0xA4, assists)
  230.             end
  231.             local deaths = stat_read(player_hash, "deaths")
  232.             if deaths ~= nil then
  233.                 writeword(player_struct, 0xAE, deaths)
  234.             end
  235.             privatesay(player, "Your scores have been resumed.")
  236.         end
  237.         if welcomeMessage ~= nil then
  238.             privatesay(player, welcomeMessage)
  239.         end
  240.     end
  241. end
  242.  
  243. function OnPlayerLeave(player, team)
  244.     local player_hash = gethash(player)
  245.     if global_players[player_hash] ~= nil then
  246.         local player_struct = getplayer(player)
  247.         if global_gametype == 1 then -- CTF
  248.             stat_write(player_hash, "ctf_score", readword(player_struct, 0xC8) )
  249.         elseif global_gametype == 2 then -- Slayer
  250.             stat_write(player_hash, "slayer_score", readdwordsigned(0x63A128, 0x4 * player) )
  251.         elseif global_gametype == 3 then -- Oddball
  252.             stat_write(player_hash, "oddball_score", readdword(0x639E9C, 0x4 * player) )
  253.         elseif global_gametype == 4 then -- KOTH
  254.             stat_write(player_hash, "koth_score", readword(player_struct, 0xC4) )
  255.         elseif global_gametype == 5 then -- Race
  256.             stat_write(player_hash, "race_score", readword(player_struct, 0xC6) )
  257.         end
  258.         local player_kills = readword(player_struct, 0x9C)
  259.         stat_write(player_hash, "kills", player_kills)
  260.         local player_assists = readword(player_struct, 0xA4)
  261.         stat_write(player_hash, "assists", player_assists)
  262.         local player_deaths = readword(player_struct, 0xAE)
  263.         stat_write(player_hash, "deaths", player_deaths)
  264.     end
  265.     if useLog then
  266.         aLog("[Info] " .. getname(player) .. " left the game.")
  267.     end
  268. end
  269.  
  270. function OnPlayerKill(killer, victim, mode)
  271. end
  272.  
  273. function OnKillMultiplier(player, multiplier)
  274. end
  275.  
  276. function OnPlayerSpawn(player, m_objectId)
  277. end
  278.  
  279. function OnPlayerSpawnEnd(player, m_objectId)
  280. end
  281.  
  282. function OnTeamChange(relevant, player, team, dest_team)
  283.     return 1
  284. end
  285.  
  286. function OnClientUpdate(player, m_objectId)
  287. end
  288.  
  289. function OnObjectInteraction(player, m_ObjectId, tagType, tagName)
  290.     return 1
  291. end
  292.  
  293. function OnWeaponReload(player, weapon)
  294.     return 1
  295. end
  296.  
  297. function OnVehicleEntry(relevant, player, vehicleId, vehicle_tag, seat)
  298.     return 1
  299. end
  300.  
  301. function OnVehicleEject(player, forceEject)
  302.     return 1
  303. end
  304.  
  305. function OnDamageLookup(receiving_obj, causing_obj, tagdata, tagname)
  306. end
  307.  
  308. function OnWeaponAssignment(player, object, count, tag)
  309. end
  310.  
  311. function OnObjectCreation(m_objectId, player_owner, tag)
  312. end
  313.  
  314. -- Misc Functions
  315.  
  316. function rows (connection, sql_statement)
  317.     local cursor = assert (connection:execute (sql_statement))
  318.     return function ()
  319.         return cursor:fetch()
  320.     end
  321. end
  322.  
  323. function stat_read(hash, stat)
  324.     local value = nil
  325.     if global_players[hash] ~= nil then
  326.         if global_players[hash][stat] ~= nil then
  327.             value = global_players[hash][stat]
  328.         else
  329.             global_players[hash][stat] = 0
  330.             value = 0
  331.         end
  332.     end
  333.     return value
  334. end
  335.  
  336. function stat_write(hash, stat, value)
  337.     if global_players[hash] ~= nil then
  338.         if global_players[hash][stat] ~= nil then
  339.             global_players[hash][stat] = value
  340.         else
  341.             global_players[hash][stat] = value
  342.         end
  343.     end
  344. end
  345.  
  346. function stat_add(hash, stat, value)
  347.     if global_players[hash] ~= nil then
  348.         if global_players[hash][stat] ~= nil then
  349.             global_players[hash][stat] = global_players[hash][stat] + value
  350.         else
  351.             global_players[hash][stat] = value
  352.         end
  353.     end
  354. end
  355.  
  356. function isDatabaseAdmin(player)
  357.     local pass = false
  358.     local hash = gethash(player)
  359.     for i=0, #adminTable do
  360.         if hash == adminTable[i] then
  361.             pass = true
  362.             break
  363.         end
  364.     end
  365.     return pass
  366. end
  367.  
  368. function aLog(message)
  369.     local file = io.open(logFile, "a")
  370.     if file ~= nil then
  371.         file:write(message .. "\n")
  372.     end
  373.     file:close()
  374. end
  375.  
  376. function matchedTag(tag)
  377.     local matched = false
  378.     for i=0, #clanTags do
  379.         if tag == clanTags[i] then
  380.             matched = true
  381.             break
  382.         end
  383.     end
  384.     return matched
  385. end