Jump to content

مساعدة في كود


Recommended Posts

السلام عليكم ,

ياعيال ابي اضيف كود الالوان للسطر 72 , 113

currentGamemode = nil 
currentGamemodeMap = nil
nextGamemode = nil
nextGamemodeMap = nil
 
setGameType(false)
setMapName("None")
 
rootElement = getRootElement()
 
addEvent("onGamemodeStart")
addEvent("onGamemodeStop")
addEvent("onGamemodeMapStart")
addEvent("onGamemodeMapStop")
 
addEventHandler("onResourcePreStart", rootElement,
    function (startingResource)
        --Is starting resource a gamemode?
        if isGamemode(startingResource) then
            --Check if another gamemode is running already
            if getRunningGamemode() and getRunningGamemode() ~= startingResource then
                -- Initiate a new changemode sequence and cancel this event
                outputMapManager( "Initiating changemode from '" .. getResourceName(getRunningGamemode()) .. "' to '" .. getResourceName(startingResource) .. "'" )
                changeGamemode(startingResource)
                cancelEvent(true)
            end
        elseif isMap(startingResource) then
            --Check if another map is running already
            if getRunningGamemodeMap() and getRunningGamemodeMap() ~= startingResource then
                -- Initiate a new changemap sequence and cancel this event
                if isGamemodeCompatibleWithMap ( getRunningGamemode(), startingResource ) then
                    outputMapManager( "Initiating changemap from '" .. getResourceName(getRunningGamemodeMap()) .. "' to '" .. getResourceName(startingResource) .. "'" )
                    changeGamemodeMap(startingResource)
                end
                cancelEvent(true)
            end
        end
    end
)
 
addEventHandler("onPlayerJoin", rootElement,
    function()
        if get("currentmap") and getRunningGamemode() and getRunningGamemodeMap() then
            outputMapManager(
                "Currently playing: " ..
                (getResourceInfo(getRunningGamemode(), "name") or getResourceName(getRunningGamemode())) ..
                " - " ..
                (getResourceInfo(getRunningGamemodeMap(), "name") or getResourceName(getRunningGamemodeMap())),
                source
            )
        end
    end
)
 
addEventHandler("onResourceStart", rootElement,
    function (startedResource)
        --Is this resource a gamemode?
        if isGamemode(startedResource) then
            --Check no gamemode is running already
            if getRunningGamemode() then
                return
            end
            if triggerEvent("onGamemodeStart", getResourceRootElement(startedResource), startedResource) then
                currentGamemode = startedResource
                --Setup our announcements
                local gamemodeName = getResourceInfo(currentGamemode, "name") or getResourceName(currentGamemode)
                if get("ASE") then
                    setGameType(gamemodeName)
                end
                if get("messages") then
                    local name = getInstigatorName ( " by " ) or ""
                    outputMapManager("Gamemode '"..gamemodeName.."' started" .. name .. "." )
                end
                --We need to wait a while to see if any maps were started.  If not, lets try and start a random one
                setTimer(
                    function()
                        if not getRunningGamemodeMap() then
                            --Lets check if there are any maps for this gamemode
                            local maps = getMapsCompatibleWithGamemode(getRunningGamemode())
                            --If we have any, we'll start a random one
                            if #maps > 0 then
                                changeGamemodeMap (maps[math.random(1,#maps)])
                            end
                        end
                    end,
                50, 1 )
            else
                currentGamemode = nil
            end
        elseif isMap(startedResource) then --If its a map
            --Make sure there is a gamemode running
            if not getRunningGamemode() then
                return
            end
            --Is there a map running already?
            if getRunningGamemodeMap() then
                return
            end
            --Is it compatible with our gamemode?
            if isGamemodeCompatibleWithMap ( getRunningGamemode(), startedResource ) then
                --Lets link the map with the gamemode
                if ( triggerEvent("onGamemodeMapStart", getResourceRootElement(startedResource), startedResource) ) then
                    currentGamemodeMap = startedResource
                    --Setup our announcements
                    local gamemodeMapName = getResourceInfo(currentGamemodeMap, "name") or getResourceName(currentGamemodeMap)
                    applyMapSettings( currentGamemodeMap )
                   
                    if get("ASE") then
                        setMapName(gamemodeMapName)
                    end
                    if get("messages") then
                        local name = getInstigatorName ( " by " ) or ""
                        outputMapManager("Map '"..gamemodeMapName.."' started" .. name .. ".")
                    end
                else
                    currentGamemodeMap = nil
                end
            end
        end
    end
)
 
addEventHandler("onResourceStop", rootElement,
    function (stoppedResource)
        -- Incase the resource being stopped has been deleted
        local stillExists = false
        for i, res in ipairs(getResources()) do
            if res == stoppedResource then
                stillExists = true
                break
            end
        end
        if not stillExists then return end
       
        local resourceRoot = getResourceRootElement(stoppedResource)
        if stoppedResource == currentGamemode then
            triggerEvent("onGamemodeStop", resourceRoot, currentGamemode)
           
            currentGamemode = nil
            setGameType(false)
           
            if currentGamemodeMap then
                stopResource(currentGamemodeMap)
            elseif nextGamemode then
                startGamemodeT(nextGamemode)
                nextGamemode = nil
                if nextGamemodeMap then
                    startGamemodeMapT(nextGamemodeMap)
                    nextGamemodeMap = nil
                end
            end
        elseif stoppedResource == currentGamemodeMap then
            triggerEvent("onGamemodeMapStop", resourceRoot, currentGamemodeMap)
           
            currentGamemodeMap = nil
            resetMapInfo()
            setMapName("None")
           
            if nextGamemode then
                startGamemodeT(nextGamemode)
                nextGamemode = nil
                if nextGamemodeMap then
                    startGamemodeMapT(nextGamemodeMap)
                    nextGamemodeMap = nil
                end
            elseif nextGamemodeMap then
                startGamemodeMapT(nextGamemodeMap)
                nextGamemodeMap = nil
            end
        end
    end
)
 
function changeGamemodeMap_cmd(source, command, ...)
    local mapName = #{...}>0 and table.concat({...},' ') or nil
    source = source or serverConsole
 
    local map
    if mapName then
        map = getMapFromName(mapName)
        if not isMap(map) then
            if (refreshResources and hasObjectPermissionTo(getThisResource(), "function.refreshResources", false)) then
                outputMapManager("'"..mapName.."' is not a valid map.", source)
            else
                outputMapManager("'"..mapName.."' is not a valid map. Use the refresh command and try again", source)
            end
            return false
        end
    else
        outputMapManager("Usage: /"..command.." map",source)
        return false
    end
   
    local gamemode = currentGamemode
    if not isGamemode(gamemode) then
        outputMapManager("No gamemode is running.",source)
    elseif not isMapCompatibleWithGamemode(map, gamemode) then
        outputMapManager("Map '"..getResourceName(map)..
            "' is not compatible with '"..getResourceName(gamemode).."'.",source)
    else
        setInstigator( source )
        changeGamemodeMap(map, gamemode)
    end
end
addCommandHandler("changemap", changeGamemodeMap_cmd, true)
 
function changeGamemode_cmd(source, command, gamemodeName,...)
    local mapName = #{...}>0 and table.concat({...},' ') or nil
    source = source or serverConsole
 
    local gamemode
    if gamemodeName then
        gamemode = getResourceFromName(gamemodeName)
        if not isGamemode(gamemode) then
            if (refreshResources and hasObjectPermissionTo(getThisResource(), "function.refreshResources", false)) then
                refreshResources(false)
                gamemode = getResourceFromName(gamemodeName)
                if not isGamemode(gamemode) then
                    outputMapManager("'"..gamemodeName.."' is not a valid gamemode.", source)
                    return false
                end
            else
                outputMapManager("'"..gamemodeName.."' is not a valid gamemode. Use the refresh command and try again", source)
                return false
            end
        end
    else
        outputMapManager("Usage: /"..command.." gamemode [map]",source)
        return false
    end
   
    local map
    if mapName then
        map = getMapFromName(mapName)
        if not isMap(map) then
            if (refreshResources and hasObjectPermissionTo(getThisResource(), "function.refreshResources", false)) then
                outputMapManager("'"..mapName.."' is not a valid map.", source)
            else
                outputMapManager("'"..mapName.."' is not a valid map. Use the refresh command and try again", source)
            end
            return false
        end
    end
    setInstigator( source )
    changeGamemode(gamemode,map)
end
addCommandHandler("gamemode", changeGamemode_cmd, true)
addCommandHandler("changemode", changeGamemode_cmd, true)
 
function stopGamemode_cmd(source)
    source = source or serverConsole
   
Link to comment

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