lr_boilerplate/client/impl/test2.impl.lua

39 lines
935 B
Lua
Raw Normal View History

2023-12-05 15:00:07 +07:00
local Impl = NewImpl("Test2")
function Impl:OnReady()
self:MainThread()
self:TestHook()
self:TestReplaceMethod()
end
function Impl:MainThread()
local testImpl = main:GetImpl("Test")
Citizen.CreateThread(function()
while true do
Wait(1000)
local result = testImpl:Add(1, 2)
main:LogInfo("TestImpl result %s", result)
end
end)
end
function Impl:TestHook()
local testImpl = main:GetImpl("Test")
testImpl:HookMethod("Add", function(self, amount, amount2)
return amount+1, amount2
end)
end
function Impl:TestReplaceMethod()
Citizen.CreateThread(function()
Wait(5000)
local testImpl = main:GetImpl("Test")
local oldMethod = testImpl:GetMethod("Add")
testImpl:ReplaceMethod("Add", function(self, amount, amount2)
self.testVar = self.testVar * amount * amount2
return self.testVar
end)
Wait(5000)
testImpl:ReplaceMethod("Add", oldMethod)
end)
end