Hey all, I've decided to slowly but surely work my way into trying to learn LUA or more importantly GLUA. First things first, i've run a snag. I attempted to code along with online sources and others(CGHIPPO + FACEPUNCH THREADS)
[CODE]
AddCSLuaFile()
concommand.Add( "b", function( ply, cmd, argms )
ply:GodEnable()
print(" Godmode : ON")
if ply:HasGodMode() then ply:GodDisable()
print(" Godmode : OFF")
end
end)
hook.Add( "PlayerSay", "Chatcmd", function(ply, text, pblc)
if string.lower(text) == "!b" then
concommand.Run(ply,"b")
end
end)
[/CODE]
But i get no errors in console about the code so i am thinking the code doesn't load so my next issue is whats the basic .lua placement for a file like this?
Do i do autorun/godmode.lua??
Or do i do addons/godmode/lua/shared.lua?
Second option, about making a folder in addons.
Also, your command won't work, regardless. It will enable godmode and then immediately disable it.
Use this
[code]
concommand.Add( "b", function( ply, cmd, argms )
if ply:HasGodMode() then
ply:GodDisable()
print(" Godmode: OFF")
else
ply:GodEnable()
print(" Godmode: ON")
end
end)
[/code]
[QUOTE=Z0mb1n3;48769853]Second option, about making a folder in addons.
Also, your command won't work, regardless. It will enable godmode and then immediately disable it.
Use this
[code]
concommand.Add( "b", function( ply, cmd, argms )
if ply:HasGodMode() then
ply:GodDisable()
print(" Godmode: OFF")
else
ply:GodEnable()
print(" Godmode: ON")
end
end)
[/code][/QUOTE]
Ah okay! That makes sense rather than having "skips" in the coding when it should all really be strung together. Let me try it out and see if it works!
Unrelated note: How come for GodDisable and GodEnable you don't have to say If SERVER then??
[editline]26th September 2015[/editline]
Interesting. I don't think i have godmode setup correctly. I get this error?
[CODE]
[ERROR] lua/autorun/godmode.lua:2: attempt to call method 'GodEnable' (a nil value)
1. unknown - lua/autorun/godmode.lua:2
2. unknown - lua/includes/modules/concommand.lua:54
[/CODE]
You need if SERVER then
[QUOTE=Kalamitous;48770015]You need if SERVER then[/QUOTE]
Im slowly working through it and i still get the error using this.
[code]
if SERVER then
concommand.Add( "b", function( ply, cmd, argms )
if ply:HasGodMode() then
ply:GodDisable()
print(" Godmode: OFF")
else
ply:GodEnable()
print(" Godmode: ON")
end
end)
end
[/code]
Do i need to runconsolecommand on client for it to not get that same error?
The concommand you want has to be run serverside. You can do that two ways.
Either having the single lua file being in lua/autorun, with the template
[CODE]
if SERVER then
AddCSLuaFile()
--stuff here
end
[/CODE]
Or, since it's only a server-side command, you can just place the file in lua/autorun/server so that you don't need to include the stuff above.
Both ways would allow the client to use the console command.
You only want to have the con command clientside if you're running an operation clientside or want to get info that's only clientsided.
[QUOTE=DeathWard;48770430]The concommand you want has to be run serverside. You can do that two ways.
Either having the single lua file being in lua/autorun, with the template
[CODE]
if SERVER then
AddCSLuaFile()
--stuff here
end
[/CODE]
Or, since it's only a server-side command, you can just place the file in lua/autorun/server so that you don't need to include the stuff above.
Both ways would allow the client to use the console command.
You only want to have the con command clientside if you're running an operation clientside or want to get info that's only clientsided.[/QUOTE]
Hey DeathWard, I put this code below into both addons/godmode/lua/autorun/server and into lua/server/autorun/server and it says unknown command g when i type g into console and nothing happens when i type "!g" so i think it isn't even being loaded.
[code]
AddCSLuaFile()
ply = LocalPlayer()
concommand.Add( "g", function( ply, cmd, argms )
if ply:HasGodMode() then
ply:GodDisable()
print("Godmode: OFF")
else
ply:GodEnable()
print("Godmode: ON")
end
end)
hook.Add( "PlayerSay", "Chatcmd", function(ply, text, pblc)
if string.lower(text) == "!g" then
concommand.Run(ply,"g")
end
end)
[/code]
[QUOTE=Keosan;48769902]Ah okay! That makes sense rather than having "skips" in the coding when it should all really be strung together. Let me try it out and see if it works!
Unrelated note: How come for GodDisable and GodEnable you don't have to say If SERVER then??
[editline]26th September 2015[/editline]
Interesting. I don't think i have godmode setup correctly. I get this error?
[CODE]
[ERROR] lua/autorun/godmode.lua:2: attempt to call method 'GodEnable' (a nil value)
1. unknown - lua/autorun/godmode.lua:2
2. unknown - lua/includes/modules/concommand.lua:54
[/CODE][/QUOTE]
I am having problems with GodEnable and GodDisable also. GodEnabled has no error but just doesn't work, and GodDisable produces an error. Will update with the info.
[editline]27th September 2015[/editline]
Okay, this is what I have.
[CODE]TEAM_ADMIN = DarkRP.createJob("Administration", {
color = Color(41, 41, 41, 255),
model = "models/player/mnu_soldier.mdl",
description = [[You are administration, you cannot RP, you must help people with administrative situations.]],
weapons = {},
command = "admin",
max = 10,
salary = 0,
admin = 0,
vote = false,
hasLicense = false,
PlayerSpawn = function(ply) ply:GodEnable() end,
PlayerDeath = function(ply) ply:GodDisable() end,
OnPlayerChangedTeam = function(ply) ply:GodDisable() end,
customCheck = function(ply) return
table.HasValue({"moderator", "owner", "superadmin", "admin"}, ply:GetNWString("usergroup")) or ply:IsAdmin() end,
CustomCheckFailMsg = "You must be a staff member.",
})[/CODE]
It gives me this. The GodEnable works.
[CODE][ERROR] addons/darkrpmodification/lua/darkrp_customthings/jobs.lua:147: attempt to call method 'GodDisable' (a nil value)
1. OnPlayerChangedTeam - addons/darkrpmodification/lua/darkrp_customthings/jobs.lua:147
2. Call - gamemodes/darkrp/gamemode/modules/base/sh_gamemode_functions.lua:18
3. Function - gamemodes/darkrp/gamemode/modules/base/cl_gamemode_functions.lua:62
4. unknown - lua/includes/modules/usermessage.lua:87[/CODE]
[editline]27th September 2015[/editline]
Nevermind, the GodEnable doesn't work. I had sv_godmode 1
[QUOTE=Sweepyoface;48770821]I am having problems with GodEnable and GodDisable also. GodEnabled has no error but just doesn't work, and GodDisable produces an error. Will update with the info.
[editline]27th September 2015[/editline]
Okay, this is what I have.
[CODE]TEAM_ADMIN = DarkRP.createJob("Administration", {
color = Color(41, 41, 41, 255),
model = "models/player/mnu_soldier.mdl",
description = [[You are administration, you cannot RP, you must help people with administrative situations.]],
weapons = {},
command = "admin",
max = 10,
salary = 0,
admin = 0,
vote = false,
hasLicense = false,
PlayerSpawn = function(ply) ply:GodEnable() end,
PlayerDeath = function(ply) ply:GodDisable() end,
OnPlayerChangedTeam = function(ply) ply:GodDisable() end,
customCheck = function(ply) return
table.HasValue({"moderator", "owner", "superadmin", "admin"}, ply:GetNWString("usergroup")) or ply:IsAdmin() end,
CustomCheckFailMsg = "You must be a staff member.",
})[/CODE]
It gives me this. The GodEnable works.
[CODE][ERROR] addons/darkrpmodification/lua/darkrp_customthings/jobs.lua:147: attempt to call method 'GodDisable' (a nil value)
1. OnPlayerChangedTeam - addons/darkrpmodification/lua/darkrp_customthings/jobs.lua:147
2. Call - gamemodes/darkrp/gamemode/modules/base/sh_gamemode_functions.lua:18
3. Function - gamemodes/darkrp/gamemode/modules/base/cl_gamemode_functions.lua:62
4. unknown - lua/includes/modules/usermessage.lua:87[/CODE]
[editline]27th September 2015[/editline]
Nevermind, the GodEnable doesn't work. I had sv_godmode 1[/QUOTE]
Ahhh I wonder whats wrong :/
Edit : [I]I think for now i'll just set player health to something incredibly high like 1 billion or something.[/I] JK. Anything over 6 figures crashes the client
[QUOTE=Keosan;48770589]Hey DeathWard, I put this code below into both addons/godmode/lua/autorun/server and into lua/server/autorun/server and it says unknown command g when i type g into console and nothing happens when i type "!g" so i think it isn't even being loaded.
[/QUOTE]
You don't need to define ply as a localplayer since the script is running on the server.
Same goes with AddCSLuaFile.
This works just fine, when placed in lua/autorun/server.
[CODE]
local function ToggleGodMode(ply)
if ply:HasGodMode() then
ply:GodDisable()
print("Godmode: OFF")
else
ply:GodEnable()
print("Godmode: ON")
end
end
concommand.Add("g", ToggleGodMode)
hook.Add( "PlayerSay", "Chatcmd", function(ply, text, pblc)
if string.lower(text) == "!g" then
ToggleGodMode(ply)
end
end)
[/CODE]
[QUOTE=DeathWard;48771421]You don't need to define ply as a localplayer since the script is running on the server.
Same goes with AddCSLuaFile.
This works just fine, when placed in lua/autorun/server.
[CODE]
local function ToggleGodMode(ply)
if ply:HasGodMode() then
ply:GodDisable()
print("Godmode: OFF")
else
ply:GodEnable()
print("Godmode: ON")
end
end
concommand.Add("g", ToggleGodMode)
hook.Add( "PlayerSay", "Chatcmd", function(ply, text, pblc)
if string.lower(text) == "!g" then
ToggleGodMode(ply)
end
end)
[/CODE][/QUOTE]
There's no need for the function to be that big for something so simple, you could just as easily to it like this:
[lua]
local function ToggleGodMode( ply )
print( string.format( "Godmode: %s", ply:HasGodMode() and "OFF" or "ON" ) )
return ply:HasGodMode() and ply:GodDisable() or ply:GodEnable()
end
[/lua]
Hey James and Deathward thanks for all the help! Sorry to everyone those as this felt like a spoonfeeding :/
[editline]27th September 2015[/editline]
[QUOTE=DeathWard;48771421]You don't need to define ply as a localplayer since the script is running on the server.
Same goes with AddCSLuaFile.
This works just fine, when placed in lua/autorun/server.
[CODE]
local function ToggleGodMode(ply)
if ply:HasGodMode() then
ply:GodDisable()
print("Godmode: OFF")
else
ply:GodEnable()
print("Godmode: ON")
end
end
concommand.Add("g", ToggleGodMode)
hook.Add( "PlayerSay", "Chatcmd", function(ply, text, pblc)
if string.lower(text) == "!g" then
ToggleGodMode(ply)
end
end)
[/CODE][/QUOTE]
[QUOTE=James xX;48771969]There's no need for the function to be that big for something so simple, you could just as easily to it like this:
[lua]
local function ToggleGodMode( ply )
print( string.format( "Godmode: %s", ply:HasGodMode() and "OFF" or "ON" ) )
return ply:HasGodMode() and ply:GodDisable() or ply:GodEnable()
end
[/lua][/QUOTE]
Using this code i get this same error
[code]
[ERROR] lua/autorun/godmode.lua:2: attempt to call method 'GodEnable' (a nil value)
1. unknown - lua/autorun/godmode.lua:2
2. unknown - lua/includes/modules/concommand.lua:54
[/code]
You are running the code from the client.
Stop running it from the client.
[B]Delete[/B] your file from the root directory of GMod inside of lua/autorun/godmode.lua
Make a new folder inside your addons folder.
Structure it as thus:
[code]
addons -- base addon folder
∟ godmode
∟ lua
∟ autorun
∟ server
∟ godmode.lua
[/code]
[QUOTE=Z0mb1n3;48773874]You are running the code from the client.
Stop running it from the client.
[B]Delete[/B] your file from the root directory of GMod inside of lua/autorun/godmode.lua
Make a new folder inside your addons folder.
Structure it as thus:
[code]
addons -- base addon folder
∟ godmode
∟ lua
∟ autorun
∟ server
∟ godmode.lua
[/code][/QUOTE]
YAYA it works now! Except for when i type !g in chat it doesn't enable/disable godmode.
Sorry, you need to Log In to post a reply to this thread.