drk Posted February 17, 2012 Posted February 17, 2012 Solidsnake, it don't works. I tried it here several ways and I can't get it to work if I remove 'for ... in ..... do' and add a text like 'WHAT THE FUCK' in the row it work. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Castillo Posted February 17, 2012 Posted February 17, 2012 Ah, I understand now, you're using 'ipairs' instead of 'pairs', you can't use 'ipairs' in that kind of table. local marker = createMarker (1605.600, -1625.300, 12.5, "cylinder", 2, 25, 50, 255, 255 ) local cars = { [596] = 'Police LS', [597] = 'Police SF', [598] = 'Police LV', [599] = 'Police Ranger' } window = guiCreateWindow(561,187,260,388,"Spawn Vehicle",false) guiWindowSetSizable(window,false) spawnButton = guiCreateButton(26,317,96,37,"Spawn",false,window) closeButton = guiCreateButton(142,318,96,37,"Close",false,window) carGrid = guiCreateGridList(23,34,210,249,false,window) guiGridListSetSelectionMode(carGrid,0) column = guiGridListAddColumn(carGrid,"Vehicle name",0.85) for id,vehName in pairs(cars) do local row = guiGridListAddRow ( carGrid ) guiGridListSetItemText ( carGrid, row, column, tostring(vehName), false, false ) guiGridListSetItemData ( carGrid, row, column, tonumber(id), false, false ) end function showWindow() local playerTeam = getPlayerTeam (localPlayer) local teamName = getTeamName ( playerTeam ) if (teamName == "Police") then guiSetVisible( window, true ) showCursor(true) end end addEventHandler ("onClientMarkerHit", marker, showWindow) function spawn() local row,col = guiGridListGetSelectedItem(carGrid) if (row and col and row ~= -1 and col ~= -1) then local model = guiGridListGetItemData(carGrid, row, 1) triggerServerEvent('onGUIClick',localPlayer,tonumber(model)) end end addEventHandler('onClientGUIClick',spawnButton, spawn, false) function setVisible() guiSetVisible(window,false) showCursor(false) end addEvent('setGUIVisible',true) addEventHandler('setGUIVisible',root,setVisible) function closeWindow() guiSetVisible(window,false) showCursor(false) end addEventHandler ("onClientGUIClick", closeButton, closeWindow, false) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Sparrow Posted February 17, 2012 Author Posted February 17, 2012 oh thanks solidsnake, it works now. a little question, whats the different between "ipairs" and "pairs" ?
Castillo Posted February 17, 2012 Posted February 17, 2012 http://lua-users.org/wiki/TablesTutorial ipairs works with indexed tables as far as I know, and pairs works with every kind of table (I may be wrong too). San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Sparrow Posted February 17, 2012 Author Posted February 17, 2012 (edited) oops, I forget that lol. what I must add to script to set the player can spawn only 1 vehicle? thanks again... Edited February 17, 2012 by Guest
drk Posted February 17, 2012 Posted February 17, 2012 http://lua-users.org/wiki/TablesTutorialipairs works with indexed tables as far as I know, and pairs works with every kind of table (I may be wrong too). pairs is for non-indexed tables. I tried with pairs too but it don't worked. EPT Team Server Development: 0% Learning C++ | C++ is amazing
drk Posted February 17, 2012 Posted February 17, 2012 Really? Solidsnake has said.. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Kenix Posted February 17, 2012 Posted February 17, 2012 pairs: t = { [1] = 1; ['two'] = 2; } for i,v in pairs( t ) do print( i,v ) --[[ 1 1 two 2 ]] end ipairs: t = { [1] = 1; ['two'] = 2; } for i,v in ipairs( t ) do print( i,v ) --[[ 1 1 ]] end http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Kenix Posted February 18, 2012 Posted February 18, 2012 No problem Remember ipairs work only with number indexes and number indexes should be order. ( 1,2,3,.. ) not (1,3,5,.. ) pairs work with all indexes. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Kenix Posted February 18, 2012 Posted February 18, 2012 No problem http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
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