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

anim_05f0aed7-5366-1024-9de0-f07365d770cc.gif
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

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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?

anim_05f0aed7-5366-1024-9de0-f07365d770cc.gif
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) 

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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...