• Problems That Don't Need Their Own Thread v3.0
    5,003 replies, posted
[CODE] local function AddModel(Ply) local PModel = ModelTable[Ply] if PModel == nil then Ply:PrintMessage("Sorry, But this is a VIP feature") return end timer.Simple(1,function() Ply:SetModel(PModel) end) return end hook.Add("PlayerSpawn","Turtle_Playermodel",function(Ply) AddModel(Ply) end)[/CODE] Seems to be overriding the default gamemode PlayerSpawn... How would you fix this? --Figured it out--
[QUOTE=meharryp;47833479]What's the difference? I've always used pairs and never had any problems.[/QUOTE] ipairs forces the iteration to be sequential if the keys are numerical and sequential.
pairs will - by implementation - iterate numeric indexes in order first, but it's undefined and not guaranteed to happen.
[code]function GM:PlayerInitialSpawn(ply) GAMEMODE:PlayerSpawnAsSpectator( ply ) end [/code] This code, for some reason, doesn't spawn the player as a spectator. I need this to work, though, because I want to do it the first time a player spawns... Am I using the wrong hook? Did I do something wrong? I need help... [editline]Edited:[/editline] I found out that PlayerInitialSpawn() is called when the player is still loading into the game, so what hook would I use that is called whenever a player has spawned but is called only the first time the player spawns?
What should I used to hook onto when the server starts? I want to initialize my game mode timer as the server is just beginning. My idea is 'InitPostEntity' but I'm not sure if this is correct. Can someone tell me if I should use this or is there a better way to go about it? [editline]29th May 2015[/editline] [QUOTE=A Fghtr Pilot;47835040][code]function GM:PlayerInitialSpawn(ply) GAMEMODE:PlayerSpawnAsSpectator( ply ) end [/code] This code, for some reason, doesn't spawn the player as a spectator. I need this to work, though, because I want to do it the first time a player spawns... Am I using the wrong hook? Did I do something wrong? I need help... [editline]Edited:[/editline] I found out that PlayerInitialSpawn() is called when the player is still loading into the game, so what hook would I use that is called whenever a player has spawned but is called only the first time the player spawns?[/QUOTE] Perhaps you could hook onto PlayerSpawn() and when that is called your function can do a conditional check weather it is first spawn or not. You can do that check by using some sort of a Boolean variable. This is my idea, what do others think?
How do I get my stupid nextbots to work? I've tried making a simple bot two times and gave up because I can never get them to actually move. Do I need to derive from sandbox to use the nextbots? [i]Gamemode/entities/entities/fa_testbot.lua[/i] [code]AddCSLuaFile() ENT.Base = "base_nextbot" ENT.Spawnable = true function ENT:Initialize() self:SetModel( "models/mossman.mdl" ) self:SetMoveType(MOVETYPE_STEP) self.LoseTargetDist = 2000 -- How far the enemy has to be before we lose them self.SearchRadius = 1000 -- How far to search for enemies end ---------------------------------------------------- -- ENT:Get/SetEnemy() -- Simple functions used in keeping our enemy saved ---------------------------------------------------- function ENT:SetEnemy( ent ) self.Enemy = ent end function ENT:GetEnemy() return self.Enemy end ---------------------------------------------------- -- ENT:HaveEnemy() -- Returns true if we have an enemy ---------------------------------------------------- function ENT:HaveEnemy() -- If our current enemy is valid if ( self:GetEnemy() and IsValid( self:GetEnemy() ) ) then -- If the enemy is too far if ( self:GetRangeTo( self:GetEnemy():GetPos() ) > self.LoseTargetDist ) then -- If the enemy is lost then call FindEnemy() to look for a new one -- FindEnemy() will return true if an enemy is found, making this function return true return self:FindEnemy() -- If the enemy is dead( we have to check if its a player before we use Alive() ) elseif ( self:GetEnemy():IsPlayer() and !self:GetEnemy():Alive() ) then return self:FindEnemy() -- Return false if the search finds nothing end -- The enemy is neither too far nor too dead so we can return true return true else -- The enemy isn't valid so lets look for a new one return self:FindEnemy() end end ---------------------------------------------------- -- ENT:FindEnemy() -- Returns true and sets our enemy if we find one ---------------------------------------------------- function ENT:FindEnemy() -- Search around us for entities -- This can be done any way you want eg. ents.FindInCone() to replicate eyesight local _ents = ents.FindInSphere( self:GetPos(), self.SearchRadius ) -- Here we loop through every entity the above search finds and see if it's the one we want for k, v in pairs( _ents ) do if ( v:IsPlayer() ) then -- We found one so lets set it as our enemy and return true self:SetEnemy( v ) return true end end -- We found nothing so we will set our enemy as nil ( nothing ) and return false self:SetEnemy( nil ) return false end ---------------------------------------------------- -- ENT:RunBehaviour() -- This is where the meat of our AI is ---------------------------------------------------- function ENT:RunBehaviour() -- This function is called when the entity is first spawned, it acts as a giant loop that will run as long as the NPC exists while ( true ) do self:StartActivity( ACT_WALK ) -- Walk anmimation self.loco:SetDesiredSpeed( 200 ) -- Walk speed self:MoveToPos( self:GetPos() + Vector( math.Rand( -1, 1 ), math.Rand( -1, 1 ), 0 ) * 400 ) -- Walk to a random place within about 400 units ( yielding ) self:StartActivity( ACT_IDLE ) coroutine.wait( 2 ) end end ---------------------------------------------------- -- ENT:ChaseEnemy() -- Works similarly to Garry's MoveToPos function -- except it will constantly follow the -- position of the enemy until there no longer -- is an enemy. ---------------------------------------------------- function ENT:ChaseEnemy( options ) local options = options or {} local path = Path( "Follow" ) path:SetMinLookAheadDistance( options.lookahead or 300 ) path:SetGoalTolerance( options.tolerance or 20 ) path:Compute( self, self:GetEnemy():GetPos() ) -- Compute the path towards the enemy's position if ( !path:IsValid() ) then print("wef") return "failed" end while ( path:IsValid() and self:HaveEnemy() ) do if ( path:GetAge() > 0.1 ) then -- Since we are following the player we have to constantly remake the path path:Compute( self, self:GetEnemy():GetPos() )-- Compute the path towards the enemy's position again end path:Update( self ) -- This function moves the bot along the path if ( options.draw ) then path:Draw() end -- If we're stuck then call the HandleStuck function and abandon if ( self.loco:IsStuck() ) then self:HandleStuck() return "stuck" end coroutine.yield() end return "ok" end list.Set( "NPC", "fa_testbot", { Name = "Simple bot", Class = "fa_testbott", Category = "NextBot" } )[/code]
[QUOTE=MGCLegend;47833692]Sorry but I don't map much and play around with mapping and lua in the same context. How do you get details from a map. Say if a player is in a custom zone. If the map has a "bitches only" zone then how would you find if ply is in zone "bitches only"?[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ents/FindInBox]ents.FindInBox[/url] would probably be your best bet.
Can someone inform me of all the related files and folders for nextbots so I can copy them over into a gamemode that derives from base?
Nextbots work in Base gamemode. It's a problem with your code. [URL="https://github.com/garrynewman/garrysmod/tree/89ee90877427712e53f82d8f073aaf07b4c70737/garrysmod/gamemodes/base/entities/entities/base_nextbot"]Here's the source.[/URL] [URL="http://pastebin.com/TpVYUS8T"]Here's an example of simple chase mechanics.[/URL] You also might not have your navmesh generated. Set sv_cheats to 1, and enter nav_generate.
Thank you for the source. I created this map, and yea the problem was with the navigation mesh. These are normally created via hammer right? Also I know there is a navigation mesh module around here somewhere, is this any more efficient(quicker) than the standard one created via hammer?
[QUOTE=find me;47836261]Thank you for the source. I created this map, and yea the problem was with the navigation mesh. These are normally created via hammer right? Also I know there is a navigation mesh module around here somewhere, is this any more efficient(quicker) than the standard one created via hammer?[/QUOTE] [QUOTE=Lolcats;47835953] You also might not have your navmesh generated. Set sv_cheats to 1, and enter nav_generate.[/QUOTE] Your brand new navmesh is located in your maps folder, named mapname.nav.
[QUOTE=WalkingZombie;47832832]I can't say for sure, but maybe fiddling around with filters will get it to work? [editline]29th May 2015[/editline] It might help to see some code.[/QUOTE] Already tried that. Here's an example print(util.TraceLine({start = Entity(blah):GetPos(), endpos = Entity(blah):GetPos()+Vector(0,0,10000)}).FractionLeftSolid)
[QUOTE=thegrb93;47836726]Already tried that. Here's an example print(util.TraceLine({start = Entity(blah):GetPos(), endpos = Entity(blah):GetPos()+Vector(0,0,10000)}).FractionLeftSolid)[/QUOTE] I think I know why you're getting numbers so close to, or equal to, 0 [quote=The Wiki]this will return at what distance the trace left the solid from [B]0-1[/B][/quote] By having your trace 10000 units long, that means if it only takes 15 units to exit the object, you'll get 0.0015 - if it takes 5 units, you'll get 0.0005 When it says from 0 to 1, 0 = it starts out in free space, 1 = it reached the end of the trace and never left the object. This is considerable when your trace is only 20 units long, but with a trace 10k units long, 100 units is just 0.01, 8 feet (or about 2.44 meters) is just 0.0128 [B]Here's a solution:[/B] Take what you get, and multiply it by 10000. This would give you the exact unit distance from Entity(blah):GetPos() to free space. I do recommend dropping that number down significantly though, perhaps to just 500... which should still be WAY more than enough to trace out of any prop / object you throw at it. [URL="https://developer.valvesoftware.com/wiki/Hammer_Units"]Unit Conversion Reference[/URL] [URL="http://wiki.garrysmod.com/page/Structures/TraceResult"]Wiki Reference[/URL] [editline]30th May 2015[/editline] I wish I knew what you were actually trying to do, there may yet still be something better you can try!
[QUOTE=MGCLegend;47833692]Sorry but I don't map much and play around with mapping and lua in the same context. How do you get details from a map. Say if a player is in a custom zone. If the map has a "bitches only" zone then how would you find if ply is in zone "bitches only"?[/QUOTE] if you want a zone in a map, you could create a custom entity folder like below then create a brush and force it to that entity by typing it in the box. [code]ENT.Base = "base_brush" ENT.Type = "brush" function ENT:StartTouch( entity ) if(entity:IsPlayer() and entity:IsValid() then for _, v in pairs(player.GetAll()) do v:PrintMessage(HUD_PRINTTALK, entity:GetName().. " has entered the lua brush area.") end end end[/code] alternatively you could probably just name a brush, use ents.FindByName to get it, use :StartTouch like above to create the callback when an entity touches it, and :SetTrigger(true) to enable it.
Does anyone know if util.DecalEx will be fixed and if so, when?
-snip-
[QUOTE=WalkingZombie;47837357]I think I know why you're getting numbers so close to, or equal to, 0 By having your trace 10000 units long, that means if it only takes 15 units to exit the object, you'll get 0.0015 - if it takes 5 units, you'll get 0.0005 When it says from 0 to 1, 0 = it starts out in free space, 1 = it reached the end of the trace and never left the object. This is considerable when your trace is only 20 units long, but with a trace 10k units long, 100 units is just 0.01, 8 feet (or about 2.44 meters) is just 0.0128 [B]Here's a solution:[/B] Take what you get, and multiply it by 10000. This would give you the exact unit distance from Entity(blah):GetPos() to free space. I do recommend dropping that number down significantly though, perhaps to just 500... which should still be WAY more than enough to trace out of any prop / object you throw at it. [URL="https://developer.valvesoftware.com/wiki/Hammer_Units"]Unit Conversion Reference[/URL] [URL="http://wiki.garrysmod.com/page/Structures/TraceResult"]Wiki Reference[/URL] [editline]30th May 2015[/editline] I wish I knew what you were actually trying to do, there may yet still be something better you can try![/QUOTE] I know how to do math on a fraction. The problem is FractionLeftSolid is returning 0.
[QUOTE=A Fghtr Pilot;47840501]I don't see any GetNextIdle or SetNextIdle functions defined.... are those defined by default or something?[/QUOTE] Take a good look at the code, there's a reason why I added the setupdatatables with the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/NetworkVar]Entity:NetworkVar[/url] function, it creates SetNextIdle and GetNextIdle when called there.
[QUOTE=Jvs;47840617]Take a good look at the code, there's a reason why I added the setupdatatables with the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/NetworkVar]Entity:NetworkVar[/url] function, it creates SetNextIdle and GetNextIdle when called there.[/QUOTE] Whoops, forgot XD. Thanks for the code, after implementing it into my SWEP code it works perfectly with the AR2 viewmodel, thanks :3
Hey, how can I get some particles to stay locked to the viewmodel? It looks really weird while moving right now, and I'm using ParticleEffectAttach already. Viewmodel effect is enabled in the particle .pcf file. I think I'm looking for a way to get the particles to use coordinates local to the viewmodel, rather than the world?
How can I keep dynamically created materials from dying when doing anything that invokes a material reload? (mat_reload, changing some video settings, etc) Preferably without checking its validity every frame?
I need to know what the best way to display a serverside variable in clientside HUDPaint hook is. In a deathmatch gamemode I'm creating I need to display the amount of kills a certain team has... problem is, the variable that shows these kills is serverside.... would I create a shared variable that's value is the serverside variable and use the shared variable in my cl_init script or would I send a net message from the client to the server, containing this variable or vice versa(that might not be a good idea to send a net message every frame, or would it be?), or would I just need to do something else I haven't thought of yet?
I want to give a player a certain item in pointshop if they kill somebody with fire. Any help? Current code: [CODE]hook.Add( "PlayerDeath", "Gift of Fire", function( victim, inflictor, attacker ) if not victim == attacker and inflictor:GetClass() == "env_fire" then attacker:PS_GiveItem( "melon" ) end --PrintMessage( HUD_PRINTTALK, tostring(inflictor) ) end )[/CODE]
[code]--class's file DEFINE_BASECLASS( "player_default" ) AddCSLuaFile() local PLAYER = {} -- -- See gamemodes/base/player_class/player_default.lua for all overridable variables -- PLAYER.WalkSpeed = 130 PLAYER.RunSpeed = 330 function PLAYER:SetModel() util.PrecacheModel( "models/player/combine_soldier.mdl" ) self.Player:SetModel( "models/player/combine_soldier.mdl" ) end[/code] [code]--init.lua player_manager.RegisterClass( "player_combine", PLAYER, "player_default" ) DEFINE_BASECLASS( "gamemode_base" ) function GM:PlayerSpawn( pl ) pl:SetTeam( 1 ) player_manager.SetPlayerClass( pl, "player_combine" ) player_manager.RunClass( pl, "Loadout" ) player_manager.RunClass( pl, "SetModel" ) pl:SetupHands() end[/code] For some reason, my class's speed stays normal and doesn't change even though I have the speed set to be slower than usual... Can anyone help?
[QUOTE=thegrb93;47840588]I know how to do math on a fraction. The problem is FractionLeftSolid is returning 0.[/QUOTE] Then try dropping the length of the trace. In theory FractionLeftSolid should then be a larger decimal, that MIGHT fix it. Also, I'm sure you've already done this, but make sure you're not rounding it somehow.
[code] >ME:ChatPrint(tostring(THIS)) Entity [131][prop_physics] >ME:ChatPrint(util.TraceLine({start=THIS:GetPos(),endpos=THIS:GetPos()+Vector(0,0,200)}).FractionLeftSolid) 0 >ME:ChatPrint(tostring(util.TraceLine({start=THIS:GetPos(),endpos=THIS:GetPos()+Vector(0,0,200)}).StartSolid)) true >ME:ChatPrint(util.TraceLine({start=THIS:GetPos(),endpos=THIS:GetPos()+Vector(0,0,200),filter=THIS}).FractionLeftSolid) 0 >ME:ChatPrint(tostring(util.TraceLine({start=THIS:GetPos(),endpos=THIS:GetPos()+Vector(0,0,200),filter=THIS}).StartSolid)) false [/code] Yes I'm sure that 200 is enough to exit the prop. Should return 1 anyway though if it doesn't exit the solid.
Quick question, is the GAMEMODE table available client side?
[QUOTE=toshko3331;47843844]Quick question, is the GAMEMODE table available client side?[/QUOTE] yes
[QUOTE=Willox;47843845]yes[/QUOTE] In that case I have some sort of a strange problem. I have a round timer thingie, and there are different states for it. I set the state of it in the GM:Initialize function as such 'GAMEMODE.state = WARMUP' (WARMUP is a constant). I have printed the value in the init.lua and shared.lua and it is fine. However, when I try to access it in the cl_init.lua it comes up nil. I access it by doing this [CODE] function GM:PlayerTick() print(" " .. self:GetGameState()) --ROUND:GetRemainingTime() end [/CODE] Actually , as a matter of fact, anything that I try to access outside of this client returns nil such as my 'ROUND:GetRemainingTime()' which is located in a different file and is supposed to return a floating point number.
Show all the relevant code.
Sorry, you need to Log In to post a reply to this thread.