Hooks not returning value, still breaking other hooks?

I’ve been having this issue on my server the last few weeks where whenever I try to add a hook, it sometimes randomly breaks other hooks of the same type. None of these hooks are returning values, so I can’t imagine why this is happening.

For example, I’ve had a hook on the server working fine for the last several weeks that, on TTTPrepareRound, stops any music that might be playing. (Which is a regular occurrence on the server.) Today, I tried to add a hook that, on TTTPrepareRound, checks some players pointshop 2 items and does things depending on what they have. It also works fine, but now suddenly the music-stopping one doesn’t work any more. Removing the new one causes it to start functioning again fine.

Here is the code for the newer hook, the one that’s breaking the old one. (Edited to avoid leaking pointshop 2 script)


function itemcheckprepare( )
	if SERVER then
		for _, v in pairs( player.GetAll() ) do
			local spawnItem = --Code that gets item equipped in the specified equipment slot ("Melee", in this case)
			if --Code that returns the name of the item specified above-- == "Red Lightsaber" then
				v:StripWeapon("weapon_zm_improvised")
				v:Give("weapon_zm_improvisedr")
				v:SelectWeapon("weapon_zm_improvisedr")
			end
			if --Code that returns the name of the item specified above-- == "Green Lightsaber" then
				v:StripWeapon("weapon_zm_improvised")
				v:Give("weapon_zm_improvisedg")
				v:SelectWeapon("weapon_zm_improvisedg")
			end
			if --Code that returns the name of the item specified above-- == "Purple Lightsaber" then
				v:StripWeapon("weapon_zm_improvised")
				v:Give("weapon_zm_improvisedp")
				v:SelectWeapon("weapon_zm_improvisedp")
			end
			if --Code that returns the name of the item specified above-- == "Draugr Axe" then
				v:StripWeapon("weapon_zm_improvised")
				v:Give("weapon_zm_improviseda")
				v:SelectWeapon("weapon_zm_improviseda")
			end
			if --Code that returns the name of the item specified above-- == "Death Sword" then
				v:StripWeapon("weapon_zm_improvised")
				v:Give("weapon_zm_improvisedd")
				v:SelectWeapon("weapon_zm_improvisedd")
			end
		end
			
		local crown = --Code that gets item equipped in the specified equipment slot ("hat", in this case)
		if --Code that returns the name of the item specified above-- == "Death's Crown" then
			v:SetColor( Color( 0, 0, 0, 200 ) ) 
		end
	end
end
hook.Add("TTTPrepareRound", "itemCheckerHook", itemcheckprepare)


And here is the one being broken:


if SERVER then
	local function stopsound()
		if not CheckSongPlaying() then
			ULib.consoleCommand( "ulx stopurlsound" .. "
" )
			SongPlaying = 0
			UrlSongPlaying = 0
		end
	end


	hook.Add ( "TTTPrepareRound", "serverstopgents", stopsound )
end

How do we know the second hook is not failing here:


if not CheckSongPlaying() then

Add print()s and see what gets called and what doesn’t.

Argh. In order to get anywhere with that I’ll have to re-enable RCON on my server. That will take some time, but I’ll go ahead and do it. In the meantime, I’m pretty sure that isn’t the issue. CheckSongPlaying() is an exceedingly simple function. All it does is check the status of a variable and return true or false depending on said variable. Plus, it works just find until I try to add in the other TTTPrepareRound hook on the other file.

EDIT: Ok, so it just randomly started working again for no reason. I hadn’t edited anything. No idea what’s going on here now. -_-

And how do we even know that there are no other functions for that hook that might be returning something?

I think I’m not entirely sure on how these things work. I’ve been pretty much doing LUA by trial-and-error so far. Your question is a good one, but to my understanding, that would not cause the issues I’m experiencing. If there was another function for that hook returning a value somewhere that I have not edited, wouldn’t it always override these hooks, instead of just sometimes?

If I’m incorrect about this, then my next issue is that I have no idea how to search for these other hooks, short of going through each and every file in every addon I have.

Well, yes and no. A function that returns doesn’t have to return all the time. There could be an if statement, and only within that if statement make a return.

A simple search using NPP’s search function, for the name of the hook, should yield the locations where a hook is being created.

Alright, I ran the function on our addons folder. Only got 3 hits, none of which return anything. Thanks for that by the way, I didn’t realize NPP had that function. That will be very useful for other things as well.

This is unrelated to your problem, but some of the code you posted above can be drastically shortened.
Try replacing your itemcheckprepare function with this;
[lua]
local items = {
[“Red Lightsaber”] = “r”,
[“Green Lightsaber”] = “g”,
[“Purple Lightsaber”] = “p”,
[“Draugr Axe”] = “a”,
[“Death Sword”] = “d”
}

function itemcheckprepare( )
if SEVER then
for _, p in pairs( player.GetAll( ) ) do
local spawnItem = --Code that gets item equipped in the specified equipment slot (“Melee”, in this case)
if items[ spawnItem ] ~= nil then
local newItem = “weapon_zm_improvised” … items[ spawnItem ]
p:StripWeapon( “weapon_zm_improvised” )
p:Give( newItem )
p:SelectWeapon( newItem )
end
local crown = --Code that gets item equipped in the specified equipment slot (“hat”, in this case)
if crown == “Death’s Crown” then
p:SetColor( Color( 0, 0, 0, 200 ) )
end
end
end
end
[/lua]

Ah, thanks for that Maurdekye. I’ve been meaning to do something like that but I hadn’t gotten around to looking up the exact syntax.