SolvedSuper simple raid detector?

Posts 18 of 8 · Page 1 of 1
Super simple raid detector?
I am a total newb in coding gmod(lua) but i do have coding background with java and c++, so im not a newb to programming, i understand loops and if statements and all so the coding lingo im fine with.

Basically what im trying to do is, when you run this script it will search in the chat for the word "raid" and when it finds it, it will play a sound and input in your chat box (chat.AddText) that someone has called raid. Therefore you can check your front door or whatever to see if that raid is on you.

Heres my code so far (im a newb please dont flip out on me, however constructive criticism is appreciated)

If you have a better/ more efficient way or better idea please do tell




chat.AddText( Color( 0, 180, 180 ), "[Raid Buddy] ", Color( 255, 255, 255 ), "You've Enabled Raid Buddy!")
if (chat.Text == "raid" || "Raid" || "RAID") then
chat.AddText( Color( 0, 180, 180 ), "[Raid Buddy] ", Color( 255, 255, 255 ), "Someone Called Raid in Chat!" )
chat.PlaySound()
end




Its not much code, i just started and i couldnt figure out how i should go about scanning the chat. I was also thinking maybe i would need a while loop so it would continue scanning until it finds the word raid?

Please help
Appreciate the help ! but didnt seem to work :/ seems this function only pulls what you type and displays it, im looking for a way to search the chat for the string "raid". Again, Thanks a lot for the help !
or just look in chat? wtf?
Sometimes im not really paying attention to chat, or i do homework but leave my headphones in while i print money, just looking for something that gives me a little heads up, no harm done ?
Code:
local BeepTable = {
	[1] = Sound( "buttons/button11.wav" ),
	[2] = Sound( "buttons/button12.wav" ),
	[3] = Sound( "buttons/button13.wav" ),
	[4] = Sound( "buttons/button14.wav" ),
	[5] = Sound( "buttons/button15.wav" ),
	[6] = Sound( "buttons/button16.wav" ),
	[7] = Sound( "buttons/button17.wav" ),
	[8] = Sound( "buttons/button18.wav" ),
	[9] = Sound( "buttons/button19.wav" )
}

local function CreateBeep()
	local ply = LocalPlayer()
	local Beep = Sound( "buttons/button1.wav" )
	
	for k, v in pairs( BeepTable ) do
		Beep = CreateSound( ply, v )
		Beep:Play()
	end
end

local function RaidAnnounced( ply, str )
	chat.AddText( Color( math.Rand( 1, 255 ), math.Rand( 1, 255 ), math.Rand( 1, 255 ) ), "you are blind [ \"" .. ply:Nick() .. "\" ] [ \"" .. str .. "\" ]" )
end

local function PlayerSpoke( ply, str )
	local lower = string.lower( str )
	
	if ( string.find( lower, "raid" ) ) then
		for i = 1, 10 do
			RaidAnnounced( ply, str )
		end
		
		CreateBeep()
	end
end

hook.Add( "OnPlayerChat", "PlayerSpoke", PlayerSpoke )
http://pastebin.com/pvhAZzEL
Greatly appreciated, im gunna look over this and get used to some of the methods
//Solved...
Posts 18 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?