DarkLink Posted June 27, 2012 Share Posted June 27, 2012 Hi there, while I am doing my resource, I would like to do it with support for this managers. Because there will be more than one map for the resource, and I would like to while the resource is running, when one match ends, appears the votemanager panel to vote for another map.. u see? I am already using events from mapmanager like : "onGamemodeMapStart" to handle some things, but I dont know how to "connect" votemanager with my resource. Can someone give me some hints please? Thanks alot in advance! Link to comment
DarkLink Posted June 28, 2012 Author Share Posted June 28, 2012 Anyone over here ? thanks Link to comment
Anderl Posted June 29, 2012 Share Posted June 29, 2012 He is not talking about that, I think. Link to comment
50p Posted June 29, 2012 Share Posted June 29, 2012 https://wiki.multitheftauto.com/wiki/Res ... otemanager Check its wiki page. There are all the functions you'll need to know about. To call the functions you need to use exports table, like so: exports.votemanager:startPoll( ..... ) -- OR exports["votemanager"]:startPoll( ..... ) Link to comment
DarkLink Posted July 3, 2012 Author Share Posted July 3, 2012 Hi there 50p , thanks again for all your support , since some years ago u are here, helping me out, I remember I did what u suggested, but I am with some problems over here, error on console: [2012-07-03 15:54:47] ERROR: bp\server_pickweed.lua:117: attempt to call a table value Here is my code and the line 117.. addEvent("say", true) function startP() exports.votemanager:startPoll({ title="Choose a map do change to..", percentage=75, timeout=30, allowchange=false, maxnominations=3, visibleTo=getRootElement(), getTable()} ) end addCommandHandler("poll", startP) function fSay(sayT) outputChatBox("Isto: " .. sayT) end addEventHandler("say", getRootElement(), fSay) function getTable() local t = {} local tableOfMaps = {} local stringOfMap = getMap() table.insert(tableOfMaps,stringOfMap) for i = 1 , 3 do local found = false while(found == false) do stringOfMap = getMap() for a,v in tableOfMaps do -- this is the line 117 ! if( stringOfMap == v ) then found = true end end end table.insert(tableOfMaps,stringOfMap) end for i, v in tableOfMaps do t[i] = {v, "say", getRootElement(), false, "I'm the number" .. i .. " with map name : " .. v } end return t end function getMap() local tb = exports.mapmanager:getMapsCompatibleWithGamemode(exports.mapmanager:getRunningGamemode ()) return getResourceName (tb[math.random(#tb)]) end Thanks alot in advance!! Would appreciate some help dude Link to comment
50p Posted July 3, 2012 Share Posted July 3, 2012 Don't you know how to do "for" loops? You can't call a table, you need to iterate through table with ipairs or pairs: for a,v in ipairs( tableOfMaps ) do Link to comment
DarkLink Posted July 3, 2012 Author Share Posted July 3, 2012 Don't you know how to do "for" loops? You can't call a table, you need to iterate through table with ipairs or pairs: for a,v in ipairs( tableOfMaps ) do Hey mate, I got it a few seconds after, was a mistake x) But still is not working... It enters on a infinite loop, i guess on getTable() function Cant understand why, can u help me ? Link to comment
50p Posted July 3, 2012 Share Posted July 3, 2012 Don't you know how to do "for" loops? You can't call a table, you need to iterate through table with ipairs or pairs: for a,v in ipairs( tableOfMaps ) do Hey mate, I got it a few seconds after, was a mistake x) But still is not working... It enters on a infinite loop, i guess on getTable() function Cant understand why, can u help me ? It's simple, never use while loops if you don't know how to make them stop. In your case, "found" will always be false unless stringOfMap is in tableOfMaps. You can't just call a function and pass a table inside a table to the startPoll like you're doing because a list of the options will be a table (in your case) but startPoll only needs 1 table and its values at [1], [2], etc. are the vote options. Anyway, if you want to start any of 3 random maps then use you could use voteBetweenMaps function instead. Link to comment
DarkLink Posted July 3, 2012 Author Share Posted July 3, 2012 Don't you know how to do "for" loops? You can't call a table, you need to iterate through table with ipairs or pairs: for a,v in ipairs( tableOfMaps ) do Hey mate, I got it a few seconds after, was a mistake x) But still is not working... It enters on a infinite loop, i guess on getTable() function Cant understand why, can u help me ? It's simple, never use while loops if you don't know how to make them stop. In your case, "found" will always be false unless stringOfMap is in tableOfMaps. You can't just call a function and pass a table inside a table to the startPoll like you're doing because a list of the options will be a table (in your case) but startPoll only needs 1 table and its values at [1], [2], etc. are the vote options. Anyway, if you want to start any of 3 random maps then use you could use voteBetweenMaps function instead. I was using the wrong variable, but now, it should work right ? Have a look: function getTable() local t = {} local tableOfMaps = {} local maps = getMaps() local stringOfMap = maps[math.random(#maps)] table.insert(tableOfMaps,stringOfMap) for i = 1 , 3 do local found = true while(found ~= false) do stringOfMap = maps[math.random(#maps)] local found = false for a,v in ipairs(tableOfMaps) do -- this is the line 117 ! if( stringOfMap == v ) then found = true end end end table.insert(tableOfMaps,stringOfMap) end for i, v in ipairs(tableOfMaps) do t[i] = {v, "say", getRootElement(), default = false, "I'm the number" .. i .. " with map name : " .. v } end return t end But sill infinite By the way, yes I need to use [1], [2] ... instead of using a table, I got that , thanks. But that is not such dinamic.. if I want to use more maps on another vote, how do I do it ? have many functions to start different startPolls ? Its not possible to had [1], [2].. using a for on that function startPoll, right ? Thanks alot in advance mate! Link to comment
DarkLink Posted July 3, 2012 Author Share Posted July 3, 2012 The map names are: "bp-official" , "bp-official_2", "bp-official_3", "bp-official_4", "bp-official_5" .. since comparing strings on lua using '==' operator, compare byte by byte, maybe cant find differences ? just asking... but I guess its not that problem.. Link to comment
DarkLink Posted July 3, 2012 Author Share Posted July 3, 2012 LOOOOOL found the problem I was creating another found variable, because I use local inside that while Got it fixed, thanks alot 50p ANYWAY, can u answer me this : By the way, yes I need to use [1], [2] ... instead of using a table, I got that , thanks. But that is not such dinamic.. if I want to use more maps on another vote, how do I do it ? have many functions to start different startPolls ? Its not possible to had [1], [2].. using a for on that function startPoll, right ? Thanks alot in advance mate! Link to comment
50p Posted July 3, 2012 Share Posted July 3, 2012 You can make it dynamic. Remember, you're passing a table to startPoll and your function is still wrong. Local variable is only accessible in its code block (inside where it was defined), you seem to define 2 "found" variables and the first one will always be true, the if statement checks the first one, can you see what you did wrong?(you found it yourself) -- here is a function which will change your votedata table to contain maps and return it function giveMeRandomMapsToMyTable( tab, mapsCount ) local compatibleMaps = exports.mapmanager:getMapsCompatibleWithGamemode(exports.mapmanager:getRunningGamemode ()) if #compatibleMaps >= mapsCount then for i = 1, mapsCount then local rndMap = getResourceName( compatibleMaps[ math.random( #compatibleMaps ) ] ); local found = false; repeat -- check if the rndMap is already on the list for j = 1, mapsCount do if tab[ j ][ 1 ] and tab[ j ][ 1 ] == rndMap then found = true; rndMap = compatibleMaps[ math.random( #compatibleMaps ) ]; break; end end until found == false; tab[ i ] = { rndMap, "say", root, "Random map #" .. tostring( i ) .. ": ".. rndMap }; end return tab; end outputDebugString( "Not enough compatible maps! (mapsCount="..tostring( mapsCount ) .."; compatible maps: "..tostring( #compatibleMaps ) ..")" ); return false; end -- here is the table with settings of your poll that you'll pass to startPoll local votedata = { title="Choose a map do change to..", percentage=75, timeout=30, allowchange=false, maxnominations=3, visibleTo=getRootElement() } votedata = giveMeRandomMapsToMyTable( votedata, 3 ) -- give me 3 random maps -- votedata[ 1 ] will have an option table I haven't tested it and wrote it here so there might be simple mistakes. If this won't work just speak up. Why don't you try voteBetweenMaps? It'd be what you want and much easier. https://wiki.multitheftauto.com/wiki/Res ... otemanager Link to comment
DarkLink Posted July 3, 2012 Author Share Posted July 3, 2012 I managed to put it working, like I did, fixing the local thing like I said. I was just trying to know how could we create dinamic amount of options to the startPoll . What you have will work ? Since ur votedata variable has the settings.. but then just have the maps, it must be inside together with the settings, no ? Thanks EDIT: voteBetweenMaps would work, but I can't pass a table of resources (maps) I need to write them, give them as arguments... Much less dynamic Look: bool, int voteBetweenMaps ( resource map1, resource map2, [ resource map3, ... ] ) Link to comment
50p Posted July 4, 2012 Share Posted July 4, 2012 My votedata contains only poll settings (that's what you want), then (look at line 34) I call the function I wrote which add the maps to votedata table and returns this table (the returned table is then reassigned to votedata with maps inside). 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