• Problems That Don't Need Their Own Thread v3.0
    5,003 replies, posted
[QUOTE=MaximLaHaxim;49058661]Anyone know how I could find the contents of a function?[/code] how would I somehow get a string that tells me what is in the function? i.e How would I create a function that would return "MsgN("Herro Der!")" if I ran it on testfunc?[/QUOTE] I'm 99% sure you can't since I've tried to do this before for ages. If you try debug.getinfo you can get a bit of stuff about it though, but not the contents. Also, I have a question that I'm sure has a really obvious answer- but is there a way to blend two sequences within gmod, e.g. when one stops, another starts, but in a blended way? I have a timer that changes sequences after the other one finishes, but this looks really odd. Edit: there seems to be some stuff to do with this in the latest update, but it isn't released yet, so is there a way in the current verison?
sorry I would like to help you but I don't know how... Btw I made this: [CODE]function ENT:OnInjured(dmginfo) self.IsIdling = false if self.male then local sound = table.Random(malepainsounds) self:EmitSound(sound) else local sound = table.Random(femalepainsounds) self:EmitSound(sound) end self:StartActivity(ACT_RUN) self.loco:SetDesiredSpeed(350) timer.Create( "helptimer", math.random(1,5) , math.random(1,5), function() if self.male then local sound = table.Random(malepanicsounds) self:EmitSound(sound) else local sound = table.Random(femalepanicsounds) self:EmitSound(sound) end end) end function ENT:RunBehaviour() while ( true ) do if (self.IsIdling) then self:StartActivity( ACT_WALK ) self.loco:SetDesiredSpeed( 80 ) self:MoveToPos( self:GetPos() + Vector( math.Rand( -1, 1 ), math.Rand( -1, 1 ), 0 ) * 1500 ) self:PlaySequenceAndWait( "idle_to_sit_ground" ) self:SetSequence( "sit_ground" ) coroutine.wait( self:PlayScene(table.Random( scenes ))) self:PlaySequenceAndWait( "sit_ground_to_idle" ) else self.IsIdling = false self:StartActivity(ACT_RUN) self.loco:SetDesiredSpeed(350) local hide = self:FindSpot( "random", { type = 'hiding', radius = 15000 } ) if (hide) then self:MoveToPos(hide) self:PlaySequenceAndWait( "fear_reaction" ) coroutine.wait(3) self:StartActivity(ACT_IDLE) end end end end[/CODE] When the npc receive damage it should start to run away and hide how set in this part : [CODE] self.IsIdling = false self:StartActivity(ACT_RUN) self.loco:SetDesiredSpeed(350) local hide = self:FindSpot( "random", { type = 'hiding', radius = 15000 } ) if (hide) then self:MoveToPos(hide) self:PlaySequenceAndWait( "fear_reaction" ) coroutine.wait(3) self:StartActivity(ACT_IDLE)[/CODE] but when I hit it the npc runs away but after 4/5 seconds it executes this part of code ONCE: [CODE] self:PlaySequenceAndWait( "idle_to_sit_ground" ) self:SetSequence( "sit_ground" ) coroutine.wait( self:PlayScene(table.Random( scenes ))) self:PlaySequenceAndWait( "sit_ground_to_idle" ) [/CODE] then it stand up and start to hide... How can you see it should sit to the ground and play the scene only if self.IsIdling is true but if I hit him self.IsIdling should become false so why the nextbot runs again the sitting to the ground animation?
[QUOTE=Shenesis;49063058]Has anyone ever ran into an issue with Player:SetPos? I have rare cases where it just doesn't teleport the player but it works on the second time. I'm not doing this on spawn or anything[/QUOTE] A simple fix for that is make a check after the teleport it the POS != tarPOS then force the teleport again
[QUOTE=Shenesis;49063058]Has anyone ever ran into an issue with Player:SetPos? I have rare cases where it just doesn't teleport the player but it works on the second time. I'm not doing this on spawn or anything[/QUOTE] I've been struggling with this issue forever. Are you calling it in a SWEP by chance?
Does anyone know of a function that return the print name of the weapon that the player is holding? There is this [url]http://wiki.garrysmod.com/page/Player/GetWeapon[/url] but I'm not sure how to use it.
I'm havin a problem with SQL. So, here's what I'm trying to do: [CODE]local data = sql.Query(sql)[/CODE] sql is defined. This error comes up: [CODE][ERROR] addons/gtawards/lua/gtawards/server/sv_gtawards.lua:154: attempt to index a string value with bad key ('Query' is not part of the string library)[/CODE] I even tried the exact code from the wiki, but it is continuing giving me this error. Any idea? [editline]6th November 2015[/editline] Sorry, found the issue: I named the variable sql, which was causing sql.Query not to work.
[QUOTE=CaptainFaggot;49063778]Does anyone know of a function that return the print name of the weapon that the player is holding? There is this [URL]http://wiki.garrysmod.com/page/Player/GetWeapon[/URL] but I'm not sure how to use it.[/QUOTE] [lua] function GetWeaponName(wep) if IsValid(wep) then if wep:IsScripted() then return wep.PrintName or "" else return wep:GetClass() end end end print(GetWeaponName(client:GetActiveWeapon())) [/lua]
[QUOTE=Shenesis;49064175]I did that but it seems to have a chance to fail even on the 2nd and 3rd try. (delayed with a 0.1s and 0.2s timer for both) Nope, I'm calling it in a timer when the player defeats another player in a duel[/QUOTE] I have this issue when I call it in my arrest baton swep but no where else. Calling it in a .3 second timer seems to fix it 99% of the time.
I'm using SetModelScale on the client's end to rescale an object, and I have the server setting model scale on a delay, but SetModelScale on the server forces a visual update on the client, so basically it flashes to the server's scale and then back to what the client is scaling it at. Is there a way to not visually update an object when the scale is set on the server?
[QUOTE=Shenesis;49063058]Has anyone ever ran into an issue with Player:SetPos? I have rare cases where it just doesn't teleport the player but it works on the second time. I'm not doing this on spawn or anything[/QUOTE] You are doing it serverside, right?
[QUOTE=MPan1;49067552]You are doing it serverside, right?[/QUOTE] Well he says it works the second time it's run, so I have to assume so, otherwise it wouldn't work, period. I get the bug sometimes, too, but only on DarkRP or a laggy server.
Also, an actual question- is there a way to make an entity get removed when a player leaves, and only a certain player? I'm trying to make a fake death ragdoll for when players die, and I want to remove the ragdoll when the player respawns, or when they leave, so it won't constantly stay on the server. [editline]7th November 2015[/editline] I could use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerDisconnected]GM/PlayerDisconnected[/url] but I don't know...
[QUOTE=MPan1;49067617]Also, an actual question- is there a way to make an entity get removed when a player leaves, and only a certain player? I'm trying to make a fake death ragdoll for when players die, and I want to remove the ragdoll when the player respawns, or when they leave, so it won't constantly stay on the server. [editline]7th November 2015[/editline] I could use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerDisconnected]GM/PlayerDisconnected[/url] but I don't know...[/QUOTE] If playerdisconnected is really not preferable, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/CallOnRemove]Entity:CallOnRemove[/url]
Thanks! Another weird thing- why does running [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/RagdollUpdatePhysics]Entity:RagdollUpdatePhysics[/url] on a ragdoll with bones modified with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetRagdollPos]Entity:SetRagdollPos[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetRagdollAng]Entity:SetRagdollAng[/url] cause it to become frozen in place, as well as make it fly to the position and end up looking really odd? Is there a way to stop it from being frozen?
I don't know SWEPs very well, but I have an automatic weapon - how do I detect that Mouse 1 and Mouse 2 is down? aka primary attack is running, basically, I wanna do 'while mouse 1 is down and mouse 2 is down, variable is equal to this, else make it something different' I know I can use a Think hook or something and check what weapon everyone has but that seems sloppy and I feel like there should be a method within the swep system itself to detect this
[QUOTE=NiandraLades;49071129]I don't know SWEPs very well, but I have an automatic weapon - how do I detect that Mouse 1 and Mouse 2 is down? aka primary attack is running, basically, I wanna do 'while mouse 1 is down and mouse 2 is down, variable is equal to this, else make it something different' I know I can use a Think hook or something and check what weapon everyone has but that seems sloppy and I feel like there should be a method within the swep system itself to detect this[/QUOTE] hook.Add [url=http://wiki.garrysmod.com/page/GM/KeyPress]GM.KeyPress[/url] Or in [url=http://wiki.garrysmod.com/page/WEAPON/Think]SWEP.Think[/url] just use [url=http://wiki.garrysmod.com/page/Player/KeyDown]Player.KeyDown[/url]. [quote]I know I can use a Think hook or something and check what weapon everyone has but that seems sloppy and I feel like there should be a method within the swep system itself to detect this[/quote] A lot of SWEP codes I've read use the "hook.add and check if a player has this weapon" method, so don't worry, it isn't as sloppy as it seems. Just put some comments in so you don't forget what certain lines of code do. [editline]fucknuggets:([/editline] Now, for my own problem. [code]function GM:PreDrawHalos() local singletab = { LocalPlayer():GetNWEntity( "SelectedCombine" ) } if singletab[1] == NULL then print("nope") return end halo.Add( singletab, Color( 255, 0, 0 ), 5, 5, 1, true, true ) end[/code] Any idea why halos draw randomly sometimes even if GetNWEntity( "SelectedCombine" ) is NULL? And if the selected combine NWvar isn't NULL it randomly stops drawing then draws again some time after? Chances are it's the arguments I used for halo.Add; what should I change?
Is there a way to disable Knockback from taking damage?
[QUOTE=NiandraLades;49071129]I don't know SWEPs very well, but I have an automatic weapon - how do I detect that Mouse 1 and Mouse 2 is down? aka primary attack is running, basically, I wanna do 'while mouse 1 is down and mouse 2 is down, variable is equal to this, else make it something different' I know I can use a Think hook or something and check what weapon everyone has but that seems sloppy and I feel like there should be a method within the swep system itself to detect this[/QUOTE] could always set a variable in PrimaryAttack and SecondaryAttack and check if it's set inside SWEP:Think. if networking is an issue, use SetupDataTables and NetworkVar.
[QUOTE=MaximLaHaxim;49072396]hook.Add [url=http://wiki.garrysmod.com/page/GM/KeyPress]GM.KeyPress[/url] Or in [url=http://wiki.garrysmod.com/page/WEAPON/Think]SWEP.Think[/url] just use [url=http://wiki.garrysmod.com/page/Player/KeyDown]Player.KeyDown[/url]. A lot of SWEP codes I've read use the "hook.add and check if a player has this weapon" method, so don't worry, it isn't as sloppy as it seems. Just put some comments in so you don't forget what certain lines of code do. [editline]fucknuggets:([/editline] Now, for my own problem. [code]function GM:PreDrawHalos() local singletab = { LocalPlayer():GetNWEntity( "SelectedCombine" ) } if singletab[1] == NULL then print("nope") return end halo.Add( singletab, Color( 255, 0, 0 ), 5, 5, 1, true, true ) end[/code] Any idea why halos draw randomly sometimes even if GetNWEntity( "SelectedCombine" ) is NULL? And if the selected combine NWvar isn't NULL it randomly stops drawing then draws again some time after? Chances are it's the arguments I used for halo.Add; what should I change?[/QUOTE] Well for one you're overriding the gamemode function, so you may want to use hooks, [I]unless[/I] you're creating a gamemode, in which case I suppose this is fine. Second, rather than comparing the NWEntity to NULL, it may be better to do [lua]IsValid(singletab[1])[/lua]
[QUOTE=MaximLaHaxim;49058661]Anyone know how I could find the contents of a function? Like, if I had a function testfunc(), [code]function testfunc() MsgN("Herro Der!") end[/code] how would I somehow get a string that tells me what is in the function? i.e How would I create a function that would return "MsgN("Herro Der!")" if I ran it on testfunc?[/QUOTE] Not possible. Closest thing you can use is [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/string/dump]string.dump[/url], but that will return the bytecode of the function, which, unless, you're going to parse yourself, won't tell you an awful lot.
[QUOTE=Ndsbot;49073087]Is there a way to disable Knockback from taking damage?[/QUOTE] I know adjusting a player's weight makes a difference. I would assume there is a more direct approach, hopefully, but maybe this is useful to you as well.
:snip:
Could anyone help me with figuring out why using SetMaterial within SWEP:DrawWorldModel causes any models that are added to the player via Point-Shop to become re-textured? When viewing yourself at certain angles the re-texturing will disappear and reappear randomly, almost like a glitching texture. Any help or advice would be much appreciated. Function Example : [lua]function SWEP:DrawWorldModel() self:SetMaterial("models/weapons/w_shotgun/w_shotgun_custom") self:DrawModel() end[/lua] In-Game Result : [IMG]http://i.imgur.com/pBuKXaV.jpg[/IMG] [IMG]http://i.imgur.com/RsRgkJj.jpg[/IMG] Video Example : [video=youtube;XZHxdga4B-c]https://www.youtube.com/watch?v=XZHxdga4B-c[/video]
[code]function GM:PreDrawHalos() local singletab = { LocalPlayer():GetNWEntity( "SelectedCombine" ) } if singletab[1] == NULL || !IsValid(singletab[1]) then print("screwit") return end halo.Add( singletab, Color( 255, 0, 0 ), 5, 5, 2, true, true ) end[/code] Still get the same problem. This is the code which I use for selecting NPCs, by the way: [code]function GM:KeyPress( ply, keynum ) local ent = ply:GetEyeTrace().Entity if ply.CombTab and table.HasValue( ply.CombTab, ent ) then if ply:GetNWEntity( "SelectedCombine", NULL ) == NULL then ply:SetNWEntity( "SelectedCombine", ent ) else ply:SetNWEntity( "SelectedCombine", NULL ) -- sets to null if no arg is provided end end end[/code] This is the code I use for spawning entities. [code]function GM:Spawn_NPC( tab ) if !tab then debug.Trace() end if tab.ply and tab.class and tab.weapon and tab.pos then local ent = ents.Create( tab.class ) ent:SetPos( tab.pos ) --ent:AddRelationship( ) if tab.angles then ent:SetAngles( tab.angles ) end ent:Give( tab.weapon ) ent:Spawn() table.insert(tab.ply.CombTab, ent) end end[/code] [editline]8th November 2015[/editline] [QUOTE=Mka0207;49076013]Could anyone help me with figuring out why using SetMaterial within SWEP:DrawWorldModel causes any models that are added to the player via Point-Shop to become re-textured? When viewing yourself at certain angles the re-texturing will disappear and reappear randomly, almost like a glitching texture. Any help or advice would be much appreciated. Function Example : [lua]function SWEP:DrawWorldModel() self:SetMaterial("models/weapons/w_shotgun/w_shotgun_custom") self:DrawModel() end[/lua] In-Game Result : [IMG]http://i.imgur.com/pBuKXaV.jpg[/IMG] [IMG]http://i.imgur.com/RsRgkJj.jpg[/IMG] Video Example : [video=youtube;XZHxdga4B-c]https://www.youtube.com/watch?v=XZHxdga4B-c[/video][/QUOTE] Don't set the material every single frame, just use self.Owner:GetViewModel():SetMaterial( material ) once.
[QUOTE=Shenesis;49075198]If you want to disable knockback from bullet damage, you could try setting the bullet's damage to 0 and applying the damage in the [URL="http://wiki.garrysmod.com/page/Structures/Bullet"]bullet's callback[/URL][/QUOTE] This would still apply Knockback to the player. Also I don't want to directly change the Players health, because I need to edit the Damage Value in an [URL="http://wiki.garrysmod.com/page/GM/EntityTakeDamage"]EntityTakeDamage[/URL] hook.
I have a hud that does this: [lua]if ply:Alive() then local wep = ply:GetActiveWeapon() local wepAmmo = ply:GetAmmoCount( wep:GetPrimaryAmmoType() ) local wepClip1 = wep:Clip1() local wepClip1Size = 0 ect... [/lua] When the player dies I get these errors: [IMG]http://i.imgur.com/e5LOA8R.png[/IMG] Is there a way to stop checking ammo when the player dies? Also, I'm checking player ammo, health, ect. every frame. Is there a way to update the hud when the player's info changes rather than doing it every single frame?
[QUOTE=CaptainFaggot;49076652]I have a hud that does this: [lua]if ply:Alive() then local wep = ply:GetActiveWeapon() local wepAmmo = ply:GetAmmoCount( wep:GetPrimaryAmmoType() ) local wepClip1 = wep:Clip1() local wepClip1Size = 0 ect... [/lua] When the player dies I get these errors: [IMG]http://i.imgur.com/e5LOA8R.png[/IMG] Is there a way to stop checking ammo when the player dies? Also, I'm checking player ammo, health, ect. every frame. Is there a way to update the hud when the player's info changes rather than doing it every single frame?[/QUOTE] check if they're alive using :Alive(). checking ammo and health every frame won't have a noticable effect on performance.
[QUOTE=skullorz;49077075]check if they're alive using :Alive(). checking ammo and health every frame won't have a noticable effect on performance.[/QUOTE] He's already using Alive(). Anyways, CaptainFaggot, see if this works. [code]if ply:Alive() and ply:GetActiveWeapon().Clip1 and ply:GetActiveWeapon().GetPrimaryAmmoType then local wep = ply:GetActiveWeapon() local wepAmmo = ply:GetAmmoCount( wep:GetPrimaryAmmoType() ) local wepClip1 = wep:Clip1() local wepClip1Size = 0 ect... [/code]
[QUOTE=Revenge282;49058759]Adding on to this, I attempted to call the function using the [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/ShouldDrawLocalPlayer]GM/ShouldDrawLocalPlayer[/url] and it still is being called too soon for particles. [lua]hook.Add("ShouldDrawLocalPlayer","Test2",function(p) if !p.TestVar then p.TestVar=true print("test") for _,v in ipairs(ents.FindByClass("fire")) do print("Drawing "..tostring(v)) ParticleEffect("fire_large_01",v:GetPos(),Angle(0,0,0),v) end end end)[/lua] [code]OPL Fire (this is using the method that you provided) Signon traffic "CLIENT": incoming 89.351 KB, outgoing 1.990 KB Queued Material System: ENABLED! Compact freed 1372160 bytes CL INIT FIRE (this is the ENT:Initialize) Attempting to create unknown particle system 'WATERFALL' Redownloading all lightmaps R_RedownloadAllLightmaps took 282.849 msec! test (this is the ShouldDrawLocalPlayer hook) Drawing Entity [382][fire][/code][/QUOTE] To add to this, I can the particle effects immediately after joining the server, but after I have completely spawned (after that splash noise), the particles are removed.
[QUOTE=MaximLaHaxim;49076268] Don't set the material every single frame, just use self.Owner:GetViewModel():SetMaterial( material ) once.[/QUOTE] I am having this problem for when trying to set the world model texture not the SWEP's view model.
Sorry, you need to Log In to post a reply to this thread.