bradio10 Posted June 9, 2013 Share Posted June 9, 2013 Hi, I have seen some scripts and they have there own custom made event handlers. I just want to know, where do I start so I can make my own? Sorry, I don't have a script to show you because I have no clue on where to start making one. I know how to make exports, just not event handlers. Thanks. Link to comment
Tete omar Posted June 9, 2013 Share Posted June 9, 2013 Just use addEvent triggerEvent . Link to comment
bradio10 Posted June 10, 2013 Author Share Posted June 10, 2013 I mean, like some servers have it like onPlayerResign for a script that have made. Since onPlayerResign isn't in the wiki, they must have made it themselves, so I want to know how I can make my own. Link to comment
xXMADEXx Posted June 10, 2013 Share Posted June 10, 2013 I guess you could use something like this: -- CLIENT -- button = createButton ( 0, 0, 50, 25, "Register", false ) addEventHandler ( "onClientGUIClick", root, -- I use "Root" because, if you use the "button" it will make a weird bug function ( ) if ( source == button ) then triggerServerEvent ( "onPlayerRegister", localPlayer ) end end ) -- SERVER -- addEvent ( "onPlayerRegister", true ) addEventHandler ( "onPlayerRegister", root, function ( ) outputChatBox ( getPlayerName ( source ).." HAS REGISTERED!", root, 0, 255, 0 ) end ) Link to comment
bradio10 Posted June 10, 2013 Author Share Posted June 10, 2013 nono, I mean so the event can be universal for all scripts. So, if I made a core script and it contained something like onPlayerResigned. Then I made a job so when he resigns, he gets some cash, so I would use the event handler as onPlayerResigned. Get what I mean? Like an export so I can use it in other scripts. Link to comment
Tete omar Posted June 10, 2013 Share Posted June 10, 2013 Yet again, use these funcitions: Just use addEvent triggerEvent . First one is to add your custom event. Second one is to trigger your custom event. Link to comment
xXMADEXx Posted June 10, 2013 Share Posted June 10, 2013 nono, I mean so the event can be universal for all scripts.So, if I made a core script and it contained something like onPlayerResigned. Then I made a job so when he resigns, he gets some cash, so I would use the event handler as onPlayerResigned. Get what I mean? Like an export so I can use it in other scripts. I guess you could use something like this: -- CLIENT -- button = createButton ( 0, 0, 50, 25, "Register", false ) addEventHandler ( "onClientGUIClick", root, -- I use "Root" because, if you use the "button" it will make a weird bug function ( ) if ( source == button ) then triggerServerEvent ( "onPlayerRegister", localPlayer ) end end ) -- SERVER -- addEvent ( "onPlayerRegister", true ) addEventHandler ( "onPlayerRegister", root, function ( ) outputChatBox ( getPlayerName ( source ).." HAS REGISTERED!", root, 0, 255, 0 ) end ) ^^ That is what that code will do. Link to comment
Blaawee Posted June 10, 2013 Share Posted June 10, 2013 Maybe this could help you : Using TableTry this (but debug first i made it in 2 Minutes without checking for bugs or else) -- Pleas add [TiLex Produkt] as commentary to your script while using this addEvent("onPlayerHealthChange", true) local playerOldHealthTable = {} function healthChangedTriggerFunction() setTimer(function() local playerTable = getElementsByType("player") for index, player in ipairs(playerTable) do local oldLive = playerOldHealthTable[player] if oldLive and (oldLive > 0) then local curLive = getElementHealth(player) if not (curLive == oldLive) then local changedlive = 0 if (curLive > oldLive) then changedlive = (curLive - oldLive) else changedlive = (oldLive - curLive) end triggerEvent ( "onPlayerHealthChange", player, player, curLive, oldLive, changedlive) -- trigger Event playerOldHealthTable[player] = curLive end else playerOldHealthTable[player] = (getElementHealth(player)) end end end, 500, 0) end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), healthChangedTriggerFunction) -- EXAMPEL FUNKTION FOR EVENT function healthChanged(player, newHealth, oldHealth, changedLive) -- Live changed. Here some stuff outputChatBox("Your Live had changed from " ..tostring(oldHealth).. " to " ..tostring(newHealth)), player, 255, 0, 0) end addEventHandler("onPlayerHealthChange", getRootElement(), healthChanged) EventName: onPlayerHealthChange Parameters: element Player, int newhealth, int oldHealth, int howManyHealthChanged [sERVERSIDE] Link to comment
Sasu Posted June 10, 2013 Share Posted June 10, 2013 A script more short. function onAdminWasted(_, killer) if killer and getElementType(killer) == "player" then local playerAcc = getPlayerAccount(source) local accName = getAccountName(playerAcc) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then triggerEvent("onAdminWasted", source, killer) end end end addEventHandler("onPlayerWasted", root, onAdminWasted) --Another Resource addEvent("onAdminWasted", true) function testMyNewEvent(thePlayer)--Parameters(1) : thePlayer : player who killed the admin. Source: the source of this event is the admin who was killed. kickPlayer(thePlayer, "You dont allowed to kill an admin.") outputChatBox("The player '"..getPlayerName(thePlayer).."' has been kicked because he/she killed you.", source, 0, 255, 0, true) end addEventHandler("onAdminWasted", root, testMyNewEvent) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now