• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
[QUOTE=NiandraLades;46313934]I know how to create my own functions and have started using them more frequently, but how would I basically 'use' the player in them? Example: [code] function GM:CustomFunction(ply) ply:ChatPrint("test") end [/code][/QUOTE] don't use GM" I'm 90% that would override anything named CustomFunction, which is redundant because I don't think it exists. (call me out if im talking out of my ass) try something like [code] function CustomFunction(ply) ply:ChatPrint("test") end [/code] and to activate that function you would use [code] CustomFunction(Entity[1]) [/code] where Entity[1] can be any entity that is a player
Is there a specific reason why we are not allowed to change any of the default values for console commands on GM? Any changes made to commands that aren't referenced in the standard config.cfg will revert when you reboot the game. I'm guessing this is for security purposes, but I remember a while ago that I could change and save default values without a problem.
[QUOTE=SimplePlanz69;46314116]Is there a specific reason why we are not allowed to change any of the default values for console commands on GM? Any changes made to commands that aren't referenced in the standard config.cfg will revert when you reboot the game. I'm guessing this is for security purposes, but I remember a while ago that I could change and save default values without a problem.[/QUOTE] I think the change had something to do with the gmod cough virus.
[QUOTE=NiandraLades;46313934]I know how to create my own functions and have started using them more frequently, but how would I basically 'use' the player in them? Example: [code] function GM:CustomFunction(ply) ply:ChatPrint("test") end [/code][/QUOTE] Feel free to add me on Steam if you like as I do tutor when people ask. Anyway, functions are functions, you can add arguments to functions to do certain things.. If ... is used as an argument, it means ALL arguments go to that ( unless other args come before the ... or so, kind of like my MsgC function which used ( color, text, ... ) where it would recurse by simply running color and text in the normal MsgC function, then it would call itself but remove color and text from the call and just used ...; what this did was allow the next 2 arguments in ... to become color and text. Sort of like shifting arguments to the left until there are no more left. Example: [code]// Defining a function called test with 1 set-in-stone argument, and ... meaning unlimited args can be added function test( blah, ... ) // It prints blah print( blah ); // Then, if there are more arguments to be printed if ( #{ ... } > 0 ) then // call itself, but instead of calling test( blah, ... ) we just call test( ... ) which essentially shifts all arguments to the left ) test( ... ); end end // Calling it test( 1, 2, 3, 4, 5 ); // Output will be ( with each space representing a new line ): 1 2 3 4 5[/code] If we want to reverse the output: [code]// Defining a function called test with 1 set-in-stone argument, and ... meaning unlimited args can be added function test( blah, ... ) // Then, if there are more arguments to be printed if ( #{ ... } > 0 ) then // call itself, but instead of calling test( blah, ... ) we just call test( ... ) which essentially shifts all arguments to the left ) test( ... ); end // It prints blah print( blah ); end // Calling it test( 1, 2, 3, 4, 5 ); // Output will be ( with each space representing a new line ): 5 4 3 2 1[/code] simply by changing the order; if we recurse first then it loads deepest first ( or in this case farthest on the right first, then moves to the left )... This is how my auto-loader works, it loads files in the deepest folder first, then next deepest and so on. It can be reversed by changing the folder recursive call to after the file-loading loop. Now, for your player in a function... You can set up your functions to do anything you want. I'm not sure on your exact experience so I hope these examples aren't too unclear. Say for example that we want to write a new hook.. something to add functionality to the weapon system ( or other things thereof )... We can redirect a function and inject our code to add functionality without hindering anything else ( kind of like how I added an injection for a vgui panel for someone because there was no callback for when a collapsible category was toggled: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/dcollapsiblecategory_ontoggle_callback.lua.html[/url] ).. To go over the category one first, basically I loaded the existing panel into memory and added a few checks that would only ever be called once ( if !PANEL.__Toggle then PANEL.__Toggle = PANEL.Toggle... What this does is save a reference ( auto-refresh compatible to prevent stack overflows ) to the original function. I then re-define the Toggle function with my own which calls the original function by the reference we saved, then I called OnToggle ( the callback that was missing ) so the user could make something happen when a category collapsed or expanded. That example is a short and sweet introduction into redirects and saving references. Now, back to the other functionality which was also somewhat of a request... Basically there is no hook that gets called when a player drops their weapon, but there is a function which is called any time the weapon will be dropped in the player meta-table. Here is the logic bit: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_hooks/playerdroppedweapon/lua/autorun/server/sv_gm_playerdroppedweapon_logic.lua[/url] So basically I store a global reference ( locals would be overwritten and would cause a stack overflow ) to the original DropWeapon player-meta-table function so that it can be referenced. I then rewrote the DropWeapon function ( which takes 1 argument for weapon ) and I added a few features. I added a CanPlayerDropWeapon check, meaning there is now a hook that can be used to determine whether or not a player can drop a weapon ( instead of only being limited by SWEP:Holster which won't let you put the weapon away... this covers dropping ). GM function; hook.Add could still be used to overwrite this.. But this simply says if the weapon isn't valid, or SWEP:Holster returns false, or the weapon class is in a table preventing you from dropping the weapon, it returns false and the DropWeapon above sees it and prevents the drop. Otherwise it returns true and allows the drop.. [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_hooks/playerdroppedweapon/lua/autorun/server/sv_gm_canplayerdropweapon.lua[/url] So, if the weapon is successfully dropped, another hook.Call is thrown out ( this is a broadcast, we aren't expecting any other data to come back to us though... PlayerDroppedWeapon can now be hooked into to have something happen when the weapon is dropped successfully. We passed 2 arguments through to the hook... The player ( via self from inside the player meta-table ), and the weapon..: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_hooks/playerdroppedweapon/lua/autorun/sh_gm_playerdroppedweapon.lua[/url] You can write any function to include any input you want, you can do anything you want with that input, and you can inject into existing code without compromising functionality in order to add functionality... I know I have an introduction to functions somewhere which I can't seem to locate, but there are many ways to declare a function and they all work identically the same... : infers self as "first" argument ( hidden / not needed to be added when using blah:blah2( ), but when calling the same function by reference, it is expected blah.blah2( blah ). For example, you can call this function: ply:IsAdmin( ) -- like that, or ply.IsAdmin( ply ); -- or even ply5.IsAdmin( ply ) -- and the IsAdmin function will refer to ply, not ply5... In this MOTD I show 3 different ways to create a function, and they all work identically the same. Remember, Lua is a language of tables, everything is in a table. period . is accessing something by reference where-as : is accessing as a call. [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/motd.lua.html[/url] [B]One more important note:[/B] With GM functions, and with hook.Call.. You are NOT limited to using hook.Call on just GM functions. If you create an admin system and you define a function as admin:functionblah( ); you can call it by doing: hook.Call( "functionblah", admin ); The second argument is the "table" where the first argument is located as a reference. It would be the same as calling: _G[ "GAMEMODE" ][ "hookname" ]( ) or _G[ "admin" ][ "functionblah" ]( ) or _G.admin.functionblah( ) etc... Hopefully this helps...
Not experienced in the gamemode side of player hands; currently they're invisible for weapon models. I have recompiled the weapon models (originally v_) to c_models, without the hands. All SWEPs have SWEP.UseHands = true set. I do not believe the custom playermodels I am using are to blame, as the "models/player/phoenix.mdl" model also has invisible hands. The problem lies in the gamemode code, I believe, as the default cstrike c_snip_scout also has no hands. Here's the gamemode code in question (inside player.lua, which is included in init.lua): PlayerSpawn: [lua] function GM:PlayerSpawn( ply ) if GAMEMODE.round_state == ROUND_ACTIVE then ply:UnSpectate() ply:Freeze(false) ply:GodDisable(false) ply:SprintDisable() ply.temp = 98.6 pang = ply:GetAngles() ply:SetAngles(Angle(0, pang.y, 0)) GAMEMODE:PlayerLoadout( ply ) GAMEMODE:PlayerSetModel( ply ) ply:SetupHands() GAMEMODE:SetPlayerSpeed( ply, 250, 300 ) if ply:Team() == TEAM_SPECTATE then ply:Spectate(OBS_MODE_ROAMING) return end end end [/lua] PlayerSetHandsModel: [lua] function GM:PlayerSetHandsModel( ply, ent ) local plymdl = player_manager.TranslateToPlayerModelName(ply:GetModel()) local info = player_manager.TranslatePlayerHands(plymdl) if info then ent:SetModel( info.model ) ent:SetSkin( info.skin ) ent:SetBodyGroups( info.body ) end end [/lua]
Im trying to create left 4 dead sweps. Everything works fine and I found workarounds for it's limitations except for the world models World models do not seem to work with garrysmod players, so I'm wondering if there are any alternatives like parenting the left 4 dead worldmodel to a hl2 worldmodel to make it seem like it's an actual worldmodel
You need to spawn gmod_hands if you're not using the player-class to create it. Seems the wiki changed... [url]http://wiki.garrysmod.com/page/Using_Viewmodel_Hands[/url] Here is the old code where it creates the entity; plus some random stuff after do return; end which also goes with hands if you use classes. The first one is if you don't want to use classes. [code]// // New Hands System - All that's needed // if ( SERVER ) then hook.Add( "PlayerSpawn", "PlayerSpawn:NewHands", function( _p ) // // Player Class Method - If you want to use the player-class method, uncomment this, and comment out the spawning it in method. // -- player_manager.SetPlayerClass( _p, "player_dev" ); // player_default -- player_manager.OnPlayerSpawn( _p ) -- player_manager.RunClass( _p, "Spawn" ) // // ViewModel HANDS Spawning it in method // local oldhands = _p:GetHands( ); if ( IsValid( oldhands ) ) then oldhands:Remove( ); end local hands = ents.Create( "gmod_hands" ); // print( hands ) if ( IsValid( hands ) ) then _p:SetHands( hands ); hands:SetOwner( _p ); -- //Which hands should we use? local cl_playermodel = _p:GetInfo( "cl_playermodel" ); local info = player_manager.TranslatePlayerHands( cl_playermodel ); if ( info ) then hands:SetModel( info.model ); hands:SetSkin( info.skin ); hands:SetBodyGroups( info.body ); end // Attach them to the viewmodel local vm = _p:GetViewModel( 0 ); hands:AttachToViewmodel( vm ); vm:DeleteOnRemove( hands ); _p:DeleteOnRemove( hands ); hands:Spawn( ); end // End VM Hands system.. end ); else hook.Add( "PostDrawViewModel", "PostDrawViewModel:NewHands", function( _vm, _p, _w ) if ( _w.UseHands || !_w:IsScripted( ) ) then local hands = _p:GetHands( ) // LocalPlayer( ) if ( IsValid( hands ) ) then hands:DrawModel( ) end end end ); end // // Player Class Hands Method - if you want to use this method, comment out do return; end and comment out the other code above // do return; end DEFINE_BASECLASS( "player_default" ); local PLAYER = { }; PLAYER.DisplayName = "AcecoolDev Player Class" PLAYER.WalkSpeed = 100 -- How fast to move when not running PLAYER.RunSpeed = 300 -- How fast to move when running PLAYER.CrouchedWalkSpeed = 0.3 -- Multiply move speed by this when crouching PLAYER.DuckSpeed = 0.3 -- How fast to go from not ducking, to ducking PLAYER.UnDuckSpeed = 0.3 -- How fast to go from ducking, to not ducking PLAYER.JumpPower = 160 -- How powerful our jump should be PLAYER.CanUseFlashlight = false -- Can we use the flashlight PLAYER.MaxHealth = 100 -- Max health we can have PLAYER.StartHealth = 100 -- How much health we start with PLAYER.StartArmor = 0 -- How much armour we start with PLAYER.DropWeaponOnDie = false -- Do we drop our weapon when we die PLAYER.TeammateNoCollide = false -- Do we collide with teammates or run straight through them PLAYER.AvoidPlayers = false -- Automatically swerves around other players PLAYER.UseVMHands = true -- Uses viewmodel hands -- -- Name: META_PLAYER:SetupDataTables -- Desc: Set up the network table accessors -- Arg1: -- Ret1: -- function META_PLAYER:SetupDataTables() print(self.Player:Nick() .. ' SetupDataTables') BaseClass.SetupDataTables( self ); META_PLAYER:NetworkVar("Int",0,"SomeInt") end function META_PLAYER:Spawn( ) -- print( "META_PLAYER:Spawn( ) ", self.Player, self.Player:GetStamina( ) ); local oldhands = self.Player:GetHands(); if ( IsValid( oldhands ) ) then oldhands:Remove() end local hands = ents.Create( "gmod_hands" ) if ( IsValid( hands ) ) then hands:DoSetup( self.Player ) hands:Spawn() end end function META_PLAYER:GetHandsModel() -- return { model = "models/weapons/c_arms_cstrike.mdl", skin = 1, body = "0100000" } local cl_playermodel = self.Player:GetInfo( "cl_playermodel" ) return player_manager.TranslatePlayerHands( cl_playermodel ) end player_manager.RegisterClass( "player_dev", PLAYER, "player_default" ) [/code]
All you need to do is follow what the wiki tells you to do, which is have the hook in your gamemode and call ply:SetupHands(). This was made so you don't have to have extreme amounts of code copy-pasted in order to get hands to work.
So then where might the problem lie?
ok for a second I thought you guys were talking about my problem and I was deathy confused
ROFLBURGER do you need the hands to be matching player models or is l4d just fine
-snip, GroupR helped me with this- How would I say "section off" a map area to a certain usergroup?
[QUOTE=LUModder;46316536]-snip, GroupR helped me with this- How would I say "section off" a map area to a certain usergroup?[/QUOTE] You could.. 1) Add an entity (invisible?) that stretches across all entrenches to the area that people collide with unless they are apart of the group 2) Over every time increment n (1 second?) check for any unauthorized persons in the region and do x (teleport them to spawn for example).
I just can't grasp the logic behind an inventory system and crafting recipes (with multiple of the same item), knowing which ones to remove from the inventory. Are there any guides that aren't unreadable c#?
So I've got a really simple problem with compiling player models for Gmod. To test/get set up, since it's been a while, I re-downloaded all the tools (though Crowbar seems to do the job nicely) and set everything up. I've made sure the filepaths are all correct, but strangely, Crowbar cannot compile a decompiled model (I decompiled male01 from HL2 for testing, though the model was taken from SFM so I'm not sure if that's going to cause problems) into Gmod. The strange thing is that it recompiles fine back into SFM, although in the model viewer the skin texture is messed up and none of the animations made it back in, which is probably because I replaced the animation paths with the ones for a player character from this thread: [url]http://facepunch.com/showthread.php?t=764320&p=15824733&viewfull=1#post15824733[/url] The error I get is: Can't find steam app user info. So, I sort of know what the issue is: I'm not compiling directly to Gmod properly (using Gmod filepaths) and I'm probably also using the wrong animation paths for player models, unless they haven't been updated since that post. Unfortunately I can't seem to find any threads that have more up to date information on how to do this, just tons of threads asking how to do it. If anyone can point me in the right direction for this, it would be a great help. Thanks in advance.
Ask your modelling questions here: [url]http://facepunch.com/forumdisplay.php?f=40[/url]
[QUOTE=Giraffen93;46317892]I just can't grasp the logic behind an inventory system and crafting recipes (with multiple of the same item), knowing which ones to remove from the inventory. Are there any guides that aren't unreadable c#?[/QUOTE] Steam's Inventory is using a combination of class id and unique id to make an item id. For example: All AUG Contractors in CS:GO have the same class id but each of the skins has an unique id specific to the class. The ItemID is then ClassID_UniqueID. That should be easily identifiable.
[QUOTE=ms333;46318266]Steam's Inventory is using a combination of class id and unique id to make an item id. For example: All AUG Contractors in CS:GO have the same class id but each of the skins has an unique id specific to the class. The ItemID is then ClassID_UniqueID. That should be easily identifiable.[/QUOTE] i have two tables, one with all the crafting ingredients in the inventory (that have names), and one with the needed ingredients i'm getting headaches just thinking about how to compare them, if the recipe has multiple of one ingredient
[QUOTE=Giraffen93;46318299]i have two tables, one with all the crafting ingredients in the inventory (that have names), and one with the needed ingredients i'm getting headaches just thinking about how to compare them, if the recipe has multiple of one ingredient[/QUOTE] [LUA] ply.Inventory.AvailableItems = {} for _, class in pairs( ply.Inventory:GetItems() ) do ply.Inventory.AvailableItems[class] = ( ply.Inventory.AvailableItems or 0 ) + 1 end -- then in your crafting you can do local function HasRequiredItems( ply, recipe ) for _, class in pairs( recipe.Materials ) do local numItems = ply.Inventory.AvailableItems[class] if numItems < recipe.Materials[class] then return false end return true end end [/LUA] something like that should do
[QUOTE=rejax;46318848] something like that should do[/QUOTE] never thought about doing integers as values in the materials, thanks!
[lua]function GM:LoadPlugin(prefix, name) local cleanprefix = prefix; if (cleanprefix == "") then prefix = "sh-"; end Plugin = table.Copy(META); if (prefix == "sv-" or prefix == "sh-") then if SERVER then include(META.Directory..cleanprefix..name..".lua"); end end if (prefix == "cl-" or prefix == "sh-") then if SERVER then AddCSLuaFile(META.Directory..cleanprefix..name..".lua"); end end if CLIENT then if (prefix == "cl-" or prefix == "sh-") then include(META.Directory..cleanprefix..name..".lua"); end end local Result = table.Copy(Plugin); Plugin = nil; return Result end function GM:RegisterPlugin(plugin, index) plugin.Prefix = META.Plugins[index]; META.Plugins[index] = plugin; end function GM:CahcePlugins() for k, v in pairs(file.Find(META.Directory.."*.lua", "LUA")) do local prefix = string.lower(string.sub(v, 1, 3)); local name; if !(prefix == "sv-" or prefix == "cl-" or prefix == "sh-") then prefix = ""; name = string.lower(string.sub(v, 1, (table.Count(string.Explode("", v)) - 4))); META.Plugins[name] = prefix; else name = string.lower(string.sub(v, 4, (table.Count(string.Explode("", v)) - 4))); META.Plugins[name] = prefix; end local Result = self:LoadPlugin(prefix, name); if !Result.Deactivated then self:RegisterPlugin(Result, name); end end end hook.Call("CahcePlugins", GM, CahcePlugins);[/lua] I decided writing a plugin system which I'll eventually add activation and deactivation hooks but I'm having trouble within my plugins with small stuff, most of which I'm ironing out but I'm having troubles now with a server-side file. I'm having issues calling Player.SendHint after I derived from sandbox and setup my gamemode.txt, this is what my plugin looks like: [lua] Plugin.Disabled = nil; --for future reference -- -- Make BaseClass available -- DEFINE_BASECLASS( "gamemode_base" ); function Plugin:Initialize() end function GM:PlayerInitialSpawn(ply) BaseClass.PlayerInitialSpawn(self, ply); end --[[--------------------------------------------------------- Name: gamemode:PlayerSpawnObject( ply ) Desc: Called to ask whether player is allowed to spawn any objects -----------------------------------------------------------]] function GM:PlayerSpawnObject( ply ) return true; end --[[--------------------------------------------------------- Name: gamemode:CanPlayerUnfreeze( ) Desc: Can the player unfreeze this entity & physobject -----------------------------------------------------------]] function GM:CanPlayerUnfreeze( ply, entity, physobject ) if ( entity:GetPersistent() ) then return false end return false end function GM:CheckPassword(steamID, ipAddress, svPassword, clPassword, name) print(steamID, name); end function GM:PlayerSpawn(ply) player_manager.SetPlayerClass(ply, "player_sandbox"); BaseClass.PlayerSpawn(self, ply); ply:SendHint("Welcome...", 30); print("welcome"); end function GM:ShowHelp(ply) return true; end function GM:ShowSpare1(ply) return true; end function GM:ShowSpare2(ply) return true; end function GM:ShowTeam(ply) return true; end[/lua] Look under GM.PlayerSpawn, any suggestions? I haven't noticed anything else break or not work.
-snip- Never mind, got it.
[QUOTE=serfma;46321121]-snip-[/QUOTE] Just in case anyone else is interested in a type of warning system where it increments and can do punishments based on warnings: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_warning_system/sv_simple_warn_command.lua.html[/url]
I'm trying to make a script that does a bunch of random stuff that I want it to, and the first item on the list is to simply make npcs patrol when they spawn. But gmod won't let me do that. [CODE]function NPCPatrolHandler( pl, nonpc ) if (GetConVarNumber("npcspatrol") < 1) then return; end ent_fire nonpc startpatrolling end[/CODE] That's the function that's supposed to check whether or not I currently want npcs to patrol when spawned, but I get this error when I set the variable to one and try to spawn an npc. [CODE][ERROR] addons/test_addon/lua/autorun/test.lua:18: '=' expected near 'nonpc' 1. unknown - addons/test_addon/lua/autorun/test.lua:0 [/CODE] Alternatively I can change the ent_fire command to [CODE]nonpc:Fire( "startpatrolling", 0, 0 )[/CODE] Which should net me the same end results I think... But I get an error that tells me that a script "expected a number but got a string" and going into the code for the error leads me to lua\includes\modules\concommand.lua on line 69. Let me save you some time here... [CODE]--[[--------------------------------------------------------- Name: concommand.Run( ) Desc: Called by the engine when an unknown console command is run -----------------------------------------------------------]] function Run( player, command, arguments, args ) local LowerCommand = string.lower( command ) if ( CommandList[ LowerCommand ] != nil ) then CommandList[ LowerCommand ]( player, command, arguments, args ) --This is line 69. return true end if ( player:IsValid() ) then player:ChatPrint( "Unknown Command: '" .. command .. "'\n" ) end return false; end[/CODE] I haven't been able to make any sense of it and I've been trying for the last two and a half hours. Can anyone explain what the error here is? With either method? (Note: This is my first endeavor into lua programming, but I know a decent amount of python, which is quite similar to lua according to some resources. Point: I'm not a total no0b to programming.)
so i cant get [code]self.Owner:GetHands():SetMaterial("models/shadertest/predator.mdl")[/code] to work (im using the ttt weapon base)
How do I check on the clientside if a player is drawn without using util.TraceLine or util.PixelVisible? I figured it should be something along the lines of player.GetByID( 2 ):GetNoDraw( ) but it doesn't work the way you'd expect it to work. Even if you're in two different visleafs, player.GetByID(2):GetNoDraw() will be false.
[QUOTE=AJ10017;46322224]so i cant get [code]self.Owner:GetHands():SetMaterial("models/shadertest/predator.mdl")[/code] to work (im using the ttt weapon base)[/QUOTE] Are you using a c_model for your swep model? That line of code works fine for me.
[QUOTE=ROFLBURGER;46322891]Are you using a c_model for your swep model? That line of code works fine for me.[/QUOTE] yes, c_slam. im setting the viewmodel material as well
[QUOTE=EthanTheGreat;46322776]How do I check on the clientside if a player is drawn without using util.TraceLine or util.PixelVisible? I figured it should be something along the lines of player.GetByID( 2 ):GetNoDraw( ) but it doesn't work the way you'd expect it to work. Even if you're in two different visleafs, player.GetByID(2):GetNoDraw() will be false.[/QUOTE] Pre/PostPlayerDraw is called for players that it draws.. If something needs to be done when you draw the player, those hooks would be appropriate. [editline]25th October 2014[/editline] [QUOTE=heatguts;46322216]I'm trying to make a script that does a bunch of random stuff that I want it to, and the first item on the list is to simply make npcs patrol when they spawn. But gmod won't let me do that. [CODE]function NPCPatrolHandler( pl, nonpc ) if (GetConVarNumber("npcspatrol") < 1) then return; end ent_fire nonpc startpatrolling end[/CODE] [/quote] Instead of using: ent_fire nonpc startpatrolling it should be something like: [CODE]function NPCPatrolHandler( pl, nonpc ) if ( GetConVarNumber( "npcspatrol" ) < 1 ) then return; end nonpc:Fire( "startpatrolling", "true", 0 ); -- http://wiki.garrysmod.com/page/Entity/Fire end[/CODE] [QUOTE=heatguts;46322216][CODE][ERROR] addons/test_addon/lua/autorun/test.lua:18: '=' expected near 'nonpc' 1. unknown - addons/test_addon/lua/autorun/test.lua:0 [/CODE] [/quote] The reason the error appears is because it is a console command, not a valid Lua command. You could use [code]RunConsoleCommand( "ent_fire", "classname/targetname", "startpatrolling" ); -- https://developer.valvesoftware.com/wiki/Ent_fire[/code] game.ConsoleCommand might be another valid option. [QUOTE=heatguts;46322216] Alternatively I can change the ent_fire command to [CODE]nonpc:Fire( "startpatrolling", 0, 0 )[/CODE] Which should net me the same end results I think... But I get an error that tells me that a script "expected a number but got a string"[/quote] Other way around, the second argument needs a string such as true/false, or even 0 but wrapped in quotes or tostring( 0 ) could be used. [QUOTE=heatguts;46322216] and going into the code for the error leads me to lua\includes\modules\concommand.lua on line 69. Let me save you some time here... [CODE]--[[--------------------------------------------------------- Name: concommand.Run( ) Desc: Called by the engine when an unknown console command is run -----------------------------------------------------------]] function Run( player, command, arguments, args ) local LowerCommand = string.lower( command ) if ( CommandList[ LowerCommand ] != nil ) then CommandList[ LowerCommand ]( player, command, arguments, args ) --This is line 69. return true end if ( player:IsValid() ) then player:ChatPrint( "Unknown Command: '" .. command .. "'\n" ) end return false; end[/CODE] [/quote] I'd change a few things to ensure proper running: [CODE]--[[--------------------------------------------------------- Name: concommand.Run( ) Desc: Called by the engine when an unknown console command is run -----------------------------------------------------------]] function Run( ply, command, arguments, args ) // Set up a default string, just in case using ternary operation -- can be done with other things too -- command = ( isstring( command ) ) && command || ""; local LowerCommand = string.lower( command ) // Don't check for != nil because a lot of things != nil. You are going to use it as a function so the isfunction function will return true if it is a function, false if not... if it is a function then it'll allow it to proceed if ( isfunction( CommandList[ LowerCommand ] ) ) then CommandList[ LowerCommand ]( ply, command, arguments, args ) --This is line 69. return true end // Don't use :IsValid, because that function won't exist on an invalid object, use the global IsValid check if ( IsValid( ply ) ) then ply:ChatPrint( "Unknown Command: '" .. command .. "'\n" ) end return false; end[/CODE] I'd also recommend shortening the vars.. basically player is an object in GLua so it is possible to mess with certain elements or cause certain errors... I changed it to ply for that reason although I personally use _p for player. [QUOTE=heatguts;46322216] I haven't been able to make any sense of it and I've been trying for the last two and a half hours. Can anyone explain what the error here is? With either method? (Note: This is my first endeavor into lua programming, but I know a decent amount of python, which is quite similar to lua according to some resources. Point: I'm not a total no0b to programming.)[/QUOTE] Hopefully some of my input has helped. Oh, and while I'm here, I'd definitely recommend using Notepad++ to write Lua, additionally I'd recommend installing an up to date xml file for the GMod Lua language so that special words are highlighted ( such as player ) to prevent certain mistakes. I'd also recommend standardizing your code a bit, you use pl in one place and then player in another. Here are some resources to help you get started: ------------------------------------------------------------- Generalized Lua Help ( Links to Wikis, Answers the question of "Where do I post a simple question or DarkRP Specific question", links to other resources compiled by forum members ) [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_general_lua_learning.lua.html[/url] Useful Programs ( SteamCMD, Autosizer, Desktops, Process Explorer ) and Notepad++ Upgrades ********** Look at this, get the XML file, install it.. it'll help. Also some other things that help are in here too! [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/___welcome_docs/_welcome_useful_programs_and_notepadpp_upgrades.lua.html[/url]
-snip fixed-
Sorry, you need to Log In to post a reply to this thread.