Mossy Posted September 30, 2012 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
Jaysds1 Posted September 30, 2012 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
Mossy Posted September 30, 2012 Author 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?
Jaysds1 Posted September 30, 2012 Posted September 30, 2012 well, if you are in the admin acl then use this function: isObjectInACLGroup BTW, fixed the error
Mossy Posted September 30, 2012 Author Posted September 30, 2012 well, if you are in the admin acl then use this function: isObjectInACLGroup BTW, fixed the error Code please? :>
Jaysds1 Posted September 30, 2012 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)
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