Mossy Posted September 30, 2012 Share Posted September 30, 2012 I'm making a script that will start a random map with the command "/random". What I'm asking is how can I set a function to generate a random map? I couldn't find a function on the wiki to do this, yet I used a resource that did this. Please help Link to comment
Jaysds1 Posted September 30, 2012 Share Posted September 30, 2012 (edited) Like this: local maps = {} addCommandHandler("random",function(source) for _,v in ipairs(getResources())do --loop through all the resources if string.lower(getResourceInfo(v,"type")) =="map" then --see if it's a map table.insert(maps,v) --if it is, insert it into our table end end map = unpack(math.random(#maps)) --get a random map from the table startResource(map) --start the map end) ?? Edited September 30, 2012 by Guest Link to comment
Mossy Posted September 30, 2012 Author Share Posted September 30, 2012 Like this: ?? Yes. By the way, Line 4 got an error. Function arguments expected near '==' And how can I make it so that only I can do the command? Link to comment
Jaysds1 Posted September 30, 2012 Share Posted September 30, 2012 well, if you are in the admin acl then use this function: isObjectInACLGroup BTW, fixed the error Link to comment
Mossy Posted September 30, 2012 Author Share Posted September 30, 2012 well, if you are in the admin acl then use this function: isObjectInACLGroup BTW, fixed the error Code please? :> Link to comment
Jaysds1 Posted September 30, 2012 Share Posted September 30, 2012 well, if you are in the admin acl then use this function: isObjectInACLGroup BTW, fixed the error Code please? :> uh, local maps = {} addCommandHandler("random",function(source) if not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)),aclGetGroup("admin")) then outputChatBox("You are not an admin!",source) return end for _,v in ipairs(getResources())do --loop through all the resources if string.lower(getResourceInfo(v,"type")) =="map" then --see if it's a map table.insert(maps,v) --if it is, insert it into our table end end map = unpack(math.random(#maps)) --get a random map from the table startResource(map) --start the map end) Link to comment
Mossy Posted September 30, 2012 Author Share Posted September 30, 2012 Works great. Thanks! 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