Advertisement
Guest User

Untitled

a guest
May 26th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. hpconfig = {}
  2. hpconfig.allowed = {TEAM_DUMBLEDORE, TEAM_SLUG, TEAM_SPROUT, TEAM_FLITWICK,TEAM_LUPIN, TEAM_BINNS, TEAM_MCGONAL, TEAM_SNAPE, TEAM_WEASELY, TEAM_HAGRID, TEAM_QUIDITCH} -- What teams can open the menu?
  3. hpconfig.gryffindor = {TEAM_GRYFFINDOR} -- gryffindor team
  4. hpconfig.hufflepuff = {TEAM_HUFFLEPUFF} -- hufflepuff team
  5. hpconfig.ravenclaw = {TEAM_RAVENCLAW} -- ravenclaw team
  6. hpconfig.slytherin = {TEAM_SLYTHERIN} -- slytherin team
  7.  
  8. util.AddNetworkString( "openPointsMenu" )
  9. util.AddNetworkString( "pointsMath" )
  10.  
  11. local function pointsMenu(ply, args) -- tells the caller of the chat command to open the points menu, will only open if their team is in the config
  12. if table.HasValue(hpconfig.allowed, ply:Team()) then
  13. net.Start("openPointsMenu")
  14. net.Send(ply)
  15. return ""
  16. end
  17. end
  18.  
  19. local function savePoints() -- saves the points when the server stops or shutsdown
  20. file.Write( "ge_points.txt", GetGlobalInt("ge_points") )
  21. file.Write( "se_points.txt", GetGlobalInt("se_points") )
  22. file.Write( "re_points.txt", GetGlobalInt("re_points") )
  23. file.Write( "he_points.txt", GetGlobalInt("he_points") )
  24. print("house points saved!")
  25. end
  26.  
  27. local function setPointsInit() -- gets the saved point values and sets them when the server starts
  28. local ge_val = tonumber(file.Read( "ge_points.txt" ), 10)
  29. local se_val = tonumber(file.Read( "se_points.txt" ), 10)
  30. local re_val = tonumber(file.Read( "re_points.txt" ), 10)
  31. local he_val = tonumber(file.Read( "he_points.txt" ), 10)
  32. SetGlobalInt("ge_points", ge_val)
  33. SetGlobalInt("se_points", se_val)
  34. SetGlobalInt("re_points", re_val)
  35. SetGlobalInt("he_points", he_val)
  36. print("house points set!")
  37. end
  38.  
  39. local function pointsMath( len, ply ) -- function that does all the math for the points
  40. local pointsa = net.ReadInt(16)
  41. local house = net.ReadString()
  42. if table.HasValue(hpconfig.allowed, ply:Team()) or ply:IsAdmin() then
  43. if GetGlobalInt(house) + pointsa < 0 then
  44. SetGlobalInt(house, 0)
  45. else
  46. SetGlobalInt(house, GetGlobalInt(house) + pointsa)
  47. end
  48. end
  49. if pointsa < 0 then
  50. for k,v in pairs(player.GetAll()) do
  51. if v != ply then
  52. if house == "ge_points" then
  53. DarkRP.notify(v, 1, 4, ply:Name() .. " took " .. pointsa*-1 .. " points from " .. "Gryffindor")
  54. elseif house == "se_points" then
  55. DarkRP.notify(v, 1, 4, ply:Name() .. " took " .. pointsa*-1 .. " points from " .. "Slytherin")
  56. elseif house == "re_points" then
  57. DarkRP.notify(v, 1, 4, ply:Name() .. " took " .. pointsa*-1 .. " points from " .. "Ravenclaw")
  58. elseif house == "he_points" then
  59. DarkRP.notify(v, 1, 4, ply:Name() .. " took " .. pointsa*-1 .. " points from " .. "Hufflepuff")
  60. end
  61. end
  62. end
  63. elseif pointsa >= 0 then
  64. for k,v in pairs(player.GetAll()) do
  65. if v != ply then
  66. if house == "ge_points" then
  67. DarkRP.notify(v, 1, 4, ply:Name() .. " gave " .. pointsa .. " points to " .. "Gryffindor")
  68. elseif house == "se_points" then
  69. DarkRP.notify(v, 1, 4, ply:Name() .. " gave " .. pointsa .. " points to " .. "Slytherin")
  70. elseif house == "re_points" then
  71. DarkRP.notify(v, 1, 4, ply:Name() .. " gave " .. pointsa .. " points to " .. "Ravenclaw")
  72. elseif house == "he_points" then
  73. DarkRP.notify(v, 1, 4, ply:Name() .. " gave " .. pointsa .. " points to " .. "Hufflepuff")
  74. end
  75. end
  76. end
  77. end
  78. end
  79.  
  80. concommand.Add("check2", function() -- debug command for checking values
  81. print(GetGlobalInt("ge_points"))
  82. print(GetGlobalInt("se_points"))
  83. print(GetGlobalInt("he_points"))
  84. print(GetGlobalInt("re_points"))
  85. end)
  86.  
  87. concommand.Add("resethppoints", function( ply, cmd, args ) -- 4 different args g, r, h, s
  88. if ply:IsAdmin() then
  89. if args[1] == "g" then
  90. SetGlobalInt("ge_points",0)
  91. elseif args[1] == "r" then
  92. SetGlobalInt("re_points",0)
  93. elseif args[1] == "h" then
  94. SetGlobalInt("he_points",0)
  95. elseif args[1] == "s" then
  96. SetGlobalInt("se_points",0)
  97. end
  98. end
  99. end)
  100.  
  101. net.Receive( "pointsMath", pointsMath )
  102. hook.Add("Initialize", "setPointsInit", setPointsInit)
  103. hook.Add("ShutDown", "save_points", savePoints)
  104. DarkRP.defineChatCommand("pointsmenu", pointsMenu)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement