General > Developers Corner

Lua Help

(1/4) > >>

Major_Pain:
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: ---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)
--- End code ---

I put the "Oh hai thar admin" thing for testing purposes.

jay209015:

--- Code: ---local function Spawn
--- End code ---
should be:


--- Code: ---local function Spawn()
--- End code ---

Major_Pain:
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.

jay209015:

--- Code: ---if ply:isAdmin or ply:isSuperAdmin then
--- End code ---
needs to be:

--- Code: ---if ply:IsAdmin() then
--- End code ---

IsSuperadmin() is not needed, since they are a part of IsAdmin() already.

Major_Pain:
Updated Code:

--- Code: ---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)
--- End code ---

Testing now.

Edit: Still doesn't work and it says this in chat: "Welcome to 61100st! We're playing"

Navigation

[0] Message Index

[#] Next page

Go to full version