• Help with concommand.Add (AKA LUA Being a pain)
    8 replies, posted
Hello, I'm here needing help with some code for init.lua so that it will work for once. The problem is that it's being a pain again, and that it keeps saying some bull crap about trying to index concommand as a global value, probably another bullshit syntax error, but here's the code. I hope someone knows the problem. [code] AddCSLuaFile("shared.lua") AddCSLuaFile("cl_init.lua") include('shared.lua') function GM:PlayerSpawn(ply) ply:StripWeapons() ply:Give("fists") ply:Give("weapon_physgun") ply:Give("weapon_physcannon") end function GM:ShowHelp() ply:ConCommand("villageStart") end function foundVillage(ply) local play=ply local playEye=Player:GetEyeTraceNoCursor() villageCenter=ents.Create("town_center") villageCenter:SetPos(playEye.HitPos) villageCenter:SetOwner(play) villageCenter:Spawn() end function onUse(ply,entity) usedClass=entity:GetClass() if(usedClass=="npc_citizen") then owner=entity:GetOwner() if(owner==ply) then ply:SetVar("talkingTo",entity) RunConsoleCommand("drawTalk") return false end else ply:ChatPrint("You don't know him...") end end function testSpawn(ply) if(ply:IsAdmin()) then playEye=Player:GetEyeTraceNoCursor() testNPC=ents.Create("npc_citizen") testNPC:SetPos(playEye.HitPos) testNPC:SetOwner(ply) testNPC:Spawn() end end concommmand.Add("Test",testSpawn) [/code]
[lua]AddCSLuaFile("shared.lua") AddCSLuaFile("cl_init.lua") include('shared.lua') function GM:PlayerSpawn(ply) ply:StripWeapons() ply:Give("fists") ply:Give("weapon_physgun") ply:Give("weapon_physcannon") end function GM:ShowHelp(ply) ply:ConCommand("villageStart") end function foundVillage(ply) local play=ply local playEye=ply:GetEyeTraceNoCursor() villageCenter=ents.Create("town_center") villageCenter:SetPos(playEye.HitPos) villageCenter:SetOwner(play) villageCenter:Spawn() end function onUse(ply,entity) usedClass=entity:GetClass() if(usedClass=="npc_citizen") then owner=entity:GetOwner() if(owner==ply) then ply:SetVar("talkingTo",entity) RunConsoleCommand("drawTalk") return false end else ply:ChatPrint("You don't know him...") end end function testSpawn(ply) if(ply:IsAdmin()) then local playEye=ply:GetEyeTraceNoCursor() testNPC=ents.Create("npc_citizen") testNPC:SetPos(playEye.HitPos) testNPC:SetOwner(ply) testNPC:Spawn() end end concommmand.Add("Test",testSpawn) [/lua] You had a few nil variables, and forgot to pass a parameter or two.
GM:ShowHelp takes ply as an argument, else your ply:ConCommand("villageStart") will fail. There are some more errors like Player.GetEyeTraceNoCursor which should be either ply.GetEyeTraceNoCursor or play.GetEyeTraceNoCursor EDIT: FlapJack :argh:
[QUOTE=_nonSENSE;24166384]GM:ShowHelp takes ply as an argument, else your ply:ConCommand("villageStart") will fail. There are some more errors like Player.GetEyeTraceNoCursor which should be either ply.GetEyeTraceNoCursor or play.GetEyeTraceNoCursor EDIT: FlapJack :argh:[/QUOTE] You were more specific, thanks. And the other character too. But still why isn't it working?
When you declare a new function and expect it to run automatically at some point, you need to hook it. Like this: [lua] function onUse(ply,entity) usedClass=entity:GetClass() if(usedClass=="npc_citizen") then owner=entity:GetOwner() if(owner==ply) then ply:SetVar("talkingTo",entity) RunConsoleCommand("drawTalk") return false end else ply:ChatPrint("You don't know him...") end end hook.Add( "PlayerUse", "MyOnUse", onUse)[/lua] (sorry for the crappy indentation, I am typing this in the browser) A list of gamemode hooks can be found [URL="http://wiki.garrysmod.com/?title=Gamemode_Hooks"][B]here[/B][/URL].
[QUOTE=_nonSENSE;24166613]When you declare a new function and expect it to run automatically at some point, you need to hook it. Like this: [lua] function onUse(ply,entity) usedClass=entity:GetClass() if(usedClass=="npc_citizen") then owner=entity:GetOwner() if(owner==ply) then ply:SetVar("talkingTo",entity) RunConsoleCommand("drawTalk") return false end else ply:ChatPrint("You don't know him...") end end hook.Add( "PlayerUse", "MyOnUse", onUse)[/lua] (sorry for the crappy indentation, I am typing this in the browser) A list of gamemode hooks can be found [URL="http://wiki.garrysmod.com/?title=Gamemode_Hooks"][B]here[/B][/URL].[/QUOTE] I'm aware of that, and thanks for baring with me, but how do I get the concommand thing working?
Check for any errors in the function that the command is calling, the command can be invalid if the function it is calling creates errors. I'm on my iPhone so I can't see the full block of code you posted.
just to be an ass : Lua isn't an acronyme and isn't said LUA , or lua . Just Lua :)
[QUOTE=TheMagician;24181721]just to be an ass : Lua isn't an acronyme and isn't said LUA , or lua . Just Lua :)[/QUOTE] Doesn't make much difference. This board is called "LUA Scripting" which is where people get it from.
Sorry, you need to Log In to post a reply to this thread.