mrvicio Posted November 15, 2011 Share Posted November 15, 2011 hi all there is a way to make this script without the if? addEventHandler ( "onResourceStart",getRootElement() , function(res) if getResourceName ( res )=="scoreboard" then restartResource (getThisResource ()) end end) i have tried something like as the example below, but it dont work addEventHandler ( "onResourceStart",getResourceFromName("scoreboard") , --i know that getResourceFromName("scoreboard") is not an element, but its only referential of what i want =p function(res) restartResource (getThisResource ()) end) im trying to make the script the most eficient posible Link to comment
Jaysds1 Posted November 15, 2011 Share Posted November 15, 2011 you don't have to use the if Link to comment
mrvicio Posted November 15, 2011 Author Share Posted November 15, 2011 how can i do it whithout the if? Link to comment
Jaysds1 Posted November 15, 2011 Share Posted November 15, 2011 try this: addEventHandler("onResourceStart",getResourceRootElement(getResourceFromName("scoreboard"), function(res) restartResource(res) end) Link to comment
Castillo Posted November 15, 2011 Share Posted November 15, 2011 addEventHandler ( "onResourceStart",getRootElement() , function(res) if tostring(getResourceName ( res )) == "scoreboard" then restartResource (res) end end) You we're trying to restart the resource from where that script is executed, not the resource that just started. Link to comment
AGENT_STEELMEAT Posted November 15, 2011 Share Posted November 15, 2011 Your going to cause an infinite loop with that. Not to mention your forgot a ')'. I am assuming you want to restart the scoreboard every time another resource is started. In that case: --This function is executed when a resource starts, it restarts the scoreboard (UNLESS it was the scoreboard that was reset). local function resourceStart(startedResource) local resourceName = getResourceName(startedResource) if resourceName ~= "scoreboard" then restartResource(getResourceFromName("scoreboard")) end end addEventHandler("onResourceStart", root, resourceStart) Link to comment
mrvicio Posted November 15, 2011 Author Share Posted November 15, 2011 Jaysds1 got the idea of (i dont want to use "IF" ) let me try and i will come back Link to comment
AGENT_STEELMEAT Posted November 15, 2011 Share Posted November 15, 2011 Why don't you want to use an if statement, that makes no sense. Link to comment
mrvicio Posted November 15, 2011 Author Share Posted November 15, 2011 because i don't want to do a comparison on every resource that start,that is inefficient way, i must attach the handler to the specific resource but i dont know how Link to comment
12p Posted November 15, 2011 Share Posted November 15, 2011 addEventHandler ( "onResourceStart", getResourceRootElement ( getResourceFromName ( "scoreboard" ) ), function ( ) --do something end, false ) Maybe that? Link to comment
AGENT_STEELMEAT Posted November 15, 2011 Share Posted November 15, 2011 that is inefficient way Well then what exactly are you trying to do? Also, a single if statement is not going to be noticeable. Link to comment
Castillo Posted November 15, 2011 Share Posted November 15, 2011 addEventHandler ( "onResourceStart", getResourceRootElement ( getResourceFromName ( "scoreboard" ) ), function ( ) --do something end, false ) Maybe that? But, if you keep restarting the resource when it starts, it'll end into a loop... Link to comment
KrSoFA Posted November 15, 2011 Share Posted November 15, 2011 function restart() local resourceName = getResourceFromName("scoreboard") if getResourceState(resourceName) == "running" then restartResource(resourceName) end end addEventHandler("onResourceStart", getRootElement(), restart) Link to comment
AGENT_STEELMEAT Posted November 15, 2011 Share Posted November 15, 2011 That exactly the same as what I posted, but incorrect. The OP needs to post what he wants to do, not "is this correct" or "i want no if statements". Link to comment
mrvicio Posted November 15, 2011 Author Share Posted November 15, 2011 dont get mad of me if my gamemode includes 10 resources, and each one have an (if statement) one single time, when i restart my gamemode it will run 100 times: S, thats what i dont like, but if im wrong tell me, i can make mistakes too by the way, the element getResourceRootElement(getResourceFromName("scoreboard")) on the EventHandler dont work, it dont do anything Link to comment
AGENT_STEELMEAT Posted November 15, 2011 Share Posted November 15, 2011 I'm not mad, i'm just trying to emphasize that you need to be clear about what you want. You still have not told us. Link to comment
Jaysds1 Posted November 15, 2011 Share Posted November 15, 2011 Ok, he wants a script with no "if" 's, "then", "else", and "end"... He just want the resource to restart by it's self and not the whole gamemode..., get it? Link to comment
AGENT_STEELMEAT Posted November 15, 2011 Share Posted November 15, 2011 What resource to restart itself? And not having if statements is dumb. Link to comment
Jaysds1 Posted November 15, 2011 Share Posted November 15, 2011 He's not putting this script in the resource he's restarting "DUH", and not having if statements is not dumb, it depends on what your doing with the code... Link to comment
AGENT_STEELMEAT Posted November 16, 2011 Share Posted November 16, 2011 Which he should be explaining. Link to comment
mrvicio Posted November 16, 2011 Author Share Posted November 16, 2011 y have my resource "legalsystem" and its its the code example call(getResourceFromName("scoreboard"), "addScoreboardColumn", "WantedLevel") function player_Wasted ( ammo, attacker, weapon, bodypart ) if ( attacker ) then if ( getElementType ( attacker ) == "player" ) then local wantedLevel = getPlayerWantedLevel ( attacker ) if wantedLevel < 6 then setPlayerWantedLevel ( attacker, 1+wantedLevel ) end setElementData ( attacker, "WantedLevel", getElementData(attacker,"WantedLevel")+1 ) -- refresh WantedLevel scoreboard end end end addEventHandler ( "onPedWasted", getRootElement(), player_Wasted ) addEventHandler ( "onResourceStart",getRootElement() , function(res) if getResourceName ( res )=="scoreboard" then restartResource (getThisResource ()) end end) without the evenHandler "onResourcestart" when the resource scoreboard restart, it dont show anymore the table "WantedLevel" in the scoreboard, because this resource "legalsystem" must be restarted in a few words i want when the resourse scoreboard start, restart legalsystem resourse(this). im writing this script in the legalsystem resource any more questions? Link to comment
AGENT_STEELMEAT Posted November 16, 2011 Share Posted November 16, 2011 (edited) So, when the scoreboard resource starts, you want to restart the resource? No problem: local function resourceStart() restartResource(resource) end addEventHandler("onResourceStart", getResourceRootElement(getResourceFromName("scoreboard")), resourceStart) Best of all, no if statements. Edited November 16, 2011 by Guest Link to comment
Cadu12 Posted November 16, 2011 Share Posted November 16, 2011 Im not sure, if it will lagger becuase of onResourceStart + restartResource Link to comment
AGENT_STEELMEAT Posted November 16, 2011 Share Posted November 16, 2011 What, that's right, I posted an infinite loop. Now that I step back and think about it, why are you restarting the resource? Just re-add the columns... local function resourceStart() exports.scoreboard:scoreboardAddColumn(name) end addEventHandler("onResourceStart", getResourceRootElement(getResourceFromName("scoreboard")), resourceStart) Link to comment
mrvicio Posted November 16, 2011 Author Share Posted November 16, 2011 i said before the attached element to the event "getResourceRootElement(getResourceFromName("scoreboard"))" dont work im thinking that it is imposible without an if statement im trying to restart "legalsystem-resource" when "scoreboard-resource" start 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