-- Lua must check for values using "==", not "=". Only use "=" when defining variables and/or setting values.
-- "PlayerMsg" accepts a function(player_t source, int type, player_t target, string msg)
-- int type being 3 means the message is a pm.
-- Learning the usage of "if", "elseif" and "end" is REQUIRED for basic lua. If you do not understand this, you cannot make scripts.
-- It seems you may need to study the language as a whole. You can start at https://wiki.srb2.org/wiki/Lua
local cv_disablemeows = CV_RegisterVar({
	name = "disablebob",
	defaultvalue = 0,
	flags = CV_SAVE|CV_SHOWMODIF,
	PossibleValue = CV_OnOff,
})

addHook("PlayerMsg", function(p, msgtype, p2, msg)
    if p.mo.skin ~= "bob" then return end -- If the player in question isn't Skylina, don't run.
	if cv_disablemeows.value > 0 then return end -- If the player does not wish to hear meows.

    -- If the message contains any of the given strings in any case, play a sound in the sender and reciever's game.
	if msgtype == 3 then
		if (msg:lower():find("ayy")) then
			S_StartSound(p.mo, sfx_bayy, p)
			S_StartSound(p2.mo, sfx_bayy, p2)
		elseif (msg:lower():find("fuck.")) then
			S_StartSound(p.mo, sfx_bfuck, p)
			S_StartSound(p2.mo, sfx_bfuck, p2)
		elseif (msg:lower():find("nice.")) then
			S_StartSound(p.mo, sfx_bnice, p)
			S_StartSound(p2.mo, sfx_bnice, p2)
		elseif (msg:lower():find("thanks.")) then
			S_StartSound(p.mo, sfx_bthank, p)
			S_StartSound(p2.mo, sfx_bthank, p2)
		elseif (msg:lower():find("no.")) then
			S_StartSound(p.mo, sfx_bno, p)
			S_StartSound(p2.mo, sfx_bno, p2)
		elseif (msg:lower():find("yes.")) then
			S_StartSound(p.mo, sfx_byes, p)
			S_StartSound(p2.mo, sfx_byes, p2)
		end
	else
		if (msg:lower():find("ayy.")) then
			for player in players.iterate do
				S_StartSound(player.mo, sfx_bayy, player)
			end
		elseif (msg:lower():find("fuck.")) then
			for player in players.iterate do
				S_StartSound(player.mo, sfx_bfuck, player)
			end
		elseif (msg:lower():find("nice.")) then
			for player in players.iterate do
				S_StartSound(player.mo, sfx_bnice, player)
			end
		elseif (msg:lower():find("thanks.")) then
			for player in players.iterate do
				S_StartSound(player.mo, sfx_bthank, player)
			end
		elseif (msg:lower():find("no.")) then
			for player in players.iterate do
				S_StartSound(player.mo, sfx_bno, player)
			end
		elseif (msg:lower():find("yes.")) then
			for player in players.iterate do
				S_StartSound(player.mo, sfx_byes, player)
			end
		end
	end
end)

