Jump to content

Variable for all


DjMixCuma

Recommended Posts

Posted
local welcomeText = "Hello World!" 
  
addEventHandler ( "onPlayerJoin", root,  
    function ( ) 
        outputChatBox ( welcomeText, source ) 
    end 
) 

That'll output the 'welcomeText' content to all players who join the server.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

solidsnake i want set this for example:

local can = {} 
  
if can[source].command == true then 
-- all players can use this command 
else 
-- no all players can use this command 
  

so how to set can[source].command (for example) for all players??

Posted

That's a table, not a variable.

And you can remove all that [ source ] and leave it like this:

local can = { }

if can.command == true then 
-- all players can use this command 
else 
-- no all players can use this command 
end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

okey working but how to on start resource give permission to start command?

my code:

local can = {} 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() 
    can.Command = true 
end 
  
function start() 
    if can.Command == true then 
        setTimer(stop, 5000, 1) 
        can.Command = false 
outputChatBox("Can!", 255, 255, 255, true) 
    else 
        outputChatBox("Can't!", 255, 255, 255, true) 
    end 
end 
  
function stop() 
    can.Command = true 
outputChatBox("Now Can Again!", 255, 255, 255, true) 
end 
addCommandHandler("test", start) 

Posted

I don't understand.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

When i spawn i want to use /test, but i cant because table is false default in this construction of code:

local can = {} 
  
function start() 
    if can.Command == true then 
        setTimer(stop, 5000, 1) 
        can.Command = false 
outputChatBox("Can!", 255, 255, 255, true) 
    else 
        outputChatBox("Can't!", 255, 255, 255, true) 
    end 
end 
  
function stop() 
    can.Command = true 
outputChatBox("Now Can Again!", 255, 255, 255, true) 
end 
addCommandHandler("test", start) 

but when i using this:

local can = {} 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() 
    can.Command = true 
end 
  
function start() 
    if can.Command == true then 
        setTimer(stop, 5000, 1) 
        can.Command = false 
outputChatBox("Can!", 255, 255, 255, true) 
    else 
        outputChatBox("Can't!", 255, 255, 255, true) 
    end 
end 
  
function stop() 
    can.Command = true 
outputChatBox("Now Can Again!", 255, 255, 255, true) 
end 
addCommandHandler("test", start) 

command not working, but when i use this:

local can = {} 
 function start() 
can.Command = true 
    if can.Command == true then 
        setTimer(stop, 5000, 1) 
        can.Command = false 
outputChatBox("Can!", 255, 255, 255, true) 
    else 
        outputChatBox("Can't!", 255, 255, 255, true) 
    end 
end 
  
function stop() 
    can.Command = true 
outputChatBox("Now Can Again!", 255, 255, 255, true) 
end 
addCommandHandler("test", start) 

i can use command infinitely

Posted

Wiki quote:

Note: You cannot use "list" or "test" as command name.
local can = { } 
  
function start ( player ) 
    if ( can.Command == true ) then 
        setTimer ( stop, 5000, 1 ) 
        can.Command = false 
        outputChatBox ( "Can!", player, 255, 255, 255, true ) 
    else 
        outputChatBox ( "Can't!", player, 255, 255, 255, true ) 
    end 
end 
addCommandHandler ( "test2", start ) 
  
function stop ( ) 
    can.Command = true 
    outputChatBox ( "Now Can Again!", root, 255, 255, 255, true ) 
end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
local can = 
    { 
        command = true 
    } 
  
function start ( player ) 
    if ( can.Command == true ) then 
        setTimer ( stop, 5000, 1 ) 
        can.Command = false 
        outputChatBox ( "Can!", player, 255, 255, 255, true ) 
    else 
        outputChatBox ( "Can't!", player, 255, 255, 255, true ) 
    end 
end 
addCommandHandler ( "test2", start ) 
  
function stop ( ) 
    can.Command = true 
    outputChatBox ( "Now Can Again!", root, 255, 255, 255, true ) 
end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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