PAYDAY 2

PAYDAY 2

View Stats:
marijn211 May 16, 2018 @ 4:10am
Post hooks
Is there any guide about them?
Last edited by marijn211; May 16, 2018 @ 4:10am
< >
Showing 1-15 of 18 comments
marijn211 May 16, 2018 @ 4:11am 
I looked at the BLT documentation but that was incomplete
andole May 16, 2018 @ 9:35am 
local original_func = SomeClass.SomeFunc SomeClass:SomeFunc(args) -- Insert your PreHook code here original_func(self, args) -- Insert your Post hook code here end
Last edited by andole; May 16, 2018 @ 9:36am
Luffy May 16, 2018 @ 10:09am 
If you wish to do a PostHook which will be called after the orignal function you can do:

Hooks:PostHook(Class, "function_name", "posthook_name", function(self, [args...])

end)

Same thing with PreHook which is called before the original function, but is called Hooks:PreHook.

I won't recommend doing the above method for people who don't understand lua. If you ever use this method, you have to include '...'. So if overkill adds new arguments your mod won't break anything.
Last edited by Luffy; May 16, 2018 @ 10:10am
marijn211 May 16, 2018 @ 10:15am 
Ok I will look at it when I can remember stuff better again
marijn211 Jun 4, 2018 @ 12:57pm 
Hooks:PostHook(tweak_data, "MoneyTweakData:init", "Nociv", function(self, self.killing_civilian_deduction = 0) end)
How could I make this work?
Posting an example is also fine, I learned most programming languages by reading examples (because trial and error is a little hard withouth debugger)
Last edited by marijn211; Jun 4, 2018 @ 9:43pm
NewPJzuza Jun 4, 2018 @ 6:26pm 
Originally posted by marijn211:
Hooks:PostHook(tweak_data, "MoneyTweakData:init", "Nociv", function(self, self.killing_civilian_deduction = 0) end)
How could I make this work?
Posting an example is also fine, I learned most programming langueses by reading examples (because trial and error is a little hard withouth debugger)
I suggested re-read the whole original codes from https://bitbucket.org/TdlQ/payday-2-luajit/src/default/lib/tweak_data/moneytweakdata.lua You will see what's called "Class", and what's just a function's name and what's the variables that are declared from that function since it seems you missed understanding something...

Anyway, It should be....
Hooks:PostHook(MoneyTweakData, "init", "YOU POST HOOK's NAME which I guess it's Nociv", function(self, tweak_data) self.killing_civilian_deduction = 0 end)
Though your line of codes looks like something nasty...but I hope you have a good intention. Not just making some bad gameplay changing mods.
Last edited by NewPJzuza; Jun 4, 2018 @ 6:31pm
marijn211 Jun 4, 2018 @ 9:56pm 
Originally posted by Cash.net NewPJzuza:
Originally posted by marijn211:
Hooks:PostHook(tweak_data, "MoneyTweakData:init", "Nociv", function(self, self.killing_civilian_deduction = 0) end)
How could I make this work?
Posting an example is also fine, I learned most programming langueses by reading examples (because trial and error is a little hard withouth debugger)
I suggested re-read the whole original codes from https://bitbucket.org/TdlQ/payday-2-luajit/src/default/lib/tweak_data/moneytweakdata.lua You will see what's called "Class", and what's just a function's name and what's the variables that are declared from that function since it seems you missed understanding something...

Anyway, It should be....
Hooks:PostHook(MoneyTweakData, "init", "YOU POST HOOK's NAME which I guess it's Nociv", function(self, tweak_data) self.killing_civilian_deduction = 0 end)
Though your line of codes looks like something nasty...but I hope you have a good intention. Not just making some bad gameplay changing mods.
I just needed an example, the mod was already made withouth the use of posthooks but never uploaded because nobody seemed to want realistic weapon, loot and other values in Payday 2 even if they were balanced
Last edited by marijn211; Jun 4, 2018 @ 10:00pm
NewPJzuza Jun 4, 2018 @ 10:02pm 
Originally posted by marijn211:
I just needed an example, the mod was already made but never uploaded because nobody seems to want realistic weapon, loot and other values in Payday 2 even if they are balanced
No need to explain the reason if you know what to do. Anyway when you use a posthook. I suggest you use RequiredScript to check when the function is called and to call it in the proper time. For example
if RequiredScript == "lib/tweak_data/moneytweakdata" then Add your posthook here end
Last edited by NewPJzuza; Jun 4, 2018 @ 10:03pm
Luffy Jun 5, 2018 @ 12:15am 
Originally posted by Cash.net NewPJzuza:
Originally posted by marijn211:
I just needed an example, the mod was already made but never uploaded because nobody seems to want realistic weapon, loot and other values in Payday 2 even if they are balanced
No need to explain the reason if you know what to do. Anyway when you use a posthook. I suggest you use RequiredScript to check when the function is called and to call it in the proper time. For example
if RequiredScript == "lib/tweak_data/moneytweakdata" then Add your posthook here end
This is mostly not required unless you have a few hooked scripts in one file also you can shorten it to
local F = table.remove(RequiredScript:split("/")) if F == "moneytweakdata" then elseif F == "otherfile" then end
Most scripts have a different name so we can use that to just use the file name and not full path.
Last edited by Luffy; Jun 5, 2018 @ 12:16am
marijn211 Jun 13, 2018 @ 6:56am 
I made some script but it only loads the first hook:
if not Network:is_server() then return end Hooks:PostHook(PlayerManager, "_set_body_bags_amount", "DragnotBag2", function(self) self._local_player_body_bags = 0 managers.hud:on_ext_inventory_changed() end) Hooks:PostHook(PlayerManager, "chk_body_bags_depleted", "DragnotBag3", function() return false end) Hooks:PostHook(PlayerManager, "has_max_body_bags", "DragnotBag4", function() return true end) Hooks:PostHook(PlayerManager, "on_used_body_bag", "DragnotBag5", function() self:_set_body_bags_amount(0) end)
What did I do wrong?
(The other file my mod changes did work)
Last edited by marijn211; Jun 13, 2018 @ 7:05am
andole Jun 13, 2018 @ 7:23am 
Originally posted by marijn211:
What did I do wrong?
Maybe it does not like functions that simply return a value?
Change returns to something like:
if true then return false end
marijn211 Jun 13, 2018 @ 7:24am 
Originally posted by andole:
Originally posted by marijn211:
What did I do wrong?
Maybe it does not like functions that simply return a value?
Change returns to something like:
if true then return false end
I will try
marijn211 Jun 13, 2018 @ 7:32am 
I could now pick up the first body but the second was blocked
marijn211 Jun 13, 2018 @ 10:38am 
I now have this:
if not Network:is_server() then return end Hooks:PostHook(PlayerManager, "_set_body_bags_amount", "DragnotBag2", function(self) self._local_player_body_bags = 0 managers.hud:on_ext_inventory_changed() end) Hooks:PostHook(PlayerManager, "chk_body_bags_depleted", "DragnotBag3", function() return self._local_player_body_bags = 100 end) Hooks:PostHook(PlayerManager, "has_max_body_bags", "DragnotBag4", function() if false then return true end) Hooks:PostHook(PlayerManager, "on_used_body_bag", "DragnotBag5", function() self:_set_body_bags_amount(0) end) Hooks:PostHook(PlayerManager, "total_body_bags", "DragnotBag6", function() local bags = self:upgrade_value("player", "corpse_dispose_amount", 1000) bags = managers.crime_spree:modify_value("PlayerManager:GetTotalBodyBags", bags) return bags end)
The HUDs use a different number than the game checks so I might set the HUD to 0 and the real to 100
Last edited by marijn211; Jun 13, 2018 @ 11:01am
Why would one choose a prehook or a posthook? Lets say the original function has this line.

allow_fire = yes

If I wanted to change this so it was

allow_fire = no

Would you do a prehook or posthook? If I did pre then would the original value be what is used since it is being called after my modified version?

In general I am always a bit confused whether to use a prehook or a posthook. Is there a general rule of thumb or any information?

Thanks!
< >
Showing 1-15 of 18 comments
Per page: 1530 50

Date Posted: May 16, 2018 @ 4:10am
Posts: 18