Author Topic: Lua Help  (Read 8355 times)

0 Members and 1 Guest are viewing this topic.

Offline Major_Pain

  • Newbie
  • *
  • Posts: 23
  • Karma: 1
Re: Lua Help
« Reply #15 on: September 03, 2009, 04:32:00 PM »
Ok! After a lot of testing and a lot of help from jay, I got the script finished. The spawn menu thing is a clientside hook so I took it out of the server script and made a clientside script for that.

Server:
Code: [Select]
AddCSLuaFile("autorun/client/MingeSpawnMenu.lua")

local totalProps = {}

local function PropLimit( ply )
totalProps[ply] = ply:GetCount("props")
if ply:IsUserGroup("minge") then
ply:PrintMessage( HUD_PRINTTALK, "You have hit your prop limit of 0!" )
return false
end
if ply:IsUserGroup("user") then
if totalProps[ply]>=30 then
ply:PrintMessage( HUD_PRINTTALK, "You have hit your prop limit of 30!" )
return false
end
end
if ply:IsUserGroup("starter") then
if totalProps[ply]>=50 then
ply:PrintMessage( HUD_PRINTTALK, "You have hit your prop limit of 50!" )
return false
end
end
if ply:IsUserGroup("regular") then
if totalProps[ply]>=70 then
ply:PrintMessage( HUD_PRINTTALK, "You have hit your prop limit of 70!" )
return false
end
end
if ply:IsUserGroup("members") then
if totalProps[ply]>=100 then
ply:PrintMessage( HUD_PRINTTALK, "You have hit your prop limit of 100!" )
return false
end
end
if ply:IsUserGroup("gettingthere") then
if totalProps[ply]>=125 then
ply:PrintMessage( HUD_PRINTTALK, "You have hit your prop limit of 125!" )
return false
end
end
if ply:IsUserGroup("there") then
if totalProps[ply]>=150 then
ply:PrintMessage( HUD_PRINTTALK, "You have hit your prop limit of 150!" )
return false
end
end
if ply:IsUserGroup("cavedweller") then
if totalProps[ply]>=175 then
ply:PrintMessage( HUD_PRINTTALK, "You have hit your prop limit of 175!" )
return false
end
end
if ply:IsUserGroup("nolife") then
if totalProps[ply]>=200 then
ply:PrintMessage( HUD_PRINTTALK, "You have hit your prop limit of 200!" )
return false
end
end
if ply:IsUserGroup("moderator") then
if totalProps[ply]>=300 then
ply:PrintMessage( HUD_PRINTTALK, "You have hit your prop limit of 300!" )
return false
end
end
end

hook.Add( "PlayerSpawnProp", "blockProps", PropLimit)

Client:
Code: [Select]
AddCSLuaFile("autorun/client/MingeSpawnMenu.lua")

local function CantOpen ()
if LocalPlayer():IsUserGroup("minge") then
LocalPlayer():PrintMessage( HUD_PRINTTALK, "Silly minge! Props are for players!" )
return false
end
end

hook.Add( "OnSpawnMenuOpen", "OpenMenu", CantOpen)


Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Lua Help
« Reply #16 on: September 03, 2009, 08:49:34 PM »
Your 'order' of group tests may be contributing to problems.
Using the normal release version of ULib, anyone in a group other than user is ALSO a 'user'.
Then, depending on how you have inheritence set up, if you do, other groups may be included in ones higher, if you inherited them.
If you're using the latest SVNs...that may not be true anymore.
So, example
If regular inherits smarter inherits user inherits minge.
The following are true;
1) All 4 groups are 'user'
2) IsUserGroup minge will be true for smarter
3) IsUsergroup smarterwill be true for smarter, regular and minge
.... hopefully you get the point.
This is one reason why we're changing the ULib so that true won't always be returned.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Lua Help
« Reply #17 on: September 04, 2009, 05:08:11 AM »
He's running the latest svn version :D
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline Major_Pain

  • Newbie
  • *
  • Posts: 23
  • Karma: 1
Re: Lua Help
« Reply #18 on: September 11, 2009, 06:25:04 PM »
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:
Code: [Select]
--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:
Code: [Select]
ERROR: Hook 'onDeath' Failed: autorun/server/AutoPromote2_2.lua:61: attempt to compare string with number
Removing Hook 'onDeath'

This is line 61:
Code: [Select]
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.
« Last Edit: September 11, 2009, 06:31:35 PM by Major_Pain »