Jump to content

on espesific resource start do something


mrvicio

Recommended Posts

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

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
function restart() 
    local resourceName = getResourceFromName("scoreboard") 
    if getResourceState(resourceName) == "running" then 
            restartResource(resourceName) 
       end 
end 
addEventHandler("onResourceStart", getRootElement(), restart) 

Link to comment

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

Link to comment

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

Link to comment

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
Link to comment

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

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