I am new to LUA and have this:
[CODE]if string.lower(txt) == "/WTFBOOM" then
surface.PlaySound["sounds/wtfboom.mp3"]
end[/CODE]
After the surface.PlaySound I want someone to blow up using their Steam ID.
Can anyone help?
I'm not sure if you can play .mp3 files :geno:
[lua]surface.PlaySound()[/lua] is the same as doing [code]play "song path and stuff"[/code] in the console :v:
I'd use [lua]RunConsoleCommand("play sound/wtfboom.wav")[/lua] (note the .wav) personally because I like to stick to stuff I know :v:
Back to your post:
You're making it so if someone says "/WTFBOOM" they blow up?
Based on your code I think it would be something like
[lua]if string.lower(txt) == "/WTFBOOM" then
RunConsoleCommand("play sound/wtfboom.wav")
--explosion code
end
[/lua] or something...?
also you should change string.lower to string.upper
Yeah I didn't know if I should have suggested that since I've never used it :raise:
Haha yeah I looked at it and thought that didn't seem right so I googled the function and it makes it lower
Haha.
[QUOTE=Chad Mobile;19619208]I'm not sure if you can play .mp3 files :geno:
[lua]surface.PlaySound()[/lua] is the same as doing [code]play "song path and stuff"[/code] in the console :v:
I'd use [lua]RunConsoleCommand("play sound/wtfboom.wav")[/lua] (note the .wav) personally because I like to stick to stuff I know :v:
Back to your post:
You're making it so if someone says "/WTFBOOM" they blow up?
Based on your code I think it would be something like
[lua]if string.lower(txt) == "/WTFBOOM" then
RunConsoleCommand("play sound/wtfboom.wav")
--explosion code
end
[/lua] or something...?[/QUOTE]
Yeah, thanks for the suggestion too.
I want it so a certain player, if in the game, blows up if someone types that.
Use [b][url=wiki.garrysmod.com/?title=Gamemode.PlayerSay]Gamemode.PlayerSay [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b].
Then use [b][url=wiki.garrysmod.com/?title=Util.BlastDamage]Util.BlastDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] or an [url=http://developer.valvesoftware.com/wiki/Env_explosion][b]env_explosion [img]http://developer.valvesoftware.com/favicon.ico[/img][/b][/url].
Thank you
Edit :
It doesn't work..
[QUOTE=AncientFryup;19626568]Thank you
Edit :
It doesn't work..[/QUOTE]
Explain further. What happens? What did you do?
blow up everyone
[lua]
function Boom(ply, text, toall)
if string.lower(txt) == "/wtfboom" then
for k,v in ipairs(player:GetAll()) do
v:EmitSound("wtfboom.mp3", 70, 100)
local pos = v:GetPos()
local data = EffectData()
data:SetPos(v:GetPos())
util.Effect("Explosion", data, true, true)
v:Kill()
end
end
end
hook.Add("PlayerSay", "Boom", Boom)
[/lua]
blow up the player who said it
[lua]
local function Boom(ply, text, toall)
if string.lower(text) == "/wtfboom" then
ply:EmitSound("wtfboom.mp3", 100, 100)
local pos = ply:GetPos()
local data = EffectData()
data:SetPos(ply:GetPos())
util.Effect("Explosion", data, true, true)
ply:Kill()
end
end
hook.Add("PlayerSay", "Boom", Boom)
[/lua]
blow up a specific steamID
[lua]
function Boom(ply, text, toall)
if string.lower(txt) == "/wtfboom" then
for k,v in ipairs(player:GetAll()) do
if v:SteamID() == "steamidhere" then
v:EmitSound("wtfboom.mp3", 70, 100)
local pos = v:GetPos()
local data = EffectData()
data:SetPos(v:GetPos())
util.Effect("Explosion", data, true, true)
v:Kill()
end
end
end
end
hook.Add("PlayerSay", "Boom", Boom)
[/lua]
That doesn't work sadly
Maybe there is a better way for a player to trigger it instead of [lua]if string.lower(txt) == "/wtfboom" then [/lua]?
Also, string.upper doesn't do anything.
it should work perfectly fine because it's some of the simplest shit you can do with chat
string.upper makes all letters uppercase, just an fyi, lower is always the way to go when you're trying to locate something in chat
I am stupid to ask this but it goes in lua/autorun/server right?
Sorry, you need to Log In to post a reply to this thread.