Jump to content

:o. How is that possible?


Recommended Posts

I gave up on that idea, when I saw that the GUI doesn't open anymore. What's wrong in this? Also, don't go around editing everything in the script, just help me find what's wrong, please.

rbnames = {  
 ["roadright"] = "Small roadblock", 
 ["helix_barrier"] = "Big Street Roadblock", 
 ["roadworkbarrier1"] = "Sidewalk Roadblock", 
 ["roadbarrier4"] = "Barrier", 
 ["roadbarrier3"] = "Detour sign", 
 ["roadbarrier6"] = "Small barrier" 
 } 
  
function cGUI() 
  
  
showCursor(true) 
toggleAllControls(true) 
rbsWindow = guiCreateWindow(0.3391,0.2832,0.3125,0.4688,"Roadblock System",true) 
guiWindowSetSizable(rbsWindow,false) 
acceptButton = guiCreateButton(0.1075,0.8813,0.3225,0.0854,"Accept",true,rbsWindow) 
closeButton = guiCreateButton(0.57,0.8813,0.3225,0.0854,"Close",true,rbsWindow) 
rbsMenu = guiCreateGridList(0.11,0.1292,0.785,0.725,true,rbsWindow) 
guiGridListSetSelectionMode(rbsMenu,2) 
guiGridListAddColumn(rbsMenu,"Roadblocks",0.90) 
addEventHandler("onClientGUIClick", acceptButton,  
     
    function () 
     
        chk = guiGridListGetSelectedItem ( rbsMenu ) 
        if chk  then   
        outputChatBox(chk) 
        toggleAllControls(false) 
        showCursor(false) 
        x, y, z = getElementPosition(localPlayer) 
        rx, ry, rz = getElementRotation(localPlayer) 
            if chk == 0 then 
                rbobj = createObject(1459, x, y, z, rx, ry, rz) 
            elseif chk == 1 then 
                rbobj = createObject(1424 x, y, z, rx, ry, rz) 
            elseif chk == 2 then 
                rbobj = createObject(1425, x, y, z, rx, ry, rz) 
            elseif chk == 3 then 
                rbobj = createObject(1423, x, y, z, rx, ry, rz) 
            elseif chk == 4 then 
                rbobj = createObject(981, x, y, z, rx, ry, rz) 
            elseif chk == 5 then 
                rbobj = createObject(978, x, y, z, rx, ry, rz) 
            end 
        showCursor(false) 
        toggleAllControls(true) 
        guiSetVisible(rbsWindow, false) 
        end 
    end) 
addEventHandler("onClientGUIClick", closeButton,  
  
    function () 
         
        guiSetVisible(rbsWindow, false) 
        toggleAllControls(true) 
        showCursor(false) 
         
    end) 
     
guiGridListAddColumn(rbsMenu,"Roadblocks",0.90) 
  
        for key,rbnames in pairs(rbnames) do 
                local row = guiGridListAddRow ( rbsMenu ) 
                guiGridListSetItemText ( rbsMenu, row, 1, rbnames, false, false ) 
        end 
  
for i = 1, 6 do 
    guiGridListAddRow(rbsMenu) 
end 
end 
addCommandHandler("rb", cGUI) 
  
  

Link to comment

Got another problem. I changed it so that it used server-side aswell. The GUI won't pop up. I can't seem to find any problems. Again, don't go around editing the script like crazy, just tell me how to fix it.

Server-side

function cobjs(chk) 
  
    outputChatBox(chk) 
    toggleAllControls(thePlayer, false) 
    showCursor(thePlayer, false) 
    x, y, z = getElementPosition(thePlayer) 
    rx, ry, rz = getElementRotation(thePlayer) 
        if chk == 0 then 
                rbobj = createObject(1459, x, y, z-0.5, rx, ry, rz) 
            elseif chk == 1 then 
                rbobj = createObject(1424, x, y, z-0.5, rx, ry, rz) 
            elseif chk == 2 then 
                rbobj = createObject(1425, x, y, z-0.5, rx, ry, rz) 
            elseif chk == 3 then 
                rbobj = createObject(1423, x, y, z-0.2, rx, ry, rz) 
            elseif chk == 4 then 
                rbobj = createObject(981, x, y, z-0.5, rx, ry, rz) 
            elseif chk == 5 then 
                rbobj = createObject(978, x, y, z-0.5, rx, ry, rz) 
        end 
     
end 
addEvent("objcrt", true) 
addEventHandler("objcrt", root, cobjs) 

Client-side

rbnames = {  
 ["roadright"] = "Small roadblock", 
 ["helix_barrier"] = "Big Street Roadblock", 
 ["roadworkbarrier1"] = "Sidewalk Roadblock", 
 ["roadbarrier4"] = "Barrier", 
 ["roadbarrier3"] = "Detour sign", 
 ["roadbarrier6"] = "Small barrier" 
 } 
  
function cGUI() 
  
  
showCursor(true) 
toggleAllControls(true) 
rbsWindow = guiCreateWindow(0.3391,0.2832,0.3125,0.4688,"Roadblock System",true) 
guiWindowSetSizable(rbsWindow,false) 
acceptButton = guiCreateButton(0.1075,0.8813,0.3225,0.0854,"Accept",true,rbsWindow) 
closeButton = guiCreateButton(0.57,0.8813,0.3225,0.0854,"Close",true,rbsWindow) 
rbsMenu = guiCreateGridList(0.11,0.1292,0.785,0.725,true,rbsWindow) 
guiGridListSetSelectionMode(rbsMenu,2) 
guiGridListAddColumn(rbsMenu,"Roadblocks",0.90) 
addEventHandler("onClientGUIClick", acceptButton,  
     
    function () 
     
        chk = guiGridListGetSelectedItem ( rbsMenu ) 
        if chk  then   
            triggerServerEvent("objcrt", root, chk) 
        guiSetVisible(rbsWindow, false) 
    end) 
addEventHandler("onClientGUIClick", closeButton,  
  
    function () 
         
        guiSetVisible(rbsWindow, false) 
        toggleAllControls(true) 
        showCursor(false) 
         
    end) 
     
guiGridListAddColumn(rbsMenu,"Roadblocks",0.90) 
  
        for key,rbnames in pairs(rbnames) do 
                local row = guiGridListAddRow ( rbsMenu ) 
                guiGridListSetItemText ( rbsMenu, row, 1, rbnames, false, false ) 
        end 
  
for i = 1, 6 do 
    guiGridListAddRow(rbsMenu) 
end 
end 
addCommandHandler("rb", cGUI) 
  
  

Link to comment

you had syntax error in clientside

either use /debugscript 3 or http://www.lua.org/cgi-bin/demo to search for them

or:

magic spoiler again: (incase you can't find them)

rbnames = { 
 ["roadright"] = "Small roadblock", 
 ["helix_barrier"] = "Big Street Roadblock", 
 ["roadworkbarrier1"] = "Sidewalk Roadblock", 
 ["roadbarrier4"] = "Barrier", 
 ["roadbarrier3"] = "Detour sign", 
 ["roadbarrier6"] = "Small barrier" 
 } 
  
function cGUI() 
  
  
showCursor(true) 
toggleAllControls(true) 
rbsWindow = guiCreateWindow(0.3391,0.2832,0.3125,0.4688,"Roadblock System",true) 
guiWindowSetSizable(rbsWindow,false) 
acceptButton = guiCreateButton(0.1075,0.8813,0.3225,0.0854,"Accept",true,rbsWindow) 
closeButton = guiCreateButton(0.57,0.8813,0.3225,0.0854,"Close",true,rbsWindow) 
rbsMenu = guiCreateGridList(0.11,0.1292,0.785,0.725,true,rbsWindow) 
guiGridListSetSelectionMode(rbsMenu,2) 
guiGridListAddColumn(rbsMenu,"Roadblocks",0.90) 
addEventHandler("onClientGUIClick", acceptButton, 
    
    function () 
    
        chk = guiGridListGetSelectedItem ( rbsMenu ) 
        if chk  then   
            triggerServerEvent("objcrt", root, chk) 
        guiSetVisible(rbsWindow, false) 
    end 
end  
) 
addEventHandler("onClientGUIClick", closeButton, 
  
    function () 
        
        guiSetVisible(rbsWindow, false) 
        toggleAllControls(true) 
        showCursor(false) 
        
    end) 
    
guiGridListAddColumn(rbsMenu,"Roadblocks",0.90) 
  
        for key,rbnames in pairs(rbnames) do 
                local row = guiGridListAddRow ( rbsMenu ) 
                guiGridListSetItemText ( rbsMenu, row, 1, rbnames, false, false ) 
        end 
  
for i = 1, 6 do 
    guiGridListAddRow(rbsMenu) 
end 
end 
  
addCommandHandler("rb", cGUI) 

Edited by Guest
Link to comment

yes, it's not on a fitting place because you've missed something, most likely an 'end'.

   function () 
    
        chk = guiGridListGetSelectedItem ( rbsMenu ) 
        if chk  then   
            triggerServerEvent("objcrt", root, chk) 
        guiSetVisible(rbsWindow, false) 
    end 
    end) 
addEventHandler("onClientGUIClick", closeButton, 

one function needs one 'end'

with this: if chk then

another 'end' is needed, else it will output syntax error

idk how to explain it, but everytime there's an 'if', there's an extra 'end'. Pretty simple

Link to comment

Can't you just edit a reply? 3 posts o.O

Server-side:

addEvent ( 'objcrt', true ); 
addEventHandler ( 'objcrt', root, 
    function ( chk ) 
        outputChatBox ( tostring ( chk ) ); -- check here what outputs 
         
        toggleAllControls ( thePlayer, false ); -- where is thePlayer defined? 
        showCursor ( thePlayer, false ); -- where is thePlayer defined? 
        local nX, nY, nZ        = getElementPosition ( thePlayer ); -- where is thePlayer defined? 
        local nX2, nY2, nZ3     = getElementRotation ( thePlayer ); -- where is thePlayer defined? 
         
        if ( chk == 0 ) then 
            rbobj = createObject(1459, nX, nY, nZ-0.5, nX2, nY2, nZ2); 
        elseif ( chk == 1 ) then 
            rbobj = createObject(1424, nX, nY, nZ-0.5, nX2, nY2, nZ2); 
        elseif ( chk == 2 ) then 
            rbobj = createObject(1425, nX, nY, nZ-0.5, nX2, nY2, nZ2); 
        elseif ( chk == 3 ) then 
            rbobj = createObject(1423, nX, nY, nZ-0.2, nX2, nY2, nZ2); 
        elseif chk == 4 then 
            rbobj = createObject(981, nX, nY, nZ-0.5, nX2, nY2, nZ2); 
        elseif chk == 5 then 
            rbobj = createObject(978, nX, nY, nZ-0.5, nX2, nY2, nZ2); 
        end 
    end 
) 

Client-side:

local tRBNames = 
{ 
    [ 'roadright' ]          = 'Small roadblock'; 
    [ 'helix_barrier' ]      = 'Big Street Roadblock'; 
    [ 'roadworkbarrier1' ]   = 'Sidewalk Roadblock'; 
    [ 'roadbarrier4' ]       = 'Barrier'; 
    [ 'roadbarrier3' ]       = 'Detour sign'; 
    [ 'roadbarrier6' ]       = 'Small barrier'; 
} 
  
function cGUI() 
    showCursor(true) 
    toggleAllControls(true) 
    rbsWindow = guiCreateWindow(0.3391,0.2832,0.3125,0.4688,"Roadblock System",true) 
    guiWindowSetSizable(rbsWindow,false) 
    acceptButton = guiCreateButton(0.1075,0.8813,0.3225,0.0854,"Accept",true,rbsWindow) 
    closeButton = guiCreateButton(0.57,0.8813,0.3225,0.0854,"Close",true,rbsWindow) 
    rbsMenu = guiCreateGridList(0.11,0.1292,0.785,0.725,true,rbsWindow) 
    guiGridListSetSelectionMode(rbsMenu,2) 
    guiGridListAddColumn(rbsMenu,"Roadblocks",0.90) 
    for _, sObject in ipairs ( tRBNames ) do 
      if ( rbsMenu ) then 
            local row = guiGridListAddRow ( rbsMenu ) 
            guiGridListSetItemText ( rbsMenu, row, 1, tostring ( sObject ), false, false ) 
          end 
    end 
    addEventHandler("onClientGUIClick", root,  
      function ( ) 
          if ( source == acceptButton ) then 
                local chk = guiGridListGetSelectedItem ( rbsMenu ) 
                if ( chk ) then   
                  triggerServerEvent("objcrt", root, chk) 
                    guiSetVisible(rbsWindow, false) 
              end 
            elseif ( source == closeButton ) then 
                guiSetVisible(rbsWindow, false) 
                toggleAllControls(true) 
                showCursor(false) 
            end 
        end 
    ) 
end 
addCommandHandler ( 'rb', cGUI ) 
  

Check comments. Also, where you trigger event 'objcrt' ?

Link to comment
pairs 
ipairs 

you changed it to 'ipairs', it will just ruin things even more than they aldready are. try again

this is what you have to do:

you had 'root'.

                  triggerServerEvent("objcrt", localPlayer, chk) 

Read this (It's from wiki):

function greetingCommand ( commandName ) 
    triggerServerEvent ( "onGreeting", getLocalPlayer(), "Hello World!" )  
    -- getLocalPlayer instead of getRootElement makes the client player the 'source' on the server function, eliminating the need for an additional player argument to be transferred. 
end 
addCommandHandler ( "greet", greetingCommand ) 

and now when you changed 'root' to 'localPlayer', you need to change 'thePlayer' to 'source' on the serverside, as it says in the example. It's really simple.

Link to comment

jayz changed it to 'ipairs' not you, i think

anyhow, post your code.

using jayz's code should work, but a fixed verison.

-- server

addEvent ( 'objcrt', true ); 
addEventHandler ( 'objcrt', root, 
    function ( chk ) 
        outputChatBox ( tostring ( chk ) ); -- check here what outputs 
        
-- following arguments with source and not thePlayer 
        toggleAllControls ( source, false ); -- source 
        showCursor ( source, false ); -- source 
        local nX, nY, nZ        = getElementPosition ( source ); -- source 
        local nX2, nY2, nZ3     = getElementRotation ( source ); -- source 
        
        if ( chk == 0 ) then 
            rbobj = createObject(1459, nX, nY, nZ-0.5, nX2, nY2, nZ2); 
        elseif ( chk == 1 ) then 
            rbobj = createObject(1424, nX, nY, nZ-0.5, nX2, nY2, nZ2); 
        elseif ( chk == 2 ) then 
            rbobj = createObject(1425, nX, nY, nZ-0.5, nX2, nY2, nZ2); 
        elseif ( chk == 3 ) then 
            rbobj = createObject(1423, nX, nY, nZ-0.2, nX2, nY2, nZ2); 
        elseif chk == 4 then 
            rbobj = createObject(981, nX, nY, nZ-0.5, nX2, nY2, nZ2); 
        elseif chk == 5 then 
            rbobj = createObject(978, nX, nY, nZ-0.5, nX2, nY2, nZ2); 
        end 
    end 
) 

local tRBNames = 
{ 
    [ 'roadright' ]          = 'Small roadblock'; 
    [ 'helix_barrier' ]      = 'Big Street Roadblock'; 
    [ 'roadworkbarrier1' ]   = 'Sidewalk Roadblock'; 
    [ 'roadbarrier4' ]       = 'Barrier'; 
    [ 'roadbarrier3' ]       = 'Detour sign'; 
    [ 'roadbarrier6' ]       = 'Small barrier'; 
} 
  
function cGUI() 
    showCursor(true) 
    toggleAllControls(true) 
    rbsWindow = guiCreateWindow(0.3391,0.2832,0.3125,0.4688,"Roadblock System",true) 
    guiWindowSetSizable(rbsWindow,false) 
    acceptButton = guiCreateButton(0.1075,0.8813,0.3225,0.0854,"Accept",true,rbsWindow) 
    closeButton = guiCreateButton(0.57,0.8813,0.3225,0.0854,"Close",true,rbsWindow) 
    rbsMenu = guiCreateGridList(0.11,0.1292,0.785,0.725,true,rbsWindow) 
    guiGridListSetSelectionMode(rbsMenu,2) 
    guiGridListAddColumn(rbsMenu,"Roadblocks",0.90) 
    for _, sObject in pairs ( tRBNames ) do -- pairs, not ipairs 
      if ( rbsMenu ) then 
            local row = guiGridListAddRow ( rbsMenu ) 
            guiGridListSetItemText ( rbsMenu, row, 1, tostring ( sObject ), false, false ) 
          end 
    end 
    addEventHandler("onClientGUIClick", root, 
      function ( ) 
          if ( source == acceptButton ) then 
                local chk = guiGridListGetSelectedItem ( rbsMenu ) 
                if ( chk ) then   
                  triggerServerEvent("objcrt", localPlayer, chk) --localPlayer, not root 
                    guiSetVisible(rbsWindow, false) 
              end 
            elseif ( source == closeButton ) then 
                guiSetVisible(rbsWindow, false) 
                toggleAllControls(true) 
                showCursor(false) 
            end 
        end 
    ) 
end 
addCommandHandler ( 'rb', cGUI ) 
  

and yours:

--client

rbnames = { 
 ["roadright"] = "Small roadblock", 
 ["helix_barrier"] = "Big Street Roadblock", 
 ["roadworkbarrier1"] = "Sidewalk Roadblock", 
 ["roadbarrier4"] = "Barrier", 
 ["roadbarrier3"] = "Detour sign", 
 ["roadbarrier6"] = "Small barrier" 
 } 
  
function cGUI() 
  
  
showCursor(true) 
toggleAllControls(true) 
rbsWindow = guiCreateWindow(0.3391,0.2832,0.3125,0.4688,"Roadblock System",true) 
guiWindowSetSizable(rbsWindow,false) 
acceptButton = guiCreateButton(0.1075,0.8813,0.3225,0.0854,"Accept",true,rbsWindow) 
closeButton = guiCreateButton(0.57,0.8813,0.3225,0.0854,"Close",true,rbsWindow) 
rbsMenu = guiCreateGridList(0.11,0.1292,0.785,0.725,true,rbsWindow) 
guiGridListSetSelectionMode(rbsMenu,2) 
guiGridListAddColumn(rbsMenu,"Roadblocks",0.90) 
addEventHandler("onClientGUIClick", acceptButton, 
    
    function () 
    
        chk = guiGridListGetSelectedItem ( rbsMenu ) 
        if chk  then   
            triggerServerEvent("objcrt", localPlayer, chk) -- localPlayer, not root 
        guiSetVisible(rbsWindow, false) 
        end 
    end 
) 
addEventHandler("onClientGUIClick", closeButton, 
  
    function () 
        
        guiSetVisible(rbsWindow, false) 
        toggleAllControls(true) 
        showCursor(false) 
        
    end) 
    
guiGridListAddColumn(rbsMenu,"Roadblocks",0.90) 
  
        for key,rbnames in pairs(rbnames) do 
                local row = guiGridListAddRow ( rbsMenu ) 
                guiGridListSetItemText ( rbsMenu, row, 1, rbnames, false, false ) 
        end 
  
for i = 1, 6 do 
    guiGridListAddRow(rbsMenu) 
end 
end 
addCommandHandler("rb", cGUI) 
  

--server

function cobjs(chk) 
  
--source all of 'em, not thePlayer 
    outputChatBox(chk) 
    toggleAllControls( source, false ) 
    showCursor( source, false ) 
    x, y, z = getElementPosition( source ) 
    rx, ry, rz = getElementRotation( source ) 
        if chk == 0 then 
                rbobj = createObject(1459, x, y, z-0.5, rx, ry, rz) 
            elseif chk == 1 then 
                rbobj = createObject(1424, x, y, z-0.5, rx, ry, rz) 
            elseif chk == 2 then 
                rbobj = createObject(1425, x, y, z-0.5, rx, ry, rz) 
            elseif chk == 3 then 
                rbobj = createObject(1423, x, y, z-0.2, rx, ry, rz) 
            elseif chk == 4 then 
                rbobj = createObject(981, x, y, z-0.5, rx, ry, rz) 
            elseif chk == 5 then 
                rbobj = createObject(978, x, y, z-0.5, rx, ry, rz) 
        end 
    
end 
addEvent("objcrt", true) 
addEventHandler("objcrt", root, cobjs) 

Link to comment

http://lua-users.org/wiki/TablesTutorial

Tables can also be used to store information which is not indexed numerically, or sequentially, as with arrays. These storage types are sometimes called dictionaries, associative arrays, hashes, or mapping types. We'll use the term dictionary where an element pair has a key and a value. The key is used to set and retrieve a value associated with it. Note that just like arrays we can use the table[key] = value format to insert elements into the table. A key need not be a number, it can be a string, or for that matter, nearly any other Lua object (except for nil or 0/0). Let's construct a table with some key-value pairs in it:
> t = { apple="green", orange="orange", banana="yellow" } 
> for k,v in pairs(t) do print(k,v) end 
apple   green 
orange  orange 
banana  yellow 

Notice that we have to use pairs(), rather than ipairs() to output the values. This is because the keys are no longer numbers and ipairs() iterates only over the indices in a table, whereas pairs() iterates over the keys in a table. Note, there is no guarantee as to the order in which keys will be stored in a table when using dictionaries so the order of retrieval of keys using pairs() is not guaranteed. This caveat even applies to the indexed portion of the table, or in a table that is not being used as a dictionary at all and has only indices as keys.
> t.melon = "green" 
> t["strawberry"] = "red" 
> for k,v in pairs(t) do print(k,v) end 
melon   green 
strawberry      red 
apple   green 
orange  orange 
banana  yellow 

_____________________________________________________________

Mixed table constructors

You are not restricted to using table constructors as just sequentially indexed lists, or as dictionaries, you can mix the two together, e.g.,

> t = { 2,4,6, language="Lua", version="5.1" } 

Here we have an array of numbers followed by some dictionary values. We can use our Lua table library functions to output the contents of the table.
> for k,v in pairs(t) do print(k,v) end 
1       2 
version 5.1 
3       6 
language        Lua 
2       4 
> for i,v in ipairs(t) do print(i,v) end 
1       2 
2       4 
3       6 

Notice how the outputs differ. ipairs() has only output the numerically indexed content, in increasing order, and pairs() has output all of the content, in an undefined order
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...