Jump to content

I need a fix for my script [Solved]


Spidy

Recommended Posts

Posted (edited)

Hello there!

I lately started learning scripting, yet I'm still new, I have made my first script, and ofc, something is missed on it because it doesn't work, the script is /goto (mapname)

function Changemap (thePlayer, goto) 
        bool changeGamemodeMap ( resource newMap, [ resource gamemodeToChangeTo ] ) 
        outputChatBox(getPlayerName(source).." changed the map!") 
end      
addCommandHandler("ChangeGamemod", Changemap) 

As I said, I'm still new at scripting, I hope I won't get aggressive comments..

Thanks!

Edited by Guest
Posted
function Changemap (thePlayer, cmd, goTo) 
    exports.mapmanager:changeGamemodeMap (goTo) 
    outputChatBox(getPlayerName(thePlayer).." changed the map!") 
end     
addCommandHandler("goto", Changemap) 

Im not sure myself as i never worked with the mapmanager, but i belive this is right.

Ingame do /goto mapname

Guest Guest4401
Posted
addCommandHandler('goto', 
    function(p,c,...) 
        local m = table.concat(arg,' ') 
        local e = exports.mapmanager 
        if #m > 0 then 
            for i,v in ipairs(e:getMaps()) do 
                local n = getResourceInfo(v,'name') 
                if n and n:lower():find(m:lower(),1,true) then 
                    e:changeGamemodeMap(v) 
                    return outputChatBox(getPlayerName(p)..' starts '..n,root,255,255,0) 
                end 
            end 
            return outputChatBox('Map not found',p,255,255,0) 
        else 
            outputChatBox('/goto [mapname]',p,255,0,0) 
        end 
    end 
) 

Posted

Karthik's one works, but I have to type whole mapname to goto, it's like the /changemap cmd, I don't want it in this way, I want it like:

E.gs: /goto Pure Skills P, it'll goto Pure Skills Paradise

/goto DC ,if there are two maps with the name DC it'll has to say "Found (2) matches": 'DC 15', 'DC 16'.."

Got me?

Guest Guest4401
Posted
local showmapsLimit = 5 
addCommandHandler('goto', 
    function(p,c,...) 
        local m = table.concat(arg,' ') 
        local e = exports.mapmanager 
        local t = {} 
        if #m > 0 then 
            for i,v in ipairs(e:getMaps()) do 
                local n = getResourceInfo(v,'name') 
                if n and n:lower():find(m:lower(),1,true) then 
                    table.insert(t,{v,n}) 
                end 
            end 
            if #t == 0 then 
                outputChatBox('No maps found',p,255,0,0) 
            elseif #t == 1 then 
                e:changeGamemodeMap(t[1][1]) 
                outputChatBox(getPlayerName(p)..' starts '..t[1][2],root,255,255,0) 
            else 
                outputChatBox('Found '.. #t ..' matches:',p) 
                for i,v in ipairs(t) do 
                    outputChatBox(v[2]) 
                    if i == showmapsLimit then 
                        outputChatBox('...',p) 
                        break 
                    end 
                end 
            end 
        else 
            outputChatBox('/goto [mapname]',p,255,0,0) 
        end 
    end 
) 

Posted

Still does not work..Whenever I type /goto a mapname it says "goto (mapname), once I write the whole name still nothing happen..

Debugscript 3: goto:8: "bad agrument #1 "ipairs' (table expected, got boolean)"..

Guest Guest4401
Posted
Still does not work..Whenever I type /goto a mapname it says "goto (mapname), once I write the whole name still nothing happen..

Are you sure you've put the code serverside?

Debugscript 3: goto:8: "bad agrument #1 "ipairs' (table expected, got boolean)"..

Are you sure that mapmanager resource is running?

Posted

No I wasn't.. Sorry..

Set it serverside and it works now, thank you for wasting your time helping me)

You can close this as well.

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