Jump to content

addEventHadler to addCommandHandler


Recommended Posts

  
localPlayer = getLocalPlayer() 
  
wnd_window = {} 
  
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ),   
    function ( theResource ) 
        --outputConsole( "wnd_showServerInfo called" ) 
        --outputConsole( " Fonte: ".. tostring( source ) ) 
        --outputConsole( " resourceStarted: ".. tostring( theResource ) ) 
        if source == getResourceRootElement( theResource ) then 
            --outputConsole( " passed if: source == resource" ) 
            local xml = xmlLoadFile( "server.xml" ) 
            local contents = xmlNodeGetValue( xml ) 
            wnd_create( "Seja Bem Vindo Ao Servidor", "logo.png", contents ) 
        end 
    end 
) 
  
function wnd_close() 
    guiSetVisible( wnd_window.wnd, false ) 
    showCursor( false ) 
end 
  
addEvent( "window_text", true ) 
function wnd_create( title, logo, content ) 
    --outputConsole( "wnd_create called" ) 
    if not wnd_window.wnd then 
        --outputConsole( " passed if" ) 
        wnd_window.wnd = guiCreateWindow( 0.1, 0.15, 0.8, 0.7, title, true ) 
        guiWindowSetSizable( wnd_window.wnd, false ) 
        guiWindowSetMovable( wnd_window.wnd, false ) 
         
        wnd_window.logo = guiCreateStaticImage( 0.01, 0.035, 1.40, 0.25, logo, true, wnd_window.wnd ) 
  
        --wnd_window.text = content- 
        wnd_window.memo = guiCreateMemo( 0, 0.3, 1, .6, content, true, wnd_window.wnd ) 
        guiMemoSetReadOnly( wnd_window.memo, true ) 
  
        wnd_window.close_btn = guiCreateButton( 0, .91, .3, 1, "Fechar", true, wnd_window.wnd ) 
        --outputConsole( " window created: ".. tostring( wnd_window.wnd ) ) 
        showCursor( true ) 
        addEventHandler( "onClientGUIClick", wnd_window.close_btn, wnd_close ) 
    end 
end 
addEventHandler( "window_text", getRootElement(), wnd_create ) 
  

I'm trying to do this:

localPlayer = getLocalPlayer() 
  
wnd_window = {} 
  
addCommandHandler( "beneficios", getResourceRootElement( getThisResource() ),   
    function ( theResource ) 
        --outputConsole( "wnd_showServerInfo called" ) 
        --outputConsole( " Fonte: ".. tostring( source ) ) 
        --outputConsole( " resourceStarted: ".. tostring( theResource ) ) 
        if source == getResourceRootElement( theResource ) then 
            --outputConsole( " passed if: source == resource" ) 
            local xml = xmlLoadFile( "server.xml" ) 
            local contents = xmlNodeGetValue( xml ) 
            wnd_create( "Seja Bem Vindo Ao Servidor", "logo.png", contents ) 
        end 
    end 
) 
  
function wnd_close() 
    guiSetVisible( wnd_window.wnd, false ) 
    showCursor( false ) 
end 
  
addEvent( "window_text", true ) 
function wnd_create( title, logo, content ) 
    --outputConsole( "wnd_create called" ) 
    if not wnd_window.wnd then 
        --outputConsole( " passed if" ) 
        wnd_window.wnd = guiCreateWindow( 0.1, 0.15, 0.8, 0.7, title, true ) 
        guiWindowSetSizable( wnd_window.wnd, false ) 
        guiWindowSetMovable( wnd_window.wnd, false ) 
         
        wnd_window.logo = guiCreateStaticImage( 0.01, 0.035, 1.40, 0.25, logo, true, wnd_window.wnd ) 
  
        --wnd_window.text = content- 
        wnd_window.memo = guiCreateMemo( 0, 0.3, 1, .6, content, true, wnd_window.wnd ) 
        guiMemoSetReadOnly( wnd_window.memo, true ) 
  
        wnd_window.close_btn = guiCreateButton( 0, .91, .3, 1, "Fechar", true, wnd_window.wnd ) 
        --outputConsole( " window created: ".. tostring( wnd_window.wnd ) ) 
        showCursor( true ) 
        addEventHandler( "onClientGUIClick", wnd_window.close_btn, wnd_close ) 
    end 
end 
addEventHandler( "window_text", getRootElement(), wnd_create ) 

but it does not work :/

can someone help me?

Link to comment

maybe like this !

localPlayer = getLocalPlayer() 
  
wnd_window = {} 
  
addCommandHandler( "beneficios",  
    function ( ) 
        --outputConsole( "wnd_showServerInfo called" ) 
        --outputConsole( " Fonte: ".. tostring( source ) ) 
        --outputConsole( " resourceStarted: ".. tostring( theResource ) ) 
        --outputConsole( " passed if: source == resource" ) 
        local xml = xmlLoadFile( "server.xml" ) 
        local contents = xmlNodeGetValue( xml ) 
        wnd_create( "Seja Bem Vindo Ao Servidor", "logo.png", contents ) 
    end 
) 
  
function wnd_close() 
    guiSetVisible( wnd_window.wnd, false ) 
    showCursor( false ) 
end 
  
function wnd_create( title, logo, content ) 
    --outputConsole( "wnd_create called" ) 
    if not wnd_window.wnd then 
        --outputConsole( " passed if" ) 
        wnd_window.wnd = guiCreateWindow( 0.1, 0.15, 0.8, 0.7, title, true ) 
        guiWindowSetSizable( wnd_window.wnd, false ) 
        guiWindowSetMovable( wnd_window.wnd, false ) 
        
        wnd_window.logo = guiCreateStaticImage( 0.01, 0.035, 1.40, 0.25, logo, true, wnd_window.wnd ) 
  
        --wnd_window.text = content- 
        wnd_window.memo = guiCreateMemo( 0, 0.3, 1, .6, content, true, wnd_window.wnd ) 
        guiMemoSetReadOnly( wnd_window.memo, true ) 
  
        wnd_window.close_btn = guiCreateButton( 0, .91, .3, 1, "Fechar", true, wnd_window.wnd ) 
        --outputConsole( " window created: ".. tostring( wnd_window.wnd ) ) 
        showCursor( true ) 
        addEventHandler( "onClientGUIClick", wnd_window.close_btn, wnd_close ) 
    end 
end 
addEvent( "window_text", true ) 
addEventHandler( "window_text", getRootElement(), wnd_create ) 

#EDIT

Edited by Guest
Link to comment

Thank you!

Is working!

I have another doubt:

this is correct?

localplayer = getLocalPlayer() 
  
function spawncomitens() 
    if (getElementData( localplayer, "MAX_Slots") = 8 ) then 
        setElementData( localplayer, "M9 SD", 1) 
        setElementData( localplayer, "M9 SD Mag", 30) 
        setElementData( localplayer, "Map", 1) 
    end 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), spawncomitens ) 
  
function checklife() 
    local playerHealth = getElementHealth ( localplayer ) 
    if (playerHealth > 102 ) then 
        banPlayer ( localplayer, false, false, true, getRootElement (), 'reason ban' ) 
    end 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), checklife ) 

Link to comment

try this:

addEventHandler ( "onPlayerSpawn",root,function() 
    if getElementData( localPlayer, "MAX_Slots") == 8 then --2 '==' is needed 
        setElementData( localPlayer, "M9 SD", 1) 
        setElementData( localPlayer, "M9 SD Mag", 30) 
        setElementData( localPlayer, "Map", 1) 
    end 
    local playerHealth = getElementHealth ( localPlayer ) 
    if playerHealth > 102  then 
        banPlayer ( localPlayer, false, false, true, getRootElement (), 'reason ban' ) 
    end 
end) 

Link to comment

this way will work?

localplayer = getLocalPlayer() 
  
addEventHandler ( "onPlayerSpawn",root,function() 
    if getElementData( localPlayer, "MAX_Slots") == 8 then --2 '==' is needed 
        setElementData( localPlayer, "M9 SD", 1) 
        setElementData( localPlayer, "M9 SD Mag", 30) 
        setElementData( localPlayer, "Map", 1) 
    end 
) 
  
function checklife() 
    local playerHealth = getElementHealth ( localplayer ) 
    if (playerHealth > 102 ) then 
        banPlayer ( localplayer, false, false, true, getRootElement (), 'reason ban' ) 
    end 
    setTimer("checklife", 2000, 0) 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), checklife ) 

Link to comment

Read the quotes:

addEventHandler ( "onPlayerSpawn",root,function() 
    if getElementData( localPlayer, "MAX_Slots") == 8 then --2 '==' is needed 
        setElementData( localPlayer, "M9 SD", 1) 
        setElementData( localPlayer, "M9 SD Mag", 30) 
        setElementData( localPlayer, "Map", 1) 
    end 
end)--forgot end 
  
function checklife() 
    local playerHealth = getElementHealth ( localPlayer ) 
    if (playerHealth > 102 ) then 
        banPlayer ( localPlayer, false, false, true, getRootElement (), 'reason ban' ) 
    end 
    setTimer(checklife, 2000, 0)--no quotes 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), checklife ) 

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