ULX

Author Topic: Lua Help  (Read 8923 times)

0 Members and 3 Guests are viewing this topic.

Offline Major_Pain

  • Newbie
  • *
  • Posts: 23
  • Karma: 1
Lua Help
« on: August 31, 2009, 03:17:30 PM »
I am trying to make a script that gives guns to certain groups. I have been learning a little bit of lua from jay but I seem to be stumped on this one. Help is greatly appreciated.

Code: [Select]
local function StartingGuns( ply )
ply:StripWeapons()
ply:Give( "weapon_physcannon" )
ply:Give( "weapon_physgun" )
ply:Give( "gmod_tool" )
ply:Give( "gmod_camera" )
if ply:IsUserGroup("admin") then
ply:Give( "weapon_punisher" )
ply:Give( "ulx_gun" )
end
if ply:IsUserGroup("superadmin") then
ply:Give( "weapon_punisher" )
ply:Give( "ulx_gun" )
ply:Give( "weapon_ar2" )
end
if ply:IsUserGroup("owner") then
ply:Give( "weapon_punisher" )
ply:Give( "ulx_gun" )
ply:Give( "weapon_haxgun" )
ply:Give( "weapon_ar2")
end
end

hook.Add( "PlayerLoadout", "StartingGuns", StartingGuns)

local function FirstSpawn( ply )
if ply:isAdmin or ply:isSuperAdmin then
ply:PrintMessage( HUD_PRINTTALK, "Major Pain: Oh hai thar admin! Lolz" )
end
end

hood.Add( "PlayerInitialSpawn", "FirstSpawn", FirstSpawn)

local function Spawn
if ply:IsUserGroup("owner") then
ply:SetGravity( 0, 90 )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 1000 )
end
end

hook.Add( "PlayerSpawn", "PlayerSpawn", Spawn)

I put the "Oh hai thar admin" thing for testing purposes.
« Last Edit: August 31, 2009, 03:35:23 PM by Major_Pain »


Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Lua Help
« Reply #1 on: August 31, 2009, 03:18:57 PM »
Code: [Select]
local function Spawnshould be:

Code: [Select]
local function Spawn()
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 #2 on: August 31, 2009, 03:23:04 PM »
Lol, how silly of me. Thanks jay. I suppose I will leave this open for more lua questions in the future if that's alright. I'm only a beginner.  :)

EDIT: Tested and it still doesn't work.
« Last Edit: August 31, 2009, 03:28:57 PM by Major_Pain »


Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Lua Help
« Reply #3 on: August 31, 2009, 03:36:26 PM »
Code: [Select]
if ply:isAdmin or ply:isSuperAdmin thenneeds to be:
Code: [Select]
if ply:IsAdmin() then
IsSuperadmin() is not needed, since they are a part of IsAdmin() already.
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 #4 on: August 31, 2009, 03:38:08 PM »
Updated Code:
Code: [Select]
local function StartingGuns( ply )
ply:StripWeapons()
ply:Give( "weapon_physcannon" )
ply:Give( "weapon_physgun" )
ply:Give( "gmod_tool" )
ply:Give( "gmod_camera" )
if ply:IsUserGroup("admin") then
ply:Give( "weapon_punisher" )
ply:Give( "ulx_gun" )
end
if ply:IsUserGroup("superadmin") then
ply:Give( "weapon_punisher" )
ply:Give( "ulx_gun" )
ply:Give( "weapon_ar2" )
end
if ply:IsUserGroup("owner") then
ply:Give( "weapon_punisher" )
ply:Give( "ulx_gun" )
ply:Give( "weapon_haxgun" )
ply:Give( "weapon_ar2")
end
end

hook.Add( "PlayerLoadout", "StartingGuns", StartingGuns)

local function FirstSpawn( ply )
if ply:IsAdmin() then
ply:PrintMessage( HUD_PRINTTALK, "Major Pain: Oh hai thar admin! Lolz" )
end
end

hood.Add( "PlayerInitialSpawn", "FirstSpawn", FirstSpawn)

local function Spawn ( ply )
if ply:IsUserGroup("owner") then
ply:SetGravity( 0, 90 )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 1000 )
end
end

hook.Add( "PlayerSpawn", "PlayerSpawn", Spawn)

Testing now.

Edit: Still doesn't work and it says this in chat: "Welcome to 61100st! We're playing"
« Last Edit: August 31, 2009, 03:44:42 PM by Major_Pain »


Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Lua Help
« Reply #5 on: August 31, 2009, 03:47:21 PM »
Line 32:
Code: [Select]
hood.Add( "PlayerInitialSpawn", "FirstSpawn", FirstSpawn)I think you know what that should be :P
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 #6 on: August 31, 2009, 03:52:23 PM »
Line 32:
Code: [Select]
hood.Add( "PlayerInitialSpawn", "FirstSpawn", FirstSpawn)I think you know what that should be :P

Lol, fixed that and now the chat thing works but still doesn't strip my weapons and give me the new ones.

Updated Code:
Code: [Select]
local function StartingGuns( ply )
ply:StripWeapons()
ply:Give( "weapon_physcannon" )
ply:Give( "weapon_physgun" )
ply:Give( "gmod_tool" )
ply:Give( "gmod_camera" )
if ply:IsUserGroup("admin") then
ply:Give( "weapon_punisher" )
ply:Give( "ulx_gun" )
end
if ply:IsUserGroup("superadmin") then
ply:Give( "weapon_punisher" )
ply:Give( "ulx_gun" )
ply:Give( "weapon_ar2" )
end
if ply:IsUserGroup("owner") then
ply:Give( "weapon_punisher" )
ply:Give( "ulx_gun" )
ply:Give( "weapon_haxgun" )
ply:Give( "weapon_ar2")
end
end

hook.Add( "PlayerLoadout", "StartingGuns", StartingGuns)

local function FirstSpawn( ply )
if ply:IsAdmin() then
ply:PrintMessage( HUD_PRINTTALK, "Major Pain: Oh hai thar admin! Lolz" )
end
end

hook.Add( "PlayerInitialSpawn", "FirstSpawn", FirstSpawn)

local function Spawn ( ply )
if ply:IsUserGroup("owner") then
ply:SetGravity( 0, 90 )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 1000 )
end
end

hook.Add( "PlayerSpawn", "PlayerSpawn", Spawn)

EDIT: Tried to change PlayerLoadout to PlayerSpawn on the "StartingGuns" function and that didn't work either.
« Last Edit: August 31, 2009, 04:12:42 PM by Major_Pain »


Offline Major_Pain

  • Newbie
  • *
  • Posts: 23
  • Karma: 1
Re: Lua Help
« Reply #7 on: August 31, 2009, 04:43:58 PM »
Ok! So after a lot of fail on my part the wiki prevailed.

Now I have a new problem.
Thanks Jay!
« Last Edit: August 31, 2009, 06:10:09 PM by Major_Pain »


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 #8 on: August 31, 2009, 06:13:40 PM »
Using a dedicated server?
Those are server functions, so if you're only editing locally then joining your server, those functions won't run.

What errors are you getting, if they aren't working?
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Major_Pain

  • Newbie
  • *
  • Posts: 23
  • Karma: 1
Re: Lua Help
« Reply #9 on: August 31, 2009, 06:27:28 PM »
Using a dedicated server?
Those are server functions, so if you're only editing locally then joining your server, those functions won't run.

What errors are you getting, if they aren't working?

I was testing on my local machine by creating a lan server. I am using it for a legit server now thanks to jay's help off of the forums.


Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Lua Help
« Reply #10 on: August 31, 2009, 11:41:14 PM »
Edit: Still doesn't work and it says this in chat: "Welcome to 61100st! We're playing"

Random question, are you using or have you tested XGUI at all? I noticed my listen server saying that a while ago, I just hope it wasn't something I did  :o

EDIT: Never mind, I saw your post in the XGUI thread.. do you remember exactly when it started saying this?
« Last Edit: August 31, 2009, 11:43:23 PM by Stickly Man! »
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline Major_Pain

  • Newbie
  • *
  • Posts: 23
  • Karma: 1
Re: Lua Help
« Reply #11 on: September 01, 2009, 02:33:32 PM »
Random question, are you using or have you tested XGUI at all? I noticed my listen server saying that a while ago, I just hope it wasn't something I did  :o

EDIT: Never mind, I saw your post in the XGUI thread.. do you remember exactly when it started saying this?

After I fixed a hook breaking.


Offline Major_Pain

  • Newbie
  • *
  • Posts: 23
  • Karma: 1
Re: Lua Help
« Reply #12 on: September 02, 2009, 08:50:04 PM »
Okay! I have started a new script that sets prop limit per user group. All I need to know is how to figure out a person's prop count. I tried doing ply:GetCount( "props" ). I wasn't successful.


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 #13 on: September 03, 2009, 02:57:44 PM »
Major Pain, see our UNoLimited script in releases.
Though not done by usergroup other than admin and superadmin (yet), it should give you a good basis to look in for at least the counting portions.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Major_Pain

  • Newbie
  • *
  • Posts: 23
  • Karma: 1
Re: Lua Help
« Reply #14 on: September 03, 2009, 03:04:20 PM »
Jay informed me that GetCount("props") is correct, so my script must be wrong somewhere. I am going to post it here:

Code: [Select]
local totalProps = {}

local function PropLimit( ply )
        totalProps[ply] = ply:GetCount("props")
if ply:IsUserGroup("minge") then
return false
end
if ply:IsUserGroup("user") then
if totalProps[ply]>30 then
return false
end
end
if ply:IsUserGroup("starter") then
if totalProps[ply]>50 then
return false
end
end
if ply:IsUserGroup("regular") then
if totalProps[ply]>70 then
return false
end
end
if ply:IsUserGroup("members") then
if totalProps[ply]>100 then
return false
end
end
if ply:IsUserGroup("gettingthere") then
if totalProps[ply]>125 then
return false
end
end
if ply:IsUserGroup("there") then
if totalProps[ply]>150 then
return false
end
end
if ply:IsUserGroup("cavedweller") then
if totalProps[ply]>175 then
return false
end
end
if ply:IsUserGroup("nolife") then
if totalProps[ply]>200 then
return false
end
end
if ply:IsUserGroup("moderator") then
if totalProps[ply]>300 then
return false
end
end
end

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

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

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

I'll go take a look at the UNoLimited.
« Last Edit: September 03, 2009, 03:20:42 PM by Major_Pain »