1. Post #281
    pennerlord's Avatar
    February 2011
    497 Posts
    I can't see firstperson reload animations!

    self.Owner:SetAnimation( PLAYER_RELOAD) --firstperson, not working
    self.Weapon:SendWeaponAnim( ACT_VM_RELOAD ) --thirdperson, working	
    

    any idea how to repair it?
    self.Weapon:DefaultReload(ACT_VM_RELOAD)
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  2. Post #282
    Krizzu's Avatar
    June 2011
    118 Posts
    self.Weapon:DefaultReload(ACT_VM_RELOAD)
    It's only for thirdperson? because In FPP I see nothing :/

    And it's there any DropCurrentWeapon() ?
    How how to drop current holding weapon?
    Reply With Quote Edit / Delete Windows 7 Poland Show Events

  3. Post #283
    MoronYard
    _nonSENSE's Avatar
    May 2010
    1,261 Posts
    Hm, still isn't emiting the sound.
    function SoundPlayer.ChatFunction( ply, text )
    
    if ply:Alive() then    
        for _, sound in pairs(Sounds) do
            if string.find( text, sound.Text ) then
                ply:EmitSound(sound.Destination, 500, 100)
                return text
            end
       end
    end
    
    end
    hook.Add("PlayerSay", "SoundPlayer.ChatFunction", SoundPlayer.ChatFunction)
    

    There, now it makes sense. While k and v are typically used, you should try to give those variables a descriptive name and use _ when you do not need one of them.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  4. Post #284
    Gold Member
    leiftiger's Avatar
    November 2009
    272 Posts
    snip I can't believe I was 50 minutes late
    Reply With Quote Edit / Delete Windows 7 Sweden Show Events

  5. Post #285
    Free Bradley Manning!
    Persious's Avatar
    April 2010
    2,193 Posts
    function SoundPlayer.ChatFunction( ply, text )
    
    if ply:Alive() then    
        for _, sound in pairs(Sounds) do
            if string.find( text, sound.Text ) then
                ply:EmitSound(sound.Destination, 500, 100)
                return text
            end
       end
    end
    
    end
    hook.Add("PlayerSay", "SoundPlayer.ChatFunction", SoundPlayer.ChatFunction)
    

    There, now it makes sense. While k and v are typically used, you should try to give those variables a descriptive name and use _ when you do not need one of them.
    Ah, thank you.
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events Friendly Friendly x 1 (list)

  6. Post #286
    Awesome Gmod Servers!
    brandonj4's Avatar
    September 2011
    1,372 Posts
    Thanks for trying to help but this is not a shared.lua file this is client only.
             if SERVER then
                     self.Owner:AddMoney(10)
             end
    
    You cant use that.
    Reply With Quote Edit / Delete Windows 7 Canada Show Events

  7. Post #287
    Krizzu's Avatar
    June 2011
    118 Posts
    Thanks for trying to help but this is not a shared.lua file this is client only.
             if SERVER then
                     self.Owner:AddMoney(10)
             end
    
    You cant use that.
    That's why I use only shared.lua, instead of cl_init.lua and init.lua :D
    Reply With Quote Edit / Delete Windows 7 Poland Show Events Dumb Dumb x 2 (list)

  8. Post #288
    Free Bradley Manning!
    Persious's Avatar
    April 2010
    2,193 Posts
    So I tried allowing my SoundPlayer.AddSound to support multiple words, but had no idea what the fuck I was doing.

    SoundPlayer = {}
    
    Sounds = {}
    
    function SoundPlayer.AddSound(Text, Destination)
    
    table.insert(Sounds, {{Text = Text}, Destination = Destination})
    
    end
    
    function SoundPlayer.ChatFunction( ply, text )
     
    if ply:Alive() then  
    
        for _, sound in pairs(Sounds) do
    
            if string.lower(text) == sound.Text then
    
                ply:EmitSound(sound.Destination, 500, 100)
    
                return text
    
          	    end
    
       		end
    
    	end
    
    end
    hook.Add("PlayerSay", "SoundPlayer.ChatFunction", SoundPlayer.ChatFunction)
    

    As you see, the table should support a table of more than one word.
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  9. Post #289
    I love you Danny <3
    Chessnut's Avatar
    August 2011
    2,690 Posts
    I assume returning something stops the loop.
    Reply With Quote Edit / Delete United States Show Events

  10. Post #290
    Free Bradley Manning!
    Persious's Avatar
    April 2010
    2,193 Posts
    Well, it worked fine when I used my old one, aka

    SoundPlayer = {}
     
    Sounds = {}
     
    function SoundPlayer.AddSound(Text, Destination)
     
    table.insert(Sounds, {Text = Text, Destination = Destination}) -- This one
     
    end
     
    function SoundPlayer.ChatFunction( ply, text )
      
    if ply:Alive() then 
     
        for _, sound in pairs(Sounds) do
     
            if string.lower(text) == sound.Text then
     
                ply:EmitSound(sound.Destination, 500, 100)
     
                return text
     
                end
     
            end
     
        end
     
    end
    hook.Add("PlayerSay", "SoundPlayer.ChatFunction", SoundPlayer.ChatFunction)
    
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  11. Post #291
    PROUD BRONY 4LYFE
    Drakehawke's Avatar
    February 2009
    3,491 Posts
    What's wrong with the "old one"?
    Reply With Quote Edit / Delete Windows Vista United Kingdom Show Events

  12. Post #292
    Free Bradley Manning!
    Persious's Avatar
    April 2010
    2,193 Posts
    Nothing, the old one worked just fine, until I wanted each SoundPlayer.AddSound to allow multiple words, example SoundPlayer.AddSound({"hi", "hello", "fag"}, "sound directory here")
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  13. Post #293
    I love you Danny <3
    Chessnut's Avatar
    August 2011
    2,690 Posts
    Check if Sounds is a table, if it is then loop through it.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  14. Post #294
    Free Bradley Manning!
    Persious's Avatar
    April 2010
    2,193 Posts
    Sounds is valid, I did loop through it, but still doesn't play the sound when I type one of the words in the table.
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  15. Post #295
    PROUD BRONY 4LYFE
    Drakehawke's Avatar
    February 2009
    3,491 Posts
    SoundPlayer = {}
      
    Sounds = {}
      
    function SoundPlayer.AddSound(Text, Destination)
      
    table.insert(Sounds, {Text = Text, Destination = Destination}) -- This one
      
    end
      
    function SoundPlayer.ChatFunction( ply, text )
       
    if ply:Alive() then
      
        for _, sound in pairs(Sounds) do
      
            if table.HasValue( sound.Text, text ) then
      
                ply:EmitSound(sound.Destination, 500, 100)
      
                return text
      
                end
      
            end
      
        end
      
    end
    hook.Add("PlayerSay", "SoundPlayer.ChatFunction", SoundPlayer.ChatFunction)
    Reply With Quote Edit / Delete Windows Vista United Kingdom Show Events Agree Agree x 1 (list)

  16. Post #296
    Free Bradley Manning!
    Persious's Avatar
    April 2010
    2,193 Posts
    I'll try that, thanks.

    Edited:

    Hook 'SoundPlayer.ChatFunction' Failed: bad argument #1 to 'pairs' (table expected, got nil)
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  17. Post #297
    Gold Banana
    Banana Lord.'s Avatar
    May 2010
    5,275 Posts
    does the table Sounds exist?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  18. Post #298
    PROUD BRONY 4LYFE
    Drakehawke's Avatar
    February 2009
    3,491 Posts
    I'll try that, thanks.

    Edited:

    Hook 'SoundPlayer.ChatFunction' Failed: bad argument #1 to 'pairs' (table expected, got nil)
    Are you trying to add some sounds as single words and some as multiple words?

    If so, you can either fiddle around with checking type(sound.Text) or just change your single word ones so they are enclosed in {}

    eg SoundPlayer.AddSound( { "hi" }, "directory" )
    Reply With Quote Edit / Delete Windows Vista United Kingdom Show Events

  19. Post #299
    TheTeekz's Avatar
    March 2012
    7 Posts
    Hey, I know this is in the example questions for the thread, and I've searched around the site a little to find an answer, but came up empty.

    So, is there a way to stop a player opening the console while they're on our server? Basically our users are spawning items with giveplayeritem rather than buying them from the in-game store, and we obviously want to prevent this.

    Thanks,
    Tom.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  20. Post #300
    pennerlord's Avatar
    February 2011
    497 Posts
    Hey, I know this is in the example questions for the thread, and I've searched around the site a little to find an answer, but came up empty.

    So, is there a way to stop a player opening the console while they're on our server? Basically our users are spawning items with giveplayeritem rather than buying them from the in-game store, and we obviously want to prevent this.

    Thanks,
    Tom.
    Never trust a player. Validate the command serverside and your problems are gone.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  21. Post #301
    TheTeekz's Avatar
    March 2012
    7 Posts
    "..and how would we go about doing this? "

    he asked, feeling like a lua noob.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  22. Post #302
    pennerlord's Avatar
    February 2011
    497 Posts
    Does your/his shop uses the "giveplayeritem" command or another one?
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  23. Post #303
    TheTeekz's Avatar
    March 2012
    7 Posts
    It uses giveplayeritem, as far as we can tell. I could probably find the code again and post it, if it would help? We're currently running the GoFish mod.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  24. Post #304
    pennerlord's Avatar
    February 2011
    497 Posts
    It uses giveplayeritem, as far as we can tell. I could probably find the code again and post it, if it would help? We're currently running the GoFish mod.
    Yeah, the code would help us.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  25. Post #305
    TheTeekz's Avatar
    March 2012
    7 Posts
    function giveplayeritem(ply,cmd,args)
    local amount = tonumber(args[2])
    if ply:GetNetworkedInt("cash") >= amount then
    ply:Give(args[1])
    ply:SetNetworkedInt("cash", ply:GetNetworkedInt("cash") - amount)
    umsg.Start("MoneyChanged",ply)
    umsg.Short(ply:GetNetworkedInt("cash"))
    umsg.End()
    else
    ply:PrintMessage( HUD_PRINTTALK, "You Do Not Have Enough Money")
    end
    end
    concommand.Add("giveplayeritem", giveplayeritem)
    

    I believe that's the section of the code that deals with purchasing from the shop.
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  26. Post #306
    pennerlord's Avatar
    February 2011
    497 Posts
    local amount = tonumber(args[2])

    With this code the client can control the price. You should use a shared/serverside table for the prices and get the price for the item from that table.

    Give me a few minutes and I will give you an example...

    Edited:

    Here's a really basic example. It should give you an idea about what I'm talking.

    local ShopTable = {}
    ShopTable["weapon_357"] = 100 -- Price = 100 <insert currency here>
    
    
    local function GivePlayerItem(ply, cmd, args)
    	local item = args[1]
    	local price = ShopTable[item]
    	if not item or not price then return end -- check if this item is a valid item
    	
    	-- your code here
    end
    concommand.Add("YourCommand", GivePlayerItem)
    
    Reply With Quote Edit / Delete Windows 7 Germany Show Events Lua Helper Lua Helper x 1 (list)

  27. Post #307

    June 2011
    192 Posts
    ok, does anyone know where the download is for the custom Trouble in Terrorist Town -Traitor turret is. it looks like a normal combine turret but it has health and only shoots non-traitors. I really want to use it to learn from, and mod it, i've seen other servers with it and i can't find it anywhere. Anyone know where it is? thanks guys!
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  28. Post #308
    TheTeekz's Avatar
    March 2012
    7 Posts
    With this code the client can control the price. You should use a shared/serverside table for the prices and get the price for the item from that table.
    Thanks for the example.

    I feel that I should note that the shop code I posted above was from the initialization script (init.lua) of the gamemode we're using, and the items/prices in the shop are already set in a different script in the same directory, (shared.lua). Could we reference these somehow, instead of creating a new table?
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  29. Post #309
    pennerlord's Avatar
    February 2011
    497 Posts
    Thanks for the example.

    I feel that I should note that the shop code I posted above was from the initialization script (init.lua) of the gamemode we're using, and the items/prices in the shop are already set in a different script in the same directory, (shared.lua). Could we reference these somehow, instead of creating a new table?
    Sure, you can, as long as the table is global.
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  30. Post #310
    LilRobot's Avatar
    January 2009
    1,562 Posts
    -snip-

    i'll just go make a topic in the questions section for more direct help
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  31. Post #311
    TheTeekz's Avatar
    March 2012
    7 Posts
    Sure, you can, as long as the table is global.
    Great, thanks for the assistance. :)
    Reply With Quote Edit / Delete Windows 7 United Kingdom Show Events

  32. Post #312
    Free Bradley Manning!
    Persious's Avatar
    April 2010
    2,193 Posts
    Are you trying to add some sounds as single words and some as multiple words?

    If so, you can either fiddle around with checking type(sound.Text) or just change your single word ones so they are enclosed in {}

    eg SoundPlayer.AddSound( { "hi" }, "directory" )
    I did enclose all the words, and never used type() - Mind explaining how it works?
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  33. Post #313
    PROUD BRONY 4LYFE
    Drakehawke's Avatar
    February 2009
    3,491 Posts
    I did enclose all the words, and never used type() - Mind explaining how it works?
    type( 123 ) == "number"
    type( "abc" ) == "string"
    type( Vector() ) == "vector"
    type( LocalPlayer() ) == "player"
    type( Entity( 0 ) ) == "entity"

    etc

    However if you enclosed the words in parenthesis correctly it should work, mind telling us which line the error occurred on?
    Reply With Quote Edit / Delete Windows Vista United Kingdom Show Events

  34. Post #314
    LilRobot's Avatar
    January 2009
    1,562 Posts
    i've fixed up most of the problems i had detailed
    the only issues now are there's no muzzle flash and the weapon doesn't fire a projectile

    Code:
    -- Effect settings
    SWEP.PrintName		= "Wunderwaffe DG-2"	-- 
    SWEP.Slot			= 0					-- 
    SWEP.SlotPos		= 11					-- 
    SWEP.DrawAmmo		= true				-- 
    SWEP.DrawCrosshair	= true				-- 
    SWEP.ViewModel		= "models/weapons/v_wunderwaffe.mdl"	-- 
    SWEP.WorldModel		= "models/weapons/c_models/c_wunderwaffe/c_wunderwaffe_hl2.mdl"	-- 
    SWEP.ReloadSound	= "wunderwaffe_reload.wav"	--
    SWEP.PickupSound	= "richtofen_pickupa.wav"
    Code:
    -- Other settings
    SWEP.HoldType			= "shotgun"
    SWEP.Weight				= 5			-- 
    SWEP.AutoSwitchTo		= true		-- 
    SWEP.AutoSwitchFrom		= false		-- 
    SWEP.Spawnable			= true		-- 
    SWEP.AdminSpawnable		= true		-- 
    --SWEP.AutoReload		= false		--
    Code:
    -- Primary fire settings
    SWEP.Primary.Sound			= "wunderwaffe_fire.wav"	-- 
    SWEP.Primary.Damage			= 50			-- 
    SWEP.Primary.NumShots		= 1			-- 
    SWEP.Primary.Recoil			= .5		-- 
    SWEP.Primary.Cone			= 0			-- 
    SWEP.Primary.Delay			= 1.5		-- 
    SWEP.Primary.ClipSize		= 3		-- 
    SWEP.Primary.DefaultClip	= 3		-- 
    SWEP.Primary.Tracer			= 1			-- 
    SWEP.Primary.Force			= 1			-- 
    SWEP.Primary.TakeAmmoPerBullet = true	-- 
    SWEP.Primary.Automatic		= false		-- 
    SWEP.Primary.Ammo			= "ar2"	--
    so uh, any help?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  35. Post #315
    Free Bradley Manning!
    Persious's Avatar
    April 2010
    2,193 Posts
    type( 123 ) == "number"
    type( "abc" ) == "string"
    type( Vector() ) == "vector"
    type( LocalPlayer() ) == "player"
    type( Entity( 0 ) ) == "entity"

    etc

    However if you enclosed the words in parenthesis correctly it should work, mind telling us which line the error occurred on?
    There simply is no error, but it doesn't emit the sound. I have no clue what's causing it.
    Reply With Quote Edit / Delete Windows 7 Faroe Islands Show Events

  36. Post #316
    PROUD BRONY 4LYFE
    Drakehawke's Avatar
    February 2009
    3,491 Posts
    There simply is no error
    Persious posted:
    Hook 'SoundPlayer.ChatFunction' Failed: bad argument #1 to 'pairs' (table expected, got nil)
    :S
    Reply With Quote Edit / Delete Windows Vista United Kingdom Show Events

  37. Post #317
    LilRobot's Avatar
    January 2009
    1,562 Posts
    i ironed out a lot of the problems with my weapon.
    now my only question is, is it possible to make it have a radius explosion or zap type thing where a bullet hits?
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  38. Post #318
    pennerlord's Avatar
    February 2011
    497 Posts
    i ironed out a lot of the problems with my weapon.
    now my only question is, is it possible to make it have a radius explosion or zap type thing where a bullet hits?
    Yes, there is a way. For example:

    local tr = self.Owner:GetEyeTrace()
    
    local effectdata = EffectData()
    effectdata:SetOrigin(tr.HitPos)
    effectdata:SetStart(self.Owner:GetShootPos())
    effectdata:SetAttachment(1)
    effectdata:SetEntity(self)
    util.Effect("ToolTracer", effectdata)
    
    Reply With Quote Edit / Delete Windows 7 Germany Show Events

  39. Post #319
    LilRobot's Avatar
    January 2009
    1,562 Posts
    thanks for that, but what i meant was kind of like an explosion where the bullet hits
    as in, an explosion that kills things, preferably dissolves them.
    Reply With Quote Edit / Delete Windows 7 United States Show Events

  40. Post #320
    pennerlord's Avatar
    February 2011
    497 Posts
    thanks for that, but what i meant was kind of like an explosion where the bullet hits
    as in, an explosion that kills things, preferably dissolves them.
    A real explosion or just the explosion effect?
    Reply With Quote Edit / Delete Windows 7 Germany Show Events