Jump to content

What is more efficient


Drakath

Recommended Posts

And those custom events call a function. It's basically the same thing.

No, here is explanation...

You should call functions in same file like function(arg) while you have a choice triggerEvent, say you made your own event like "onClientDepositMoney" but this event will not be triggered unless you make it happen manually, in this case, you'll use 'triggerEVent' within SAME file, now when you add "onClientDepositMoney" EXTERNALLY in some other script, the event will be triggered on original script and will call the function from OTHER script too, here is example:

-- atms_c.lua 
function confirmDeposit(acc, money) -- Acc is account of player, got from serverside ofcourse while money is numeric value. 
    if (not money) or (not acc) then return end 
    local prev = getAccountData(acc, "atms.money") or 0 
    setAccountData(acc, "atms.money", tonumber(prev) + money) 
    triggerEvent("onDepositMoney", root, getAccountName(acc), money) 
end 
addEventHandler("onClientGUIClick", deposit_btn, confirmDeposit, false) 
addEvent("onDepositMoney", true) -- Make event trigger-able externally... 

Now some other resource, some other file:

-- logs_c.lua 
function writeLog(acc, money) 
    if (not acc) or (not money) then return end 
    writeLog(acc, "Player has deposited $"..money.."in his bank.") 
end 
addEventHandler("onDepositMoney", root, writeLog) 

Link to comment
And those custom events call a function. It's basically the same thing.

No, here is explanation...

You should call functions in same file like function(arg) while you have a choice triggerEvent, say you made your own event like "onClientDepositMoney" but this event will not be triggered unless you make it happen manually, in this case, you'll use 'triggerEVent' within SAME file, now when you add "onClientDepositMoney" EXTERNALLY in some other script, the event will be triggered on original script and will call the function from OTHER script too, here is example:

-- atms_c.lua 
function confirmDeposit(acc, money) -- Acc is account of player, got from serverside ofcourse while money is numeric value. 
    if (not money) or (not acc) then return end 
    local prev = getAccountData(acc, "atms.money") or 0 
    setAccountData(acc, "atms.money", tonumber(prev) + money) 
    triggerEvent("onDepositMoney", root, getAccountName(acc), money) 
end 
addEventHandler("onClientGUIClick", deposit_btn, confirmDeposit, false) 
addEvent("onDepositMoney", true) -- Make event trigger-able externally... 

Now some other resource, some other file:

-- logs_c.lua 
function writeLog(acc, money) 
    if (not acc) or (not money) then return end 
    writeLog(acc, "Player has deposited $"..money.."in his bank.") 
end 
addEventHandler("onDepositMoney", root, writeLog) 

Wow, that's a really nice feature. Thank you for a nice explanation :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...