Ok! If you have read the AutoPromote thread, I promised I would remake it. I have been struggling with this thing for a week now.
Here is my code:
--Format is { ["hours"] = "group" }
--If you aren't using a group, put nil!! Ex: "A9 = nil"
A1 = { ["1"] = "starter" }
A2 = { ["2"] = "regular" }
A3 = { ["3"] = "members" }
A4 = { ["4"] = "gettingthere" }
A5 = { ["5"] = "there" }
A6 = { ["6"] = "cavedweller" }
A7 = { ["7"] = "nolife" }
A8 = nil
A9 = nil
A10 = nil
--Exclusion groups go here
B1 = "minge"
B2 = "owner"
B3 = "admin"
B4 = "superadmin"
B5 = "moderator"
B6 = nil
B7 = nil
B8 = nil
B9 = nil
B10 = nil
---Don't edit below this line unless you know what you are doing!---
function excludedCheck( ply )
local exclude = false
if ply:IsUserGroup(B1) or ply:IsUserGroup(B2) or ply:IsUserGroup(B3) or ply:IsUserGroup(B4) or ply:IsUserGroup(B5) or ply:IsUserGroup(B6) or ply:IsUserGroup(B7) or ply:IsUserGroup(B8) or ply:IsUserGroup(B9) or ply:IsUserGroup(B10) then
exclude = true
end
return exclude
end
function groupSet( ply )
local hours = math.floor((ply:GetUTime() + CurTime() - ply:GetUTimeStart())/60/60)
if A10 then
for k1,v1 in pairs(A10) do
if hours>=k1 then groupAP = v1
return true
end
end
end
if A9 then
for k2,v2 in pairs(A9) do
if hours>=k2 then groupAP = v2
return true
end
end
end
if A8 then
for k3,v3 in pairs(A8) do
if hours>=k3 then groupAP = v3
return true
end
end
end
if A7 then
for k4,v4 in pairs(A7) do
if hours>=k4 then groupAP = v4
return true
end
end
end
if A6 then
for k5,v5 in pairs(A6) do
if hours>=k5 then groupAP = v5
return true
end
end
end
if A5 then
for k6,v6 in pairs(A5) do
if hours>=k6 then groupAP = v6
return true
end
end
end
if A4 then
for k7,v7 in pairs(A4) do
if hours>=k7 then groupAP = v7
return true
end
end
end
if A3 then
for k8,v8 in pairs(A3) do
if hours>=k8 then groupAP = v8
return true
end
end
end
if A2 then
for k9,v9 in pairs(A2) do
if hours>=k9 then groupAP = v9
return true
end
end
end
if A1 then
for k10,v10 in pairs(A1) do
if hours>=k10 then groupAP = v10
return true
end
end
end
return false
end
function promotePlayer( ply )
if not excludedCheck( ply ) then
if groupSet( ply ) then
game.ConsoleCommand("ulx adduser "..string.format("%q", ply:Nick() ).." "..string.format("%q", groupAP).." \n")
end
end
end
hook.Add( "PlayerDeath", "onDeath", promotePlayer)
I am going to convert the exclude groups and stuff at the top into tables but I wanted to get it working first. I have rewrote this code at least 3-4 times. When I go to test it, I kill my self and it gives me an error in the server console:
ERROR: Hook 'onDeath' Failed: autorun/server/AutoPromote2_2.lua:61: attempt to compare string with number
Removing Hook 'onDeath'
This is line 61:
if hours>=k4 then groupAP = v4
I can't figure this out. Help please.
EDIT: I figured it out right after. The quotes in the A1-A10 are making the number a string. I changed it to just A1=[1] instead of A1=["1"] and now it works perfectly! I am going to go post this in the auto promote thread.