• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
[QUOTE=vexx21322;46236722]I wouldn't recommend using :IsValid() unless you know 100% that the variable can't be nil. Use IsValid(var).[/QUOTE] [lua]timer.Create("VehicleCheck", 1, 0, function() if not IsValid( tank1 ) then tank1 = ents.Create("sent_sakarias_car_abrams") tank1:SetPos(Vector(1984.000000, 192.000000, -3.750000)) tank1:Spawn() end end)[/lua] It spawns 1 tank, like it should, but after the tank is destroyed one isn't spawned again. (no errors ofc)
I'm trying to solve this ancient issue that has been occuring ENT:Use does not work for some reason, and I don't fucking know why. is it because of my physicsint or what? [code] function ENT:Initialize() self:SetModel("models/weapons/w_c4_planted.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) self:SetUseType(CONTINUOUS_USE) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() phys:SetBuoyancyRatio(0) end self.Delay = CurTime() + 30 self.First = true end function ENT:Use(activator, caller) print(activator:Nick() .. " is a pretty cool guy") end [/code]
[QUOTE=ROFLBURGER;46234708]Does anyone know how to make render.DrawSprite render over other props? [editline]14th October 2014[/editline] like this is what's happening [t]http://i.imgur.com/y4nLiSN.jpg[/t][/QUOTE] Make sure you don't have IgnoreZ enabled for the material; that can cause issues sometimes. [QUOTE=WalkingZombie;46235784]I said functions, not variables. Thanks for an answer though[/QUOTE] [QUOTE=BFG9000;46235389]Just check for the index. [editline]14th October 2014[/editline] if YourWeaponHere.Whateverthefuck then return end[/QUOTE] [QUOTE=WalkingZombie;46235374]I want to check and see if a weapon has a function. Does the weapon have :Whateverthefuck() ? Yes = True, No = False[/QUOTE] Lua is a language of tables; . will return something by "reference" but can still be used to call by adding ( ). : is used for calls and requires a ( ). When using a : defined function, self is inferred as the first argument, so if you want to call ply:GetVelocity( ) using the "reference", then self must be added; ie: ply.GetVelocity( ply ). If you want to check to see if a function exists, you need to check the variable reference pointing to the function; ie . This is an example of a Ternary Operation; shorthand for defining a local var, if cond then alter value. So, _vel = ply:GetVelocity( ), only if ply.GetVelocity exists, otherwise it is 0. local _vel = ( ply.GetVelocity ) && ply:GetVelocity( ) || 0; Instead of a rude response when someone helps you, why not ask them why it works that way? For example, you can make global "variable-variables" by altering the global table directly... [code]for i = 1, 10 do _G[ "varvar_" .. i ] = i * 100; end print( varvar_1 ); -- 100 print( varvar_10 ); -- 1000[/code] And there are lots of other interesting things that can be done by looking outside the box.
[QUOTE=Acecool;46237632]Make sure you don't have IgnoreZ enabled for the material; that can cause issues sometimes.[/QUOTE] Do you mean in the VTF/VMT or is there a lua command? I thought IgnoreZ drew threw walls and whatnot, and the material does not.
[QUOTE=ROFLBURGER;46237812]Do you mean in the VTF/VMT or is there a lua command? I thought IgnoreZ drew threw walls and whatnot, and the material does not.[/QUOTE] IgnoreZ has nothing to do with it, all you have to do is make sure your sprites are rendered after all opaque entities. - If they are rendered by an entity, use ENT:DrawTranslucent instead of ENT:Draw (and make sure the rendergroup is set to RENDERGROUP_BOTH) - If they are rendered by a gamemode hook, use Pre/PostDrawTranslucentRenderables instead of Pre/PostDrawOpaqueRenderables - If they are rendered by an effect, you can't do anything about it and it would be just better to use particle emitters instead - If they are rendered by anything else, you're most likely doing it wrong
a question about mounting with gamemodes. How exactly are gamemodes mounted? Since i try to include an lib, which i got in GAMEMODENAME/gamemode/lib inside an Entity, which is in GAMEMODENAME/entities/entities. if it isn't mounted, it should be ../../gamemode/lib/luaname.lua, right? edit:// i think i will just network everything. that would be easier.
[QUOTE=Tomelyr;46238762]a question about mounting with gamemodes. How exactly are gamemodes mounted? Since i try to include an lib, which i got in GAMEMODENAME/gamemode/lib inside an Entity, which is in GAMEMODENAME/entities/entities. if it isn't mounted, it should be ../../gamemode/lib/luaname.lua, right? edit:// i think i will just network everything. that would be easier.[/QUOTE] Isn't everything mounted into the root? so gamemode/entities/entityname is just in lua/entities/entityname?
Hey, so I'm working on a thing to give players a random gender, either male or female upon spawning. I was wondering the best way to do this and upon some thought/suggestions, decided to use GetNWBool to do it. The thing is, it's always returning 1 here when I spawn, and always making me male. Is this the best way to be going about this, and if so, what am I doing wrong? Everything looks fine to me here [code] //Gender GENDER_MALE = 1 GENDER_FEMALE = 0 function GM:PlayerSpawn(ply) local gender = math.random(GENDER_MALE, GENDER_FEMALE) ply:SetNWBool("Player_Gender", gender) print(gender) if ply:GetNWBool("Player_Gender") then ply:ChatPrint("You're male!") ply:SetModel(table.Random(NiandraLades.MaleModels)) else ply:ChatPrint("You're female!") ply:SetModel(table.Random(NiandraLades.FemaleModels)) end end [/code] I also just placed the print and math.random into a think hook and low and behold: [IMG]http://i.imgur.com/8Nwbp3Il.png[/IMG]
[QUOTE=NiandraLades;46241037]Hey, so I'm working on a thing to give players a random gender, either male or female upon spawning. I was wondering the best way to do this and upon some thought/suggestions, decided to use GetNWBool to do it. The thing is, it's always returning 1 here when I spawn, and always making me male. Is this the best way to be going about this, and if so, what am I doing wrong? Everything looks fine to me here [code] //Gender GENDER_MALE = 1 GENDER_FEMALE = 0 function GM:PlayerSpawn(ply) local gender = math.random(GENDER_MALE, GENDER_FEMALE) ply:SetNWBool("Player_Gender", gender) print(gender) if ply:GetNWBool("Player_Gender") then ply:ChatPrint("You're male!") ply:SetModel(table.Random(NiandraLades.MaleModels)) else ply:ChatPrint("You're female!") ply:SetModel(table.Random(NiandraLades.FemaleModels)) end end [/code] I also just placed the print and math.random into a think hook and low and behold: [IMG]http://i.imgur.com/8Nwbp3Il.png[/IMG][/QUOTE] 0 is evaluated as true by Lua when treated as a boolean. The tobool function has more desirable behaviour in this case: [code] local gender = tobool( math.random(GENDER_MALE, GENDER_FEMALE) ) [/code] Alternatively just use conditional logic like so: [code] local gender = math.random(0, 1) == 0 and true or false [/code] Or even more fun! [code] GENDER_MALE = 1 GENDER_FEMALE = 0 local models = { [GENDER_FEMALE] = {"model1", "model2"}, [GENDER_MALE] = {"model1", "model2"} } local gender = math.random(GENDER_FEMALE, GENDER_MALE) local model = table.Random(models[gender]) [/code]
OH shit, yeah, I remember Garry saying on a blogpost he disliked lua because of that, but it didn't cross my mind The tobool one works, thank you very much! Although gmod's random features continues to print heavily in favour of one result but that seems to occur with a lot of stuff like this :v: [editline]15th October 2014[/editline] That is quite an interesting method of doing it, I shall experiment around!
[del]Does anyone know why RenderView is affected by the halo library, and turns the whole rendertarget black?[/del] Edit: Upon further testing, I have found out that this only happens when using render.PushCustomClipPlane. Removing these calls from the code below results in a perfectly fine result. Is custom clip planes interfering with halos or RenderView (or both?) [video=youtube;Nwe5NRr_W14]http://www.youtube.com/watch?v=Nwe5NRr_W14[/video] The stencil buffer is not what is causing this, I show this later in the video. The code for the renderView is right here: [code] local oldRT = render.GetRenderTarget() render.SetRenderTarget( portal:GetTexture() ) render.Clear( 0, 0, 0, 255 ) render.ClearDepth() render.ClearStencil() render.EnableClipping(true) render.PushCustomClipPlane( exitPortal:GetForward(), exitPortal:GetForward():Dot(exitPortal:GetPos() - (exitPortal:GetForward() *0.5) ) ) worldportals.drawing = true render.RenderView( { x = 0, y = 0, w = ScrW(), h = ScrH(), origin = camOrigin, angles = camAngles, drawpostprocess = true, drawhud = false, drawmonitors = false, drawviewmodel = false, } ) worldportals.drawing = false render.PopCustomClipPlane() render.EnableClipping(false) render.SetRenderTarget( oldRT ) [/code]
[QUOTE=Metamist;46241245]Does anyone know why RenderView is affected by the halo library, and turns the whole rendertarget black?[/code][/QUOTE] Have you tested this on the dev branch? The halo lib's rendering has changed quite a bit.
[QUOTE=RonanZer0;46236762][lua]timer.Create("VehicleCheck", 1, 0, function() if not IsValid( tank1 ) then tank1 = ents.Create("sent_sakarias_car_abrams") tank1:SetPos(Vector(1984.000000, 192.000000, -3.750000)) tank1:Spawn() end end)[/lua] It spawns 1 tank, like it should, but after the tank is destroyed one isn't spawned again. (no errors ofc)[/QUOTE] 'hey hey hey'
[QUOTE=Willox;46241264]Have you tested this on the dev branch? The halo lib's rendering has changed quite a bit.[/QUOTE] No, I have not, will try it and report back. Edit: Confirmed, this happens on the dev branch as well.
I'm trying to convert a version of the Flechette Gun to TTT, and make it work without HL2:Ep2 mounted. I've packed the need models, materials, and particles into the addon, but my final issue is that whenever I fire the weapon, I get this error, and the flechettes appear sideways regardless as to where they were fired from; [code]Bad sequence (-2 out of 2 max) in GetSequenceLinearMotion() for model 'weapons\Hunter_flechette.mdl'![/code] What am I missing?
[QUOTE=Metamist;46241300]No, I have not, will try it and report back. Edit: Confirmed, this happens on the dev branch as well.[/QUOTE] If you can send some code that reproduces it (on Steam if you wish) I'll look in to sorting it out.
[QUOTE=_Kilburn;46238047]IgnoreZ has nothing to do with it, all you have to do is make sure your sprites are rendered after all opaque entities. - If they are rendered by an entity, use ENT:DrawTranslucent instead of ENT:Draw (and make sure the rendergroup is set to RENDERGROUP_BOTH) - If they are rendered by a gamemode hook, use Pre/PostDrawTranslucentRenderables instead of Pre/PostDrawOpaqueRenderables - If they are rendered by an effect, you can't do anything about it and it would be just better to use particle emitters instead - If they are rendered by anything else, you're most likely doing it wrong[/QUOTE] Yeah I'm using a no gravity entity for a particle. I'm using ENT:Draw(), I'll change it to DrawTranslucent
[QUOTE=WitheredPyre;46241347]I'm trying to convert a version of the Flechette Gun to TTT, and make it work without HL2:Ep2 mounted. I've packed the need models, materials, and particles into the addon, but my final issue is that whenever I fire the weapon, I get this error, and the flechettes appear sideways regardless as to where they were fired from; [code]Bad sequence (-2 out of 2 max) in GetSequenceLinearMotion() for model 'weapons\Hunter_flechette.mdl'![/code] What am I missing?[/QUOTE] is the flechette model on the server too?
[QUOTE=NiandraLades;46241179]OH shit, yeah, I remember Garry saying on a blogpost he disliked lua because of that, but it didn't cross my mind The tobool one works, thank you very much! Although gmod's random features continues to print heavily in favour of one result but that seems to occur with a lot of stuff like this :v: [editline]15th October 2014[/editline] That is quite an interesting method of doing it, I shall experiment around![/QUOTE] [url]http://wiki.garrysmod.com/page/math/randomseed[/url] math.randomseed( os.time() )
Anyone know how to prevent an entity from being hit by a bullet? What I mean is that the bullet goes straight through the entity like it's not there. [QUOTE=ROFLBURGER;46237027]I'm trying to solve this ancient issue that has been occuring ENT:Use does not work for some reason, and I don't fucking know why. is it because of my physicsint or what? [code] function ENT:Initialize() self:SetModel("models/weapons/w_c4_planted.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) self:SetUseType(CONTINUOUS_USE) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() phys:SetBuoyancyRatio(0) end self.Delay = CurTime() + 30 self.First = true end function ENT:Use(activator, caller) print(activator:Nick() .. " is a pretty cool guy") end [/code][/QUOTE] Anyone?
Can someone help me with particle systems? I am trying to use a particle system in my game but cant seem to get it to work without errors :( My serverside code on the Gamemode is [code] PrecacheParticleSystem("devtest.pcf") PrecacheParticleSystem("advisor.pcf") [/code] And in a clientside file I have this. [code] ParticleEffect("test_lighting",Vector(-1008.854370,1594.918457,-2494.968750),Angle(0,0,0)) ParticleEffect("advisor_object_charge_bits",Vector(-1008.854370,1594.918457,-2494.968750),Angle(0,0,0)) [/code] My console shows these errors [code] Attemped to precache unknown particle system "test_lighting"! Attemped to precache unknown particle system "advisor_object_charge_bits"! [/code]
[b]Edit:[/b] Fixed it. Had to send the idle animation after the reloading is finished. So, for some reason the first time the reload animation plays on my gun - it works fine. But any time after that; it seems to bug out about 50% of the time and not play (it does seem to "flicker" to the animation or something though). Does anyone know why this would be? Is it a problem with the model? I am not using the DefaultReload function for this. [video=youtube;_CjPYcpJB6s]http://www.youtube.com/watch?v=_CjPYcpJB6s[/video] (ignore me shaking around in the video, that was me trying to emphasize the issue)
[QUOTE=a-cookie;46242421]is the flechette model on the server too?[/QUOTE] I'm testing it via a local server, should I expect it to work properly if it's loaded as an addon on the server, too?
Is there anyway to change the volume of a sound played using surface.PlaySound or make sound.Play heard everywhere or somehow follow a player's position? I really just need volume control for sounds that aren't positioned or anything.
[QUOTE=zeaga;46246286]Is there anyway to change the volume of a sound played using surface.PlaySound or make sound.Play heard everywhere or somehow follow a player's position? I really just need volume control for sounds that aren't positioned or anything.[/QUOTE] I had this problem yesterday. Just create multiple instances of it, I made sound.Play be called 5 times at once, it DEFINITELY makes it much louder.
[QUOTE=RonanZer0;46246425]I had this problem yesterday. Just create multiple instances of it, I made sound.Play be called 5 times at once, it DEFINITELY makes it much louder.[/QUOTE] I don't want it to be louder, and I definitely want a lot more control over the volume that just stacking the same sound.
[QUOTE=zeaga;46246487]I don't want it to be louder, and I definitely want a lot more control over the volume that just stacking the same sound.[/QUOTE] If you don't want it louder than the 0-1 scale, what's your problem? Just... Just set the volume like normal, I'm 99% it's in the function of sound.Play.
[QUOTE=RonanZer0;46246628]If you don't want it louder than the 0-1 scale, what's your problem? Just... Just set the volume like normal, I'm 99% it's in the function of sound.Play.[/QUOTE] Because like I said, I don't want it to be played at a certain position in the world. I want it to act like surface.PlaySound. If regular sound.Play can achieve this, please let me know, because I'm not aware.
[QUOTE=zeaga;46246818]Because like I said, I don't want it to be played at a certain position in the world. I want it to act like surface.PlaySound. If regular sound.Play can achieve this, please let me know, because I'm not aware.[/QUOTE] If I recall correctly, I think I remember Robotboy saying setting the sound level to 0 for sound.Play will achieve the effect you're seeking.
[QUOTE=Jeezy;46246855]If I recall correctly, I think I remember Robotboy saying setting the sound level to 0 for sound.Play will achieve the effect you're seeking.[/QUOTE] That works! Thank you so much!
Sorry, you need to Log In to post a reply to this thread.