Jump to content

on espesific resource start do something


mrvicio

Recommended Posts

Posted

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 :)

Posted

try this:

addEventHandler("onResourceStart",getResourceRootElement(getResourceFromName("scoreboard"), 
function(res) 
    restartResource(res) 
end) 

Posted
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.

Posted

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) 
  

Posted

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 xD

Posted
addEventHandler ( "onResourceStart", getResourceRootElement ( getResourceFromName ( "scoreboard" ) ), 
function ( ) 
--do something 
end, false ) 

Maybe that?

Posted
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...

Posted
function restart() 
    local resourceName = getResourceFromName("scoreboard") 
    if getResourceState(resourceName) == "running" then 
            restartResource(resourceName) 
       end 
end 
addEventHandler("onResourceStart", getRootElement(), restart) 

Posted

dont get mad of me xD

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 xD

by the way, the element

getResourceRootElement(getResourceFromName("scoreboard"))

on the EventHandler dont work, it dont do anything xD

Posted

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?

Posted

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...

Posted

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? :P

Posted (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 by Guest
Posted

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) 
  

Posted

i said before

the attached element to the event "getResourceRootElement(getResourceFromName("scoreboard"))" dont work
:S

im thinking that it is imposible without an if statement :S

im trying to restart "legalsystem-resource" when "scoreboard-resource" start :P

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...