• Problems using player.concommand ("ETC")
    11 replies, posted
Hello, I seem to be having trouble using the player.concommand( "" ) here is what it says: gamemodes\laststand\gamemode\init.lua:25: '=' expected near 'player'-init --player.concommand( "PlayerInitialGear" ) _______________ gamemodes\laststand\gamemode\cl_init.lua:21: 'then' expected near 'player' -cl_init --player.ConCommand( "sb_team1" ) ___________________________________________________________________________ Any idea what is wrong?
There's no such function as player.concommand or player.ConCommand.
[QUOTE=yakahughes;24627263]There's no such function as player.concommand or player.ConCommand.[/QUOTE] [url]http://wiki.garrysmod.com/?title=Player.ConCommand[/url] ? If not this how else should i run a console command?
You understood the wiki wrong. The Player. is refering to the player metatable. Its a object oriented function means this function can be used on any player. Its used like Player:ConCommand(string)
[QUOTE=Wizard of Ass;24627582]You understood the wiki wrong. The Player. is refering to the player metatable. Its a object oriented function means this function can be used on any player. Its used like Player:ConCommand(string)[/QUOTE] Im still getting the same warnings. I am using the same code, but with : instead of . What's wrong?
[lua]RunConsoleCommand("command", "arg1", "etc")[/lua]
[QUOTE=yakahughes;24628895][lua]RunConsoleCommand("command", "arg1", "etc")[/lua][/QUOTE] How would the arg affect it? Would it cause the errors? If so, how can I put in a value that won't conflict with a command such as this: function GM:PlayerLoadout( ply ) ply:Give( "weapon_crowbar" ) end concommand.add( "PlayerInitialGear", GM:PlayerLoadout ) I'm not using this function now, as it can be more easily done by the give command, but i have many more such as: function sb_team1( ply ) ply:UnSpectate() ply:SetTeam( 1 ) ply:Spawn() Unused ATM ply:PrintMessage( HUD_PRINTTALK, "[Ravenous Dead] Welcome," .. ply:Nick().. "can you survive the horde?" ) end concommand.Add( "sb_team1", sb_team1 )
RunConsoleCommand runs a console command, so if you wanted to do that player loadout thing, you would do [lua]RunConsoleCommand("PlayerInitialGear")[/lua] The additional arguments in my example just run the command with arguments. The one in my post would be as if you typed [code]command arg1 etc[/code] into the console.
[QUOTE=yakahughes;24630918]RunConsoleCommand runs a console command, so if you wanted to do that player loadout thing, you would do [lua]RunConsoleCommand("PlayerInitialGear")[/lua] The additional arguments in my example just run the command with arguments. The one in my post would be as if you typed [code]command arg1 etc[/code] into the console.[/QUOTE] Ah, well that solved my problem, so onto the next: The console keeps saying "Function argument expected at line 122 near the ')'" Heres the code: function GM:ZombieSpawn( tr ) local spawns = ents.FindByClass( "Zombie_Spawn_Point" ) local random = math.random(#spawns) local ent = ents.Create( "npc_zombie" ) ent:SetPos( tr.HitPos ) ent:Spawn() ent:Activate() end concommand.Add("ZombieSpawn", GM:ZombieSpawn) --- Line 122 timer.Create( "ZombieSpawnTimer1", 10, 0, function( ply ) player:concommand( "ZombieSpawn" ) player:concommand( "ZombieSpawn" ) player:concommand( "ZombieSpawn" ) player:concommand( "ZombieSpawn" ) player:concommand( "ZombieSpawn" ) player:concommand( "ZombieSpawn" ) end ) Any ideas?
concommand.Add("ZombieSpawn", GM:ZombieSpawn) the : can only be used when you're calling metafunctions. Changing it to GM.ZombieSpawn will make it work.
[QUOTE=yakahughes;24633259]concommand.Add("ZombieSpawn", GM:ZombieSpawn) the : can only be used when you're calling metafunctions. Changing it to GM.ZombieSpawn will make it work.[/QUOTE] This seems to work, thanks.
Sorry, you need to Log In to post a reply to this thread.