Making custom hooks help?

So I am trying to make a function which can be called by a logger with hook.Add (Trying to make my own hitman system, which also has logging support)
Example - https://github.com/myrage2000/ulogs/blob/master/ultimatelogs/lua/ultimatelogs/logtypes/ulogs_darkrp_hitman.lua

Only thing I have come up with so far…



function HitAccept( player, target )

end


I have no clue, and cannot find anywhere, how to make a custom hook.Add which can return information.
The closest thing I found was http://wiki.garrysmod.com/page/hook/Call, but that doesn’t seem to be what I want.

Thanks!



hook.Add( "HitAccept", "HitAccept", function( player, target )
	--put your code here
end )


Thanks, I am still confused with how I define the hook. Do you just put the global function’s name in the first parameter of the hook?

Thanks, but I already saw that and can’t see any information on there about creating custom hooks, only adding to existing ones.

[editline]5th May 2016[/editline]

Unless you can make a hook out of thin air so it has no reference?
Then would I just use hook.Call to make stuff run on the hook.add events with the unique made up event?
Worded that part badly - hook.Add( string eventName, any identifier, function func ), so does the event have to be something which already exists?


function HitAccept(player, target)

	target:ChatPrint("If you give me enough money, I'll kill my cousin")

end

hook.Add("HitManStuff", "UniqueName", function(player, target)

	
	target:ChatPrint("If you give me enough money, I'll show you a good time.")


end)

Okay so HitManStuff is our made up function. Initially we’ve created it.
To avoid overwriting that function we use a hook to basically build upon what is there.
So we did


hook.Add("HitManStuff", "UniqueName", function(player, target)

	
	target:ChatPrint("If you give me enough money, I'll show you a good time.")


end)

The first string is the function name, in this case "HitManStuff ". Second string is the unique name, that can be anything ranging from balls to tits. 3rd is the function that we want to add in.
So the output would be “If you give me enough money, I’ll kill my cousin” and “If you give me enough money, I’ll show you a good time.”
I’m not really sure what you’re asking, but I hope this helps.

[editline]4th May 2016[/editline]

If you’re still confused, don’t be afraid to ask questions. I know sometimes you have to ask things multiple times in different ways due to the fact that you don’t even know what you’re asking. (I know from experience)

That really helps!

One more thing, would I use



hook.Call("HitManStuff", "UniqueName", ply, target ) 


to run the code in the hook which would for example set a hit? Also, would I then use something like



hook.Add( "HitManStuff", "UniqueName", function( player, target )
target:ChatPrint("Oi, someone placed a hit on you. This is being logged")
end)


which would run when the hook is called so I could use that to make a basic log?

Thanks!

To run the code you’ll need to find a function to call it in.
For example,



hook.Add("PlayerInitialSpawn", "titsandballs", function()

	HitManStuff(player, target)

end)


PlayerInitialSpawn is a function which is called when a player initially spawns. Right now we are running the function HitManStuff in PlayerInitialSpawn.
So when a player first joins it’s going to run everything that’s in the function GM:PlayerInitialSpawn() and then since we’ve hooked the function HitManStuff
to PlayerInitialSpawn it will now run the function HitManStuff and hook.Add("HitManStuff " blahblahblah)

To give you the very simple answer: Yes, you can hook.Add non-default event names and they will then work when you hook.Call the same new event name, essentially creating a new hook event. Any argument passed to hook.Call also gets passed to all hook.Adds there may be, and any of these returning anything will get returned by the initial hook.Call.

Thanks, I think I understand it now :smiley: