Hey, im making a Darkrp server and i want some help on this.
So i want the combine to make noise when they run.
[CODE]function GM:PlayerFootstep( ply, pos, foot, sound, volume, rf )
local Team = ply:Team()
if Team == {"TEAM_POLICE","TEAM_CHIEF","TEAM_CPELITE"} then
ply:EmitSound("npc/combine_soldier/gear1.wav", 65, 70)
else
return false
end
end[/CODE]
I currently have that.
But it gives an error something about "GM" nil
[QUOTE=Insect;43449116]Hey, im making a Darkrp server and i want some help on this.
So i want the combine to make noise when they run.
[CODE]function GM:PlayerFootstep( ply, pos, foot, sound, volume, rf )
local Team = ply:Team()
if Team == {"TEAM_POLICE","TEAM_CHIEF","TEAM_CPELITE"} then
ply:EmitSound("npc/combine_soldier/gear1.wav", 65, 70)
else
return false
end
end[/CODE]
I currently have that.
But it gives an error something about "GM" nil[/QUOTE]
Use a hook, here is an example:
[lua]
local function MyFootstepFunction( ply, pos, foot, sound, volume, rf )
local Team = ply:Team()
if Team == {"TEAM_POLICE","TEAM_CHIEF","TEAM_CPELITE"} then
ply:EmitSound("npc/combine_soldier/gear1.wav", 65, 70)
else
return false
end
end
hook.Add("PlayerFootstep", "MyHookName", MyFootstepFunction)[/lua]
player.Team doesn't return a string. It returns an integer. DarkRP sets variables like TEAM_CITIZEN for ease, so remove the quotes around the team names.
[code]Change "TEAM_POLICE" to TEAM_POLICE[/code]
[editline]7th January 2014[/editline]
Also, what you're doing is comparing a non table to a table. Use this instead:
[code]table.HasValue({TEAM_POLICE, TEAM_CHIEF, TEAM_CPELITE}, ply:Team())[/code]
Here's your entire hook:
[code]local function FootNoise( ply )
if table.HasValue( { TEAM_POLICE, TEAM_CHIEF, TEAM_CPELITE }, ply:Team()) then
ply:EmitSound("npc/combine_soldier/gear1.wav", 65, 70)
else
return false -- might need to be true instead, don't know the return value for normal noise
end
end
hook.Add("PlayerFootstep", "FootNoise", FootNoise)
[/code]
[editline]7th January 2014[/editline]
Also also: if GM is nil, use GAMEMODE.
BTW, that's not how you compare a number to a table in Lua:
[code]if Team == {"TEAM_POLICE","TEAM_CHIEF","TEAM_CPELITE"} then[/code]
[code]local function MyFootstepFunction( ply, pos, foot, sound, volume, rf )
if table.HasValue( { TEAM_POLICE, TEAM_CHIEF, TEAM_CPELITE }, ply:Team() ) then
ply:EmitSound("npc/combine_soldier/gear1.wav", 65, 70)
else
return false
end
end
hook.Add("PlayerFootstep", "MyHookName", MyFootstepFunction)[/code]
Ah, Thank you very much guys, An extreme "noob" here ^.^ But we all start out as "noob's"
Anyway, What would i have to do if i want a variation in sounds ?
[QUOTE]npc/combine_soldier/gear1.wav, npc/combine_soldier/gear2.wav[/QUOTE]
"npc/combine_soldier/gear" .. math.random(1,2) .. ".wav"
or
local table = { "snd1", "snd2" }
table.Random( table )
[lua]
local stepsounds = { "npc/combine_soldier/gear1.wav", "npc/combine_soldier/gear2.wav" }
local function FootNoise( ply )
if table.HasValue( { TEAM_POLICE, TEAM_CHIEF, TEAM_CPELITE }, ply:Team()) then
ply:EmitSound(stepsounds[math.Random(#stepsounds)], 65, 70)
else
return false -- might need to be true instead, don't know the return value for normal noise
end
end
hook.Add("PlayerFootstep", "FootNoise", FootNoise)
[/lua]
[b]EDIT:[/b]
DAMNIT ROBOT
[QUOTE=Koolaidmini;43449930][lua]
local stepsounds = { "npc/combine_soldier/gear1.wav", "npc/combine_soldier/gear2.wav" }
local function FootNoise( ply )
if table.HasValue( { TEAM_POLICE, TEAM_CHIEF, TEAM_CPELITE }, ply:Team()) then
ply:EmitSound(stepsounds[math.Random(#stepsounds)], 65, 70)
else
return false -- might need to be true instead, don't know the return value for normal noise
end
end
hook.Add("PlayerFootstep", "FootNoise", FootNoise)
[/lua]
[b]EDIT:[/b]
DAMNIT ROBOT[/QUOTE]
Calm down, be kool.
[QUOTE=Robotboy655;43450004]Calm down, be kool.[/QUOTE]
I respect the pun you just made.
ok..
[QUOTE]
[ERROR] lua/autorun/client/combinewalk.lua:8: attempt to call field 'Random' (a nil value)
1. fn - lua/autorun/client/combinewalk.lua:8
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183
[/QUOTE]
Which person code do i use xD and which is the correct way?
Both ways are correct, he just made a typo, it's math.random, not math.Random.
Ah, Thank you guys very much!
[editline]7th January 2014[/editline]
Ok, Now how would i get this to work?
Typing "lamarr" in chat would play that iconic sentence xD But i would of course add more such as Combine radio chatter.
[QUOTE]local sounds = {}
sounds[ "lamarr" ] = { "vo/k_lab/kl_nocareful.wav" }[/QUOTE]
I'm just going to say this now, we can't help you with every little issue, it's nice to help others, but it get extremely tedious when they continually ask questions that could be solved with some simple googling. BUT, since I too wen through the struggle of being an amateur, try researching a bit about gmod chat commands. Once you figure that out, hook the specific command to emit a sound from the caller. Cheers!
Ok, Sorry but that was my last question xD
Sorry, you need to Log In to post a reply to this thread.