Jump to content

How would I make a map be random?


Mossy

Recommended Posts

Posted

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 :P

Posted (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 by Guest
Posted
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?

Posted
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) 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...