self.Weapon:DefaultReload(ACT_VM_RELOAD)
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?
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.
snip I can't believe I was 50 minutes late
Ah, thank you.
Thanks for trying to help but this is not a shared.lua file this is client only.
You cant use that.if SERVER then self.Owner:AddMoney(10) end
That's why I use only shared.lua, instead of cl_init.lua and init.lua :D
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.
I assume returning something stops the loop.
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)
What's wrong with the "old one"?
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")
Check if Sounds is a table, if it is then loop through it.
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.
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)
I'll try that, thanks.
Edited:
Hook 'SoundPlayer.ChatFunction' Failed: bad argument #1 to 'pairs' (table expected, got nil)
does the table Sounds exist?
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" )
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.
"..and how would we go about doing this?"
he asked, feeling like a lua noob.![]()
Does your/his shop uses the "giveplayeritem" command or another one?
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.
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.
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)
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!
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.
-snip-
i'll just go make a topic in the questions section for more direct help
Great, thanks for the assistance. :)
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?
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 --so uh, any help?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" --
There simply is no error, but it doesn't emit the sound. I have no clue what's causing it.
:SPersious posted:
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)
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?