Jump to content

executeCommandHandler - how it works?


Recommended Posts

Hi community :) i tested a long time with executeCommandHandler, but it still don´t work.

i need it as a client-side script

local localPlayer = getLocalPlayer ( ) 
  
function openAdminReport() 
    executeCommandHandler( "report", localPlayer ) 
end 

any ideas what is wrong with this code?

Edited by Guest
Link to comment

Does it actually gets called? Do you get errors? How exactly it does not work? Give more details. You may have to give "Default" (ACL) access to that function. Type "debugscript 3" in console and then try to call openAdminReport().

Link to comment

the function is part of a gui

thanks Borov i added this line:

addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), openAdminReport ) 

And it works, BUT only on my Homeserver (Windows XP), and not on the real server (Windows Server 2003) :(

Here is the complete code:

  
--------------------------- 
-- Report window toggle 
--------------------------- 
local localPlayer = getLocalPlayer ( ) 
  
function openAdminReport() 
    executeCommandHandler( "report", localPlayer ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), openAdminReport ) 
  
  

and a part of the gui, to show you the Button:

{'btn', id='Contact', onclick=openAdminReport}, 

i allowed executeCommandHandler for 'Defaults' group too.

It works on MY home Server when i press the button, it called /report :)

But not on the real Server

//EDIT:

/debugscript 3 says nothing :/

any ideas?

Link to comment
nice idea but the gui script i client-side, and a call only works with server-side script ;/

eAi does not mean to use "call" function, he means "simply call the function". As you call any other functions e.g. getRootElement()

Link to comment

ah ok, but i don´t know how i made this, how it works?

addEventHandler ( "onResourceStart", getResourceRootElement([color=#FFBF00]admin[/color](), [color=#FFBF00]report function in admin resource[/color] ) 

is that right? i don´t know it :)

Link to comment

getResourceRootElement() returns resource's root element and its argument is the resource element.

If you admin() function returns resource element then you'd do

addEventHandler( "onResourceStart", getResourceRootElement( admin() ), reportFunction ) 

But if you want it to be client-side (I saw in your first post getLocalPlayer) attach the report function to onClientResourceStart, not onResourceStart (this is server-side event).

Link to comment

thanks for help, nice function :)

it works on my homeserver, but NOT on the real server (again) ;(

i tested 3 variants:

1.

local localPlayer = getLocalPlayer ( ) 
  
function openAdminReport() 
    addEventHandler( "onClientResourceStart", getResourceRootElement( admin() ), aReport ) 
end 

2.

local localPlayer = getLocalPlayer ( ) 
  
function openAdminReport() 
    addEventHandler( "onClientResourceStart", getResourceRootElement( admin() ), aReport ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), openAdminReport ) 

3.

local localPlayer = getLocalPlayer ( ) 
  
function openAdminReport() 
    addEventHandler( "onClientResourceStart", getResourceRootElement( admin() ), aReport ) 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), openAdminReport ) 

but nothing works on the real server, but on my testserver all 3 variants works perfektly :/

befor i uploading new resources i test it on my homeserver, so the homeserver have pretty the same resource as the real server :wink:

any ideas? :?:

//EDIT:

i checked all script files from this resource with the files on my PC, there a absolutly the same! (checked by bytes [e.g 37.381 Bytes])

any ideas? :?:

Link to comment

1. What does admin function do?

2. Why do you add a handler to onClientResourceStart in a function that is called from the same event? It won't work as this event is triggered only one.

3. What does aReport function does?

4. If you use getLocalPlayer it means the script is client-side. Why do you use server events (like onResourceStart)?

The last example looks the most "real" which could work. but don't add functions to events that's just been called. In the last example, if you replaced line 4 with the code that shows the report, it will work.

Link to comment

1. in the resource "admin" there is the function to open the report window

3. aReport - the function to open the report window

4. now changed to onClientResourceStart (but don´t work)

In the last example, if you replaced line 4 with the code that shows the report, it will work.

Very good idea, i tested it:

--------------------------- 
-- Report window toggle 
--------------------------- 
  
function openAdminReport() 
--[[********************************** 
* 
*   Multi Theft Auto - Admin Panel 
* 
*   gui\admin_report.lua 
* 
*   Original File by lil_Toady 
* 
**************************************]] 
  
aReportForm = nil 
  
function aReport ( player ) 
    if ( aReportForm == nil ) then 
        local x, y = guiGetScreenSize() 
        aReportForm     = guiCreateWindow ( x / 2 - 150, y / 2 - 150, 300, 300, "Contact Admin", false ) 
                       guiCreateLabel ( 0.05, 0.11, 0.20, 0.09, "Category:", true, aReportForm ) 
                       guiCreateLabel ( 0.05, 0.21, 0.20, 0.09, "Subject:", true, aReportForm ) 
                       guiCreateLabel ( 0.05, 0.30, 0.20, 0.07, "Message:", true, aReportForm ) 
        aReportCategory = guiCreateEdit ( 0.30, 0.10, 0.65, 0.09, "Question", true, aReportForm ) 
                       guiEditSetReadOnly ( aReportCategory, true ) 
        aReportDropDown = guiCreateStaticImage ( 0.86, 0.10, 0.09, 0.09, "client\\images\\dropdown.png", true, aReportForm ) 
                       guiBringToFront ( aReportDropDown ) 
        aReportCategories   = guiCreateGridList ( 0.30, 0.10, 0.65, 0.30, true, aReportForm ) 
                       guiGridListAddColumn( aReportCategories, "", 0.85 ) 
                       guiSetVisible ( aReportCategories, false ) 
                       guiGridListSetItemText ( aReportCategories, guiGridListAddRow ( aReportCategories ), 1, "Question", false, false ) 
                       guiGridListSetItemText ( aReportCategories, guiGridListAddRow ( aReportCategories ), 1, "Suggestion", false, false ) 
                       guiGridListSetItemText ( aReportCategories, guiGridListAddRow ( aReportCategories ), 1, "Cheater/Moder", false, false ) 
                       guiGridListSetItemText ( aReportCategories, guiGridListAddRow ( aReportCategories ), 1, "Other", false, false ) 
        aReportSubject      = guiCreateEdit ( 0.30, 0.20, 0.65, 0.09, "", true, aReportForm ) 
        aReportMessage  = guiCreateMemo ( 0.05, 0.38, 0.90, 0.45, "", true, aReportForm ) 
        aReportAccept       = guiCreateButton ( 0.40, 0.88, 0.25, 0.09, "Send", true, aReportForm ) 
        aReportCancel       = guiCreateButton ( 0.70, 0.88, 0.25, 0.09, "Cancel", true, aReportForm ) 
  
        addEventHandler ( "onClientGUIClick", aReportForm, aClientReportClick ) 
        addEventHandler ( "onClientGUIDoubleClick", aReportForm, aClientReportDoubleClick ) 
    end 
    guiBringToFront ( aReportForm ) 
    showCursor ( true ) 
end 
addCommandHandler ( "report", aReport ) 
  
function aReportClose ( ) 
    guiSetInputEnabled ( false ) 
    if ( aReportForm ) then 
        removeEventHandler ( "onClientGUIClick", aReportForm, aClientReportClick ) 
        removeEventHandler ( "onClientGUIDoubleClick", aReportForm, aClientReportDoubleClick ) 
        destroyElement ( aReportForm ) 
        aReportForm = nil 
        showCursor ( false ) 
    end 
end 
  
function aClientReportDoubleClick ( button ) 
    if ( button == "left" ) then 
        if ( source == aReportCategories ) then 
            if ( guiGridListGetSelectedItem ( aReportCategories ) ~= -1 ) then 
                local cat = guiGridListGetItemText ( aReportCategories, guiGridListGetSelectedItem ( aReportCategories ), 1 ) 
                guiSetText ( aReportCategory, cat ) 
                guiSetVisible ( aReportCategories, false ) 
            end 
        end 
    end 
end 
  
function aClientReportClick ( button ) 
    if ( source == aReportCategory ) then 
        guiBringToFront ( aReportDropDown ) 
    end 
    if ( source ~= aReportCategories ) then 
        guiSetVisible ( aReportCategories, false ) 
    end 
    if ( button == "left" ) then 
        if ( source == aReportAccept ) then 
            if ( ( string.len ( guiGetText ( aReportSubject ) ) < 1 ) or ( string.len ( guiGetText ( aReportMessage ) ) < 5 ) ) then 
                aMessageBox ( "error", "Subject/Message missing." ) 
            else 
                aMessageBox ( "info", "Your message has been submited and will be processed as soon as possible." ) 
                setTimer ( aMessageBoxClose, 3000, 1, true ) 
                local tableOut = {} 
                tableOut.category = guiGetText ( aReportCategory ) 
                tableOut.subject = guiGetText ( aReportSubject ) 
                tableOut.message = guiGetText ( aReportMessage ) 
                triggerServerEvent ( "aMessage", getLocalPlayer(), "new", tableOut ) 
                aReportClose () 
            end 
        elseif ( source == aReportSubject ) then 
            guiSetInputEnabled ( true ) 
        elseif ( source == aReportMessage ) then 
            guiSetInputEnabled ( true ) 
        elseif ( source == aReportCancel ) then 
            aReportClose () 
        elseif ( source == aReportDropDown ) then 
            guiBringToFront ( aReportCategories ) 
            guiSetVisible ( aReportCategories, true ) 
        end 
    end 
end 
end 

and here is the complete code with gui for the button etc: http://pastebin.com/m2bad56db

and again, it works on MY WinXP Home-test-Server, but not on the Real server :shock: i am realy wondering why all changes work on my testserver, and not on the real server :?

When i press the button to open the function, nothing happens ON THE REAL SERVER

its that a chache problem on my side or so? i tried already to delete the chache.

Can you pleas connect to the server (see @ signatur) and press F1, then on the button "Berichten"

Link to comment

Now i tested a little bit, and i found a strange problem.

First, the code:

wndMain = { 
    'wnd', 
    text = 'Spieleverwaltung', 
    x = 10, 
    y = 175, 
    width = 320, 
    controls = { 
        {'lbl', text='Spielereinstellungen'}, 
        {'br'}, 
        {'btn', id='Selbstmord', onclick=killLocalPlayer}, 
        {'btn', id='Model', window=wndSkin}, 
        --{'btn', id='weapon', window=wndWeapon}, 
        {'btn', id='Klamotten', window=wndClothes}, 
        {'btn', id='playergrav', text='Gravitation', window=wndGravity}, 
        {'btn', id='Gehe zu', window=wndWarp}, 
        {'btn', id='Statistik', window=wndStats}, 
        {'br'}, 
        {'chk', id='Jetpack', onclick=toggleJetPack}, 
        {'chk', id='falloff', text='Vom Motorrad fallen', onclick=toggleFallOffBike}, 
        {'br'}, 
         
        {'lbl', text='Pos:'}, 
        {'lbl', id='xpos', text='x', width=50}, 
        {'lbl', id='ypos', text='y', width=50}, 
        {'lbl', id='zpos', text='z', width=50}, 
        {'btn', id='setpos', text='Weltkarte', window=wndSetPos}, 
        {'br'}, 
        {'br'}, 
         
        {'lbl', text='Fahrzeug'}, 
        {'br'}, 
        {'lbl', text='Aktuell:'}, 
        {'lbl', id='curvehicle'}, 
        {'br'}, 
        {'btn', id='createvehicle', window=wndCreateVehicle, text='Erstellen'}, 
        {'btn', id='Reparieren', onclick=repairVehicle}, 
        {'btn', id='Aufrichten', onclick=flipVehicle}, 
        {'btn', id='Aufmotzen', window=wndUpgrades}, 
        {'btn', id='Farbe', window=wndColor}, 
        {'btn', id='Farbmuster', window=wndPaintjob}, 
        {'br'}, 
        {'chk', id='lightson', text='Lichter an', onclick=forceLightsOn}, 
        {'chk', id='lightsoff', text='Lichter aus', onclick=forceLightsOff}, 
        {'br'}, 
        {'br'}, 
         
        {'lbl', text='Weltweit'}, 
        {'br'}, 
        {'btn', id='Zeit', window=wndTime}, 
        {'btn', id='Wetter', window=wndWeather}, 
        --{'btn', id='speed', window=wndGameSpeed} 
        [color=#FF8000]{'btn', id='Berichten', onclick=testbutton},[/color] 
    }, 
    oncreate = mainWndShow, 
    onclose = mainWndClose 
} 

This is the MainWindow, can you see the orange line (at the end)? This is the button. When it press it, "testbutton" should be launched.

Now, testbutton:

function testbutton() 
    outputChatBox('it works', 0, 255, 0) 
end 

This is the testbutton function for onclick=testbutton

Now when i press the button "Berichten" in the MainWindow, it should give me a outputChatBox.

but nothing happens! not on my homeserver and not on the realserver.

Any ideas?

(debugscript 3 give me nothing!)

(the MainWindow code is from the Freeroam GUI [fr_client.lua])

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