Charlie_Jefferson Posted April 18, 2012 Share Posted April 18, 2012 How can you destroy an object that you gave an ID with setElementID? I thought of destroyElement, but that uses a name. Link to comment
Callum Posted April 18, 2012 Share Posted April 18, 2012 You can loop each object (using getElementsByType) and getElementID. If it has the correct value, then use destroyElement with the value variable. Link to comment
Charlie_Jefferson Posted April 18, 2012 Author Share Posted April 18, 2012 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
Absence2 Posted April 18, 2012 Share Posted April 18, 2012 syntax error, line 36. rbobj = createObject(1424 x, y, z, rx, ry, rz) missed a comma Link to comment
Charlie_Jefferson Posted April 18, 2012 Author Share Posted April 18, 2012 If that's why it doesn't work, your a fucking genius. Edit: That was it, I love you! Link to comment
Charlie_Jefferson Posted April 18, 2012 Author Share Posted April 18, 2012 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
Absence2 Posted April 18, 2012 Share Posted April 18, 2012 (edited) 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 April 18, 2012 by Guest Link to comment
Charlie_Jefferson Posted April 18, 2012 Author Share Posted April 18, 2012 Nothing was showing up IG, because I didn't have debugscript open. >.> Edit: All it says is that ")" is at an unexpected place, at line 31, which is where the function's end is and the event handler's bracket ends, so I don't know what's wrong there. Nvm, got it. Link to comment
Absence2 Posted April 18, 2012 Share Posted April 18, 2012 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
Charlie_Jefferson Posted April 18, 2012 Author Share Posted April 18, 2012 Got server-side errors which I never knew how to fix. It says bad argument at getElementPosition and such. It means that the argument thePlayer ain't right, which I never knew how to fix, mind helping me on that? Also, yes, I know I must end the if, I just didn't pay attention to it . Link to comment
Charlie_Jefferson Posted April 18, 2012 Author Share Posted April 18, 2012 Also, I couldn't figure to how to make the objects get a continuous ID, like start at 1 and go up to whatever number of objects I have. Link to comment
Charlie_Jefferson Posted April 18, 2012 Author Share Posted April 18, 2012 Still didn't figure how to fix and add those things. Link to comment
Michael# Posted April 18, 2012 Share Posted April 18, 2012 Can't you just edit a reply? 3 posts 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
Absence2 Posted April 19, 2012 Share Posted April 19, 2012 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
Charlie_Jefferson Posted April 19, 2012 Author Share Posted April 19, 2012 I didn't notice I changed it to ipairs. Thanks for explaining. I will change it now and see if it works. Link to comment
Charlie_Jefferson Posted April 19, 2012 Author Share Posted April 19, 2012 Yeah, it kinda works. Still gives an error at getElementRotation and nothing happens after that. Link to comment
Absence2 Posted April 19, 2012 Share Posted April 19, 2012 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
Michael# Posted April 19, 2012 Share Posted April 19, 2012 (edited) Fail I'm must learn about tables again Edited April 19, 2012 by Guest Link to comment
Absence2 Posted April 19, 2012 Share Posted April 19, 2012 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 constructorsYou 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
Charlie_Jefferson Posted April 19, 2012 Author Share Posted April 19, 2012 Works, but getElementRotation doesn't seem to work, it just spawns the object rotated normally, not depending on my rotation, using Jayz's code, fixed by absence. Edit: No errors. Link to comment
Charlie_Jefferson Posted April 20, 2012 Author Share Posted April 20, 2012 You did help, but the getElementRotation doesn't get the rotation, apparently, because the object isn't rotated how I want it to be. Link to comment
Absence2 Posted April 20, 2012 Share Posted April 20, 2012 how do you want it to be then? Link to comment
Charlie_Jefferson Posted April 20, 2012 Author Share Posted April 20, 2012 I wanted the object to be rotated, depending on my rotation. That's the thing that doesn't work. It doesn't do that. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now