Jump to content

Resource Restart


isa_Khamdan

Recommended Posts

Hello , I made this function triggered to the server side , The function Restarts the resource named with player name so if your name is Player it will restart the resource name Player if it exists but I tested it and it's not working so can anyone tell me how to fix this problem?

addEvent("Restart",true) 
addEventHandler("Restart",root, 
  
  
  
    function() 
  
        local account = getPlayerAccount(source) -- get account element from player element 
        local accname = getAccountName(account) -- get account name from account element 
        local RestartResource = getResourceFromName ( "accname" ) 
        if isObjectInACLGroup("user."..accname,aclGetGroup("PCS")) then 
        if ( RestartResource and theResource == RestartResource ) then  
        restartResource(RestartResource) 
  
  
        
end 
    end 
end 
  
) 

The trigger in the client side

addEventHandler("onClientGUIClick", root, function(Restart) 
  if source == PCSbutton5 then 
   
            triggerServerEvent("Restart",root,thePlayer) 
  
  
        end 
   end 

Link to comment

I'm not on my phone right now, hang on. Checking your script

edit; you didn't define the source but you did give 'thePlayer' as a variable in your client. try this;

server;

addEvent("Restart",true) 
addEventHandler("Restart",root, 
    function( thePlayer )  
        local account = getPlayerAccount ( thePlayer ); 
        local accname = getAccountName ( account ); 
        local RestartResource = getResourceFromName ( tostring( accname ) ); 
        if ( isObjectInACLGroup( "user." .. accname , aclGetGroup ( "PCS" ) ) then 
            if ( RestartResource and theResource == RestartResource ) then 
                restartResource(RestartResource) 
            end 
        end 
    end  
); 

client;

  
addEventHandler("onClientGUIClick", root,  
    function(Restart) 
        if ( source == PCSbutton5 ) then  
            triggerServerEvent("Restart",root, localPlayer);  
        end 
    end 
); 

Link to comment
I'm not on my phone right now, hang on. Checking your script

edit; you didn't define the source but you did give 'thePlayer' as a variable in your client. try this;

server;

addEvent("Restart",true) 
addEventHandler("Restart",root, 
    function( thePlayer )  
        local account = getPlayerAccount ( thePlayer ); 
        local accname = getAccountName ( account ); 
        local RestartResource = getResourceFromName ( tostring( accname ) ); 
        if ( isObjectInACLGroup( "user." .. accname , aclGetGroup ( "PCS" ) ) then 
            if ( RestartResource and theResource == RestartResource ) then 
                restartResource(RestartResource) 
            end 
        end 
    end  
); 

client;

  
addEventHandler("onClientGUIClick", root,  
    function(Restart) 
        if ( source == PCSbutton5 ) then  
            triggerServerEvent("Restart",root, localPlayer);  
        end 
    end 
); 

Error in line 7 ) expected near then

Link to comment

My bad;

addEvent( "Restart" , true ); 
addEventHandler( "Restart" , root, 
    function( thePlayer ) 
        local account = getPlayerAccount ( thePlayer ); 
        local accname = getAccountName ( account ); 
        local RestartResource = getResourceFromName ( tostring( accname ) ); 
        if ( isObjectInACLGroup( "user." .. accname , aclGetGroup ( "PCS" ) ) ) then 
            if ( RestartResource ) then 
                restartResource( RestartResource ) 
            end 
        end 
    end 
); 

oh and btw, you didn't define this variable before;

theResource 

Did you define it somewhere else cause I removed it right now.

Link to comment
My bad;
addEvent( "Restart" , true ); 
addEventHandler( "Restart" , root, 
    function( thePlayer ) 
        local account = getPlayerAccount ( thePlayer ); 
        local accname = getAccountName ( account ); 
        local RestartResource = getResourceFromName ( tostring( accname ) ); 
        if ( isObjectInACLGroup( "user." .. accname , aclGetGroup ( "PCS" ) ) ) then 
            if ( RestartResource ) then 
                restartResource( RestartResource ) 
            end 
        end 
    end 
); 

oh and btw, you didn't define this variable before;

theResource 

Did you define it somewhere else cause I removed it right now.

hmm I think it's not defined because when I click on the restart button it doesn't do anythings ( no errors ) and in console this message appear " voiceptt: This server does not have voice enabled "

Link to comment

Well I can tell you for what it's getting used. The onResourceStart eventHandler returns a variable called theResource. So they can say if a type of resource is restarted.

why are you even adding 1 eventHandler for all the buttons? If I may ask. You can simply do this;

addEventHandler ( "onClientGUIClick", gui["_gameInterface_quitlbl"], btnRestart, false ); 
  
function btnRestart() 
-- todo 
end 

Give me your client-side script. :3

Link to comment
Well I can tell you for what it's getting used. The onResourceStart eventHandler returns a variable called theResource. So they can say if a type of resource is restarted.

why are you even adding 1 eventHandler for all the buttons? If I may ask. You can simply do this;

addEventHandler ( "onClientGUIClick", gui["_gameInterface_quitlbl"], btnRestart, false ); 
  
function btnRestart() 
-- todo 
end 

Give me your client-side script. :3

the button name is PCSbutton5

addEventHandler("onClientGUIClick", root,  
  
    function(Restart) 
  
        if ( source == PCSbutton5 ) then  
  
            triggerServerEvent("Restart",root, localPlayer);  
  
        end 
  
    end 
  
); 
  
addEventHandler("onClientGUIClick", root, function(Arrow) 
  
    if ( source == PCScheckbox2 ) then 
  
           if not (isPedInVehicle ( localPlayer ) ) then 
  
    guiCheckBoxSetSelected(PCScheckbox2,false) 
  
        end 
  
        if guiCheckBoxGetSelected(PCScheckbox2) then 
  
            triggerServerEvent("Arrow",localPlayer) 
  
        else 
  
            triggerServerEvent("Arrow",localPlayer) 
  
end 
  
end 
  
end ) 
  
addEventHandler("onClientGUIClick", root, function() 
  if source == PCSbutton2 then 
    guiSetVisible(windowPCS, false) 
    showCursor(false) 
  end 
end 
) 
  
addEventHandler("onClientGUIClick", root, function(Spawn) 
  if source == PCSbutton3 then 
   
            triggerServerEvent("Spawn",localPlayer) 
  
  
        end 
   end 
)    
  
addEventHandler("onClientGUIClick", root, function(Warp) 
  if source == PCSbutton4 then 
   
            triggerServerEvent("Warp",localPlayer) 
  
  
        end 
   end 
)    
  
  

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