1. Post #2361
    Pandaman09's Avatar
    January 2012
    1,278 Posts
    Did you set the use mode to SIMPLE_USE?
    self:SetUseType( SIMPLE_USE )
    
    ENT:Use() is also a server only hook

    http://wiki.garrysmod.com/page/Entity/SetUseType
    Reply With Quote Edit / Delete Show Events Informative Informative x 1 (list)

  2. Post #2362
    RalphORama's Avatar
    January 2011
    57 Posts
    I'm trying to make a custom job in DarkRP (a Riot Police team) that's only available when the mayor has initiated a lockdown. I'm trying to do so with customCheck, but I can't get the class become available when a lockdown is underway. No errors are thrown back, the class just can't be switched to, even if there is a lockdown.
    Code:
    customCheck = function(ply) if SERVER then if DarkRP.lockdown() then return true end end end,
    CustomCheckFailMsg = "There's no lockdown right now!"
    Also, is there a way that I can make the class be demoted back to the CP team when unLockdown() is called?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  3. Post #2363
    Gold Member
    unrezt's Avatar
    August 2009
    2,539 Posts
    How do I get the imaterial SetShader function to work? I have tried it with various materials (both png and normal) and shader types.

    Code:
    local mat = Material("phoenix_storms/stripes")
    print(mat:GetShader())
    
    mat:SetShader("unlitgeneric")
    print(mat:GetShader())
    
    
    prints
    
    VertexLitGeneric
    VertexLitGeneric
    Edited:
    Nvm, it was removed apparently, damnit.
    Reply With Quote Edit / Delete Show Events

  4. Post #2364
    Acecool discovered a way to get classes working in Lua; MetaTable users hate him, ArmA devs love him

    February 2012
    5,839 Posts
    Still NO luck whatsoever.
    Add me on Steam; when I get my dev-server back up ( tier0.dll issue ) I'll take a look. I'm pretty sure it should work fine unless it's a legs-mod issue; and with the vehicle I'm not sure, I'll have to look at see if it's messed up on mine.

    Are you overwriting the two hooks for player getting in vehicle, or the animations.lua file?

    Edited:

    I'm trying to make a custom job in DarkRP (a Riot Police team) that's only available when the mayor has initiated a lockdown. I'm trying to do so with customCheck, but I can't get the class become available when a lockdown is underway. No errors are thrown back, the class just can't be switched to, even if there is a lockdown.
    Code:
    customCheck = function(ply) if SERVER then if DarkRP.lockdown() then return true end end end,
    CustomCheckFailMsg = "There's no lockdown right now!"
    Also, is there a way that I can make the class be demoted back to the CP team when unLockdown() is called?
    Here's the DarkRP Help Thread: http://facepunch.com/showthread.php?t=1249475

    You could just do return !DarkRP.lockdown( ) or return !DarkRP:lockdown( ) depending how it's written.

    By returning the inverse, if there is a lockdown it returns false meaning they can't join.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  5. Post #2365
    RalphORama's Avatar
    January 2011
    57 Posts
    Oh god, where's that been all my life? I'll use that from now on. (Right in front of my face, but I have a habit of not seeing the obvious.)

    You could just do return !DarkRP.lockdown( ) or return !DarkRP:lockdown( ) depending how it's written.

    By returning the inverse, if there is a lockdown it returns false meaning they can't join.
    I'm shooting for the inverse, the class is only available if there is a lockdown. I'm assuming I can just use the following, and it should work fine?
    Code:
    customCheck = function(ply) return DarkRP.lockdown() end,
    CustomCheckFailMsg = "There's no lockdown right now!"
    Reply With Quote Edit / Delete Linux United States Show Events Friendly Friendly x 1 (list)

  6. Post #2366
    Acecool discovered a way to get classes working in Lua; MetaTable users hate him, ArmA devs love him

    February 2012
    5,839 Posts
    Oh god, where's that been all my life? I'll use that from now on. (Right in front of my face, but I have a habit of not seeing the obvious.)


    I'm shooting for the inverse, the class is only available if there is a lockdown. I'm assuming I can just use the following, and it should work fine?
    Code:
    customCheck = function(ply) return DarkRP.lockdown() end,
    CustomCheckFailMsg = "There's no lockdown right now!"
    I don't run DarkRP so I wouldn't know regarding all of it; but that should work fine.

    I also recommend using ;s everywhere instead of commas for tables, etc that you add.

    Reason being is if you make a table and the last element has a comma, it'll error. With a ; it won't. See: https://dl.dropboxusercontent.com/u/...dards.lua.html

    That's just my personal preference; but meh..

    Anyway for some additional DarkRP help, see: http://wiki.darkrp.com/index.php/Main_Page and http://wiki.darkrp.com/index.php/DarkRP:CustomJobFields for job fields
    Reply With Quote Edit / Delete Windows 7 United States Show Events Disagree Disagree x 3Funny Funny x 1Dumb Dumb x 1 (list)

  7. Post #2367
    Gold Member

    March 2012
    2,311 Posts
    Reason being is if you make a table and the last element has a comma, it'll error. With a ; it won't.
    That's actually incorrect. Lua will happily accept a comma at the end of the last element without any error.

    -- Valid syntax
    local t = {
        this = "something",
        that = 98,
    }
    
    Reply With Quote Edit / Delete United Kingdom Show Events Agree Agree x 2Friendly Friendly x 1 (list)

  8. Post #2368
    Acecool discovered a way to get classes working in Lua; MetaTable users hate him, ArmA devs love him

    February 2012
    5,839 Posts
    That's actually incorrect. Lua will happily accept a comma at the end of the last element without any error.

    -- Valid syntax
    local t = {
        this = "something",
        that = 98,
    }
    
    Insteresting; I've actually seen cases where a comma has given an error. I'll have to look at the code I have stored once I get my srcds running again, but there is one case where a comma will error and a semi-colon will not. I can't remember if it's if you pass a table to a function, or net.WriteTable, or something.
    Reply With Quote Edit / Delete Show Events Dumb Dumb x 1 (list)

  9. Post #2369

    January 2014
    43 Posts
    Insteresting; I've actually seen cases where a comma has given an error. I'll have to look at the code I have stored once I get my srcds running again, but there is one case where a comma will error and a semi-colon will not. I can't remember if it's if you pass a table to a function, or net.WriteTable, or something.
    In my recent experience a comma at the end will generate an error when initializing tables without field names, i.e.
    Code:
    -- will error so use commas with care
    local names = {
         "Adam",
         "Ben",
    }
    Edit: Thanks for proving me wrong. I normally would check it myself before posting something I just assumed from my apparently untrustworthy memory.
    Reply With Quote Edit / Delete Show Events Disagree Disagree x 7 (list)

  10. Post #2370

    March 2014
    122 Posts
    In my recent experience a comma at the end will generate an error when initializing tables without field names, i.e.
    Code:
    -- will error so use commas with care
    local names = {
         "Adam",
         "Ben",
    }
    Reply With Quote Edit / Delete Show Events Agree Agree x 3 (list)

  11. Post #2371
    Dennab
    March 2011
    980 Posts
    I have a question about lua... It's probably kind of dumb so I'm sorry.

    I understand the way it works but how do you KNOW what can and actually can be used, as in what actually exists as something you can use in your code?

    Like for example in the creation of an swep, one thing is

    "SWEP.Primary.ClipSize = -1"

    How would you otherwise know that "SWEP.Primary.ClipSize" is even something that exists and is what you would type in to have it do whatever function it is that it does as opposed to say, typing in something like

    "GunMagCount = 3" blindly, which probably doesnt do anything because it probably doesn't exist.

    Edited:

    Or like "Ply"
    How would I know without reading it somewhere that "Ply" is something that exists and that it means "Player", and then how would I know how/where to use it?
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  12. Post #2372
    WalkingZombie's Avatar
    June 2013
    1,182 Posts
    I have a question about lua... It's probably kind of dumb so I'm sorry.

    I understand the way it works but how do you KNOW what can and actually can be used, as in what actually exists as something you can use in your code?

    Like for example in the creation of an swep, one thing is

    "SWEP.Primary.ClipSize = -1"

    How would you otherwise know that "SWEP.Primary.ClipSize" is even something that exists and is what you would type in to have it do whatever function it is that it does as opposed to say, typing in something like

    "GunMagCount = 3" blindly, which probably doesnt do anything because it probably doesn't exist.

    Edited:

    Or like "Ply"
    How would I know without reading it somewhere that "Ply" is something that exists and that it means "Player", and then how would I know how/where to use it?
    "ply" is usually used to represent the player entity, but anything can really be used in that case.

    As for SWEP.Primary.ClipSize, well... you could do guess work, or you can read.



    I need an entity to be: Usable ( +use default E ), Touchable, and Shoot-able, all without interfering with the player's movement.
    Reply With Quote Edit / Delete Show Events

  13. Post #2373
    Dennab
    March 2011
    980 Posts
    "ply" is usually used to represent the player entity, but anything can really be used in that case.

    As for SWEP.Primary.ClipSize, well... you could do guess work, or you can read.



    I need an entity to be: Usable ( +use default E ), Touchable, and Shoot-able, all without interfering with the player's movement.
    You didn't even read the question, did you?...
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  14. Post #2374
    WalkingZombie's Avatar
    June 2013
    1,182 Posts
    I did... and uh, what I got was you didn't understand how you should know certain variable names without looking them up, that's at least what I caught

    Edited:

    Oh, and the bold underline at the bottom was and is my own problem.

    I need an entity to be: Usable ( +use default E ), Touchable, and Shoot-able, all without interfering with the player's movement.
    (basically, it runs a function when it's used, when it would be touched, and when it gets shot, but it doesn't really collide with anything)

    Imagine an Antlion Grub that you could use like a button
    Reply With Quote Edit / Delete Show Events Dumb Dumb x 1 (list)

  15. Post #2375
    Dennab
    March 2011
    980 Posts
    I did... and uh, what I got was you didn't understand how you should know certain variable names without looking them up, that's at least what I caught

    Edited:

    Oh, and the bold underline at the bottom was and is my own problem.

    I need an entity to be: Usable ( +use default E ), Touchable, and Shoot-able, all without interfering with the player's movement.
    Here is what you said:
    ""ply" is usually used to represent the player entity, but anything can really be used in that case.

    As for SWEP.Primary.ClipSize, well... you could do guess work, or you can read."

    I never asked for someone to tell me what 'ply' represents or what SWEP.Primary.ClipSize means. In fact I even show that I already know what it means in my original post. I asked how I should know of the existence of these sorts of things, as in what would do what, and what WOULDN'T do that.

    So to explain it again in a new fashion, for example let's say I were making a weapon and wanted it to play a sound. You'd use something like self:EmitSound( ShootSound ) ((I know what that is and I know what it does, so you don't make this mistake again, I'm not asking what self:EmitSound does...))
    But how would I know that self:EmitSound is actually the thing I should type in to make it do that?
    Otherwise I'd be blindly typing something in like Playsound:Gun or something like that which isn't a real thing. Albeit in english saying to do the same thing, is not what would be used to make it happen in code. How would I know that self:EmitSound exists and that it is what I'd use for this
    Reply With Quote Edit / Delete Windows 7 Show Events

  16. Post #2376

    March 2014
    122 Posts
    Or like "Ply"
    How would I know without reading it somewhere that "Ply" is something that exists and that it means "Player", and then how would I know how/where to use it?
    You go to the wiki, look for what order the parameters are in, and put your arguments in that order.

    Let's use an example here.



    It takes a string and it takes a function. There are other things but those are optional. One step at a time. First parameter is a string. Easy enough.



    The second parameter is a function, and I know you'll be wondering what is supposed to go there.



    If we look further down the page we see that the function should have these parameters (you don't HAVE to use any of the parameters, though).



    Parameter names can be arbitrary, but it's a good idea to name the parameters after what they represent. No one wants to look at your code and see a parameter named shit because it doesn't really make sense. Name your parameters after what should go in as the argument. The first parameter is a player so we named it player.





    Those functions both do the same thing. The only thing that actually matters is the order that they are in. Since the first parameter was named player, we know that it is now a valid variable to use in the function.
    Reply With Quote Edit / Delete Windows 7 Show Events Friendly Friendly x 1 (list)

  17. Post #2377
    WalkingZombie's Avatar
    June 2013
    1,182 Posts
    no, for as far as I'm aware ply is nothing but a personally chosen variable.

    so... basically the answer is, don't be stupid. If you didn't know what you needed to do you could look it up, but if you understand the way code works you'd eventually guess it.

    In the case that you're really having trouble figuring anything out for real, I recommend getting syntax highlighting installed into your text editor if it's actually difficult for you.

    Here I only know of one major problem, the official garry's mod wiki has a god awful search function. I hate the way it's lain out. Because of this I use http://maurits.tv/data/garrysmod/wiki/ since when you search it's more likely to find the right answer to your request.

    Edited:

    I knew as soon as I saw brandonj4's name at the bottom of the page that I was going to get AT LEAST ONE dumb rating.

    Edited:

    just a general tip to you GoldenTWM, if you really need to do a search to find what you need, and http://wiki.garrysmod.com/ is being a stuck-up bitch about it, then use the link above in this post.
    Reply With Quote Edit / Delete United States Show Events Dumb Dumb x 3 (list)

  18. Post #2378
    Dennab
    March 2011
    980 Posts
    no, for as far as I'm aware ply is nothing but a personally chosen variable.

    so... basically the answer is, don't be stupid. If you didn't know what you needed to do you could look it up, but if you understand the way code works you'd eventually guess it.

    In the case that you're really having trouble figuring anything out for real, I recommend getting syntax highlighting installed into your text editor if it's actually difficult for you.

    Here I only know of one major problem, the official garry's mod wiki has a god awful search function. I hate the way it's lain out. Because of this I use http://maurits.tv/data/garrysmod/wiki/ since when you search it's more likely to find the right answer to your request.

    Edited:

    I knew as soon as I saw brandonj4's name at the bottom of the page that I was going to get AT LEAST ONE dumb rating.

    Edited:

    just a general tip to you GoldenTWM, if you really need to do a search to find what you need, and http://wiki.garrysmod.com/ is being a stuck-up bitch about it, then use the link above in this post.
    You failed to even be RELEVANT to a simple question 3 times in a row, but thanks anyway man. I'll just go back to the programming section, this is why nobody ever wants to come to the gmod section.

    And to BayLife, thanks that helped a bit but it wasn't exactly what I meant. I wasn't talking about specifics such as ply, thats just an example. very detailed and well explained post though, I appreciate it
    Reply With Quote Edit / Delete Windows 7 Canada Show Events Dumb Dumb x 4Friendly Friendly x 1 (list)

  19. Post #2379
    WalkingZombie's Avatar
    June 2013
    1,182 Posts
    You failed to even be RELEVANT to a simple question 3 times in a row, but thanks anyway man. I'll just go back to the programming section, this is why nobody ever wants to come to the gmod section.

    And to BayLife, thanks that helped a bit but it wasn't exactly what I meant. I wasn't talking about specifics such as ply, thats just an example. very detailed and well explained post though, I appreciate it
    oh come on man, then your question is hardly obvious. I'm not even the only person to fail at understanding it apparently.
    Reply With Quote Edit / Delete United States Show Events Agree Agree x 3 (list)

  20. Post #2380
    Dennab
    March 2011
    980 Posts
    I just asked my friend so nevermind it's all good now
    Reply With Quote Edit / Delete Windows 7 Canada Show Events Funny Funny x 1 (list)

  21. Post #2381
    WalkingZombie's Avatar
    June 2013
    1,182 Posts
    I'm confused...
    Reply With Quote Edit / Delete Show Events

  22. Post #2382
    Acecool discovered a way to get classes working in Lua; MetaTable users hate him, ArmA devs love him

    February 2012
    5,839 Posts
    I have a question about lua... It's probably kind of dumb so I'm sorry.

    I understand the way it works but how do you KNOW what can and actually can be used, as in what actually exists as something you can use in your code?

    Like for example in the creation of an swep, one thing is

    "SWEP.Primary.ClipSize = -1"

    How would you otherwise know that "SWEP.Primary.ClipSize" is even something that exists and is what you would type in to have it do whatever function it is that it does as opposed to say, typing in something like

    "GunMagCount = 3" blindly, which probably doesnt do anything because it probably doesn't exist.

    Edited:

    Or like "Ply"
    How would I know without reading it somewhere that "Ply" is something that exists and that it means "Player", and then how would I know how/where to use it?
    Alright, so objects / meta-tables, or classes such as SWEPs are initialized in the back-end. Anything that is in the file as SWEP. is imported into the Weapons table, kind of like you defining local PANEL = { }; and building a vgui element, then registering it.

    Instead of manually registering a SWEP ( even though it can be done if you don't want to use the swep dir ), anything with the SWEP prefix will be available in SWEP functions.

    You can also define alternative local files, and they'll follow scope of the file. So, if you define local GunMagCount = 3; at the top of a swep file, say CanPrimaryAttack, and inside SWEP:CanPrimaryAttack you check GunMagCount; you can read it.

    Now, there is something important to know, you can define SWEP functions, and any other meta-table or GM, or whatever functions two ways and they'll be absolutely identical.


    function SWEP.CanPrimaryAttack( self )
    	// This is the same as
    	return self:Clip1( ) > 0;
    
    	// This, and this is the same as
    	--return self.Clip1( self ) > 0;
    end
    
    // Just like this is the same as the function above
    function SWEP:CanPrimaryAttack( )
    	// This is the same as
    	return self:Clip1( ) > 0;
    
    	// This, and this is the same as
    	--return self.Clip1( self ) > 0;
    end

    I commented one return because you can only have one or you'll get an error.

    So, scope, what is it and how does it work?

    Scope can be described as what a segment of code being executed has access to.

    This example will print nil, because the local variable is defined within the scope of the if; it's not seen by the print even though it's defined before it.
    if ( true ) then
    	local _ammo = 30;
    end
    print( _ammo );

    The same is for this, but we defined _ammo before-hand you say? Yes, but we also defined a difference instance of _ammo within the if.
    local _ammo;
    if ( true ) then
    	local _ammo = 30;
    end
    print( _ammo );

    Now it will print 30, the reason being is the scope is on the same level as the print. If we tried printing _ammo in a different file, it'd fail because they can't see locals from other files.
    local _ammo;
    if ( true ) then
    	_ammo = 30;
    end
    print( _ammo );

    I hope this helps.


    Quick addition: To simulate different Lua files within one file we can use a do. Load order will always be linear, so one after the other.


    File 1 will print properly, file 2 will not because its outside the scope of the file.
    // File 1
    do
    	local _ammo;
    	if ( true ) then
    		_ammo = 30;
    	end
    	print( _ammo );
    end
    
    // File 2
    do
    	print( _ammo );
    end
    

    Hopefully that puts things into better perspective in terms of separate files.
    Reply With Quote Edit / Delete Show Events

  23. Post #2383
    residualgrub's Avatar
    May 2011
    729 Posts
    I am having a really hard time getting the position of an attachment on a view model in sp. I am trying to grab it clientside because I am mocking shell ejection with clientside models. When I attempt to get the position of the attachment it sometimes returns the pos of the attachment but most of the time it returns something like 32,32,32. Any idea why it does this? I can't figure out why and its driving me insane.
    Reply With Quote Edit / Delete Show Events

  24. Post #2384
    Don't PM me about moderation - PM any of the mods.
    Robotboy655's Avatar
    May 2008
    15,875 Posts
    How does one attach lua particles to an entity? So that they are not affected by entity moving at high speeds?
    Reply With Quote Edit / Delete Show Events

  25. Post #2385

    December 2013
    1,797 Posts
    Is there a way to detect mouse wheel movement up and down?

    As well, how would I replace the $basetexture of a weapon's scope lens?
    Reply With Quote Edit / Delete Windows 7 Poland Show Events

  26. Post #2386
    Reply With Quote Edit / Delete Show Events Informative Informative x 1 (list)

  27. Post #2387

    December 2013
    1,797 Posts
    Thank you. Does anyone know of an answer to my second question?
    Reply With Quote Edit / Delete Show Events

  28. Post #2388
    Nova Prospekt's Avatar
    January 2009
    241 Posts
    How can I extract values from the entity returned by game:GetWorld()?

    More specifically, the bool for "World is Cold" (coldworld)
    Reply With Quote Edit / Delete Show Events

  29. Post #2389
    Acecool discovered a way to get classes working in Lua; MetaTable users hate him, ArmA devs love him

    February 2012
    5,839 Posts
    How does one attach lua particles to an entity? So that they are not affected by entity moving at high speeds?
    Typically it's supposed to be done in a PostDrawMethod; but because particles have a life-time, gravity, and other effects they're spawned in the world and don't keep the relation unless you manually create the effect and update the position based on the deltas and the current location; it ceases to being an "effect".

    Now, you could use the effect Lua files, and keep track of each particle you make, instead of relying on the built-in functions to update you could do it in the effect think foreach particle created...

    Is there a way to detect mouse wheel movement up and down?

    As well, how would I replace the $basetexture of a weapon's scope lens?
    Use CreateMove; it is more reliable than input.IsMouseDown.

    hook.Add( "CreateMove", "CreateMove:MouseWheelCheck", function( _cmd )
    	local _wheel = _cmd:GetMouseWheel( );
    	if ( _wheel != 0 ) then
    		print( _wheel );
    	end
    end );

    To replace the texture, you'd need to find the exact texture. Use +mat_texture_list to show the list of textures; then work through getting the texture, saving a reference if you want to switch back, and overwriting $basetexture on the old with the new.

    How can I extract values from the entity returned by game:GetWorld()?

    More specifically, the bool for "World is Cold" (coldworld)
    On either Client or Server it'll return NULL, or empty entity if I recall correctly. I personally store worldspawn values in a list at index 0, actually I store all entity values in a list using the EntIndex as the key.
    Reply With Quote Edit / Delete Windows 7 United States Show Events Dumb Dumb x 3 (list)

  30. Post #2390
    The Android1's Avatar
    January 2013
    160 Posts
    How would I go about making a derma skin for GMod? There is a lack of documentation for how to do it on the wikis.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  31. Post #2391
    Acecool discovered a way to get classes working in Lua; MetaTable users hate him, ArmA devs love him

    February 2012
    5,839 Posts
    How would I go about making a derma skin for GMod? There is a lack of documentation for how to do it on the wikis.
    Take a look at garrysmod/lua/skins/default.lua

    That contains ALL options for a skin. You can make your own and use any number of those to create the effect you want. There are minimalistic skins which only change buttons to rounded, scrollbar colors, etc.

    It really isn't documented that well and to find out what part of a skin you need to change usually involves digging in the vgui code, unfortunately.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  32. Post #2392
    Nova Prospekt's Avatar
    January 2009
    241 Posts
    On either Client or Server it'll return NULL, or empty entity if I recall correctly. I personally store worldspawn values in a list at index 0, actually I store all entity values in a list using the EntIndex as the key.

    Alrighty so, how do I/You go about obtaining the values (and KeyValues?) for Worldspawn?

    That's what I'm really after D:
    Reply With Quote Edit / Delete Show Events

  33. Post #2393
    DEFCON1's Avatar
    April 2010
    267 Posts
    Hi,

    I try to improve a script I did.. Previously I used the HUDPaint hook to draw the names of players. Now I try to switch to PostPlayerDraw, since it could theorically make my script much simpler. But it doesn't work as expected.

    This is what I used before (simplified a lot)
    Code:
    hook.Add( "HUDPaint", "paint",
        function()
            for _, ply in ipairs(player.GetAll()) do
                ply.ToScreenData = ply:GetPos():ToScreen()
                draw.SimpleText(ply:Name(), fontName, ply.ToScreenData.x, ply.ToScreenData.y, Color(255,255,255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP )
            end
        end
    )

    And this is what I try to do now:
    Code:
    hook.Add( "PostPlayerDraw", "paint",
        function( ply )
            ply.ToScreenData = ply:GetPos():ToScreen()
            draw.SimpleText(ply:Name(), fontName, ply.ToScreenData.x, ply.ToScreenData.y, Color(255,255,255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP )
        end
    )
    But with this, the text doesn't show at the player's pos on my screen. It seem to show at map origin + what seem to be the coordinates of where it should display on my screen, and also the angle is wrong, always pointing north.

    What am I missing? I know I could use cam.start3d2d, but I don't want that. I just want to understand why it's working in one hook and not working correctly in another.
    Reply With Quote Edit / Delete Windows 7 France Show Events

  34. Post #2394
    My eyes bleed everytime you fail to make your functions local
    wh1t3rabbit's Avatar
    January 2012
    1,092 Posts
    What am I missing? I know I could use cam.start3d2d, but I don't want that. I just want to understand why it's working in one hook and not working correctly in another.
    HUDPaint is a 2d rendering context, so drawing to your screen works fine. IIRC PostPlayerDraw is a 3d rendering context, so you need to wrap your code inside cam.Start2D()/End2D() for it to behave the same way.

    You could use Start2D for having everything aligned to your screen, or Start3D2D to have them aligned to the entity (or whatever angle you choose).
    Reply With Quote Edit / Delete Windows 7 Australia Show Events Informative Informative x 1 (list)

  35. Post #2395
    DEFCON1's Avatar
    April 2010
    267 Posts
    HUDPaint is a 2d rendering context, so drawing to your screen works fine. IIRC PostPlayerDraw is a 3d rendering context, so you need to wrap your code inside cam.Start2D()/End2D() for it to behave the same way.

    You could use Start2D for having everything aligned to your screen, or Start3D2D to have them aligned to the entity (or whatever angle you choose).
    Thanks a lot I totally forgot about this function Start2D ;)


    Edit: it's much, much slower than with my HUDPaint hook. The only advantage of PostPlayerDraw is that it can draw things behind the weapon. Well, at least I tried :)

    Edit again: is there a better "2D" hook than HUDPaint, in which I could draw behind the weapon ?


    Edit: I solved my problem by doing something like this:
    Code:
    local shouldDraw = false
    
    hook.Add("HUDPaint", "test", function() shouldDraw = true end )
    
    hook.Add( "PreDrawViewModel", "test",
        function()
            if shouldDraw == true then
                -- My old code that was inside the HUDPaint hook, but now inside a cam.Start2D()
                shouldDraw = false
            end
        end
    )
    This way, it is drawn only when needed, and behind the weapon :) . I lose only few FPS. I will do some more experiments, I'm sure there is still a better way. Feel free to reply if you have another solution!
    Reply With Quote Edit / Delete Show Events

  36. Post #2396
    NeuroTec Vehicles
    Hoffa1337's Avatar
    August 2006
    3,036 Posts
    How does one attach lua particles to an entity? So that they are not affected by entity moving at high speeds?
    Set the particles velocity to effectdata:GetEntity():GetVelocity() + YourNewVelocity or use this:

    Code:
    ParticleEffectAttach( "particle_name", PATTACH_ABSORIGIN_FOLLOW, entity, 0 )
    But this makes the particle effect spawn the particles at the entity but there's nothing that tells them to maintain the velocity of the parent object. Not sure if you can specify that as a flag or keyvalue in the Particle Editor.
    Reply With Quote Edit / Delete Show Events

  37. Post #2397

    May 2010
    251 Posts
    trying to make players spawn as spectators on inital spawn... dosen't work.
    players just spawn as normal.. does anyone know how to do this?

    i do DeriveGamemode( "base" ) in my shared.lua not sure if this has something to say but anyway..
    
    function GM:PlayerInitialSpawn(ply)
    	ply:SetTeam(TEAM_SPECTATOR)
    	ply:Spectate( OBS_MODE_ROAMING )
    end
    
    Reply With Quote Edit / Delete Windows 7 Denmark Show Events Useful Useful x 1 (list)

  38. Post #2398
    My eyes bleed everytime you fail to make your functions local
    wh1t3rabbit's Avatar
    January 2012
    1,092 Posts
    Thanks a lot I totally forgot about this function Start2D ;)


    Edit: it's much, much slower than with my HUDPaint hook. The only advantage of PostPlayerDraw is that it can draw things behind the weapon. Well, at least I tried :)

    Edit again: is there a better "2D" hook than HUDPaint, in which I could draw behind the weapon ?


    Edit: I solved my problem by doing something like this:
    Code:
    local shouldDraw = false
    
    hook.Add("HUDPaint", "test", function() shouldDraw = true end )
    
    hook.Add( "PreDrawViewModel", "test",
        function()
            if shouldDraw == true then
                -- My old code that was inside the HUDPaint hook, but now inside a cam.Start2D()
                shouldDraw = false
            end
        end
    )
    This way, it is drawn only when needed, and behind the weapon :) . I lose only few FPS. I will do some more experiments, I'm sure there is still a better way. Feel free to reply if you have another solution!
    I'm not sure if this would be any better than your solution but I draw 'behind' the weapon in HUDPaint by using stencils. Draw the viewmodel onto the stencil, and then it set it to only draw anything outside of that area. Anything you draw will be cut by the viewmodel and seem to be going behind it.
    Reply With Quote Edit / Delete Show Events Informative Informative x 1 (list)

  39. Post #2399
    Acecool discovered a way to get classes working in Lua; MetaTable users hate him, ArmA devs love him

    February 2012
    5,839 Posts
    HUDPaint is a 2d rendering context, so drawing to your screen works fine. IIRC PostPlayerDraw is a 3d rendering context, so you need to wrap your code inside cam.Start2D()/End2D() for it to behave the same way.

    You could use Start2D for having everything aligned to your screen, or Start3D2D to have them aligned to the entity (or whatever angle you choose).
    Make sure what is returned isn't NULL; if it is look at Entity( 0 ) which may also return NULL, etc -- you may also be able to do a search ents.FindByClass( "worldspawn" )[ 1 ];.. That is if you're trying to target it directly to retrieve data that you didn't set.

    If you want to set / track data, I'd still recommend making your own table and managing it that way without attaching it directly to the entity.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  40. Post #2400
    STOP BUGGING ME WITH YOUR SHITTY RP EDITS
    CGNick's Avatar
    July 2012
    1,865 Posts
    So I've been trying to nail down AI pathing, but it always turns out goofy like this, and I'm not sure why. Anybody got any ideas to this?

    Reply With Quote Edit / Delete Windows 7 Bulgaria Show Events