Jump to content

عندي مشكلة بمود مهمة السنايبر


Recommended Posts

مسوي كل شيئ تمام بس مدري ليش ما يشتغل

السيرفر

local Display = textCreateDisplay() 
local CrText = textCreateTextItem("0 Criminal", 0.05, 0.65, "high", 255, 0, 0, 255, 1.2, "center", "center", 255)
local VsText = textCreateTextItem("Vs", 0.1, 0.65, "high", 255, 255, 255, 255, 1.2, "center", "center", 255)
local PoText = textCreateTextItem("0 Police", 0.15, 0.65, "high", 0, 0, 255, 255, 1.2, "center", "center", 255)
textDisplayAddText(Display, CrText)
textDisplayAddText(Display, VsText)
textDisplayAddText(Display, PoText)
 
CrTable = {}
PoTable = {}
 
function updateText()
    textItemSetText(CrText, #CrTable.." Criminal")
    textItemSetText(PoText, #PoTable.." Police")
end
 
function AddPlayer(player, Table)
    if not getPlayerTable(player, CrTable) and not getPlayerTable(player, PoTable) then
        textDisplayAddObserver(Display, player)
        table.insert(Table, player)
        setElementData(player, "MissionProtection", true)
        if Table == CrTable then
            setPlayerWantedLevel(player, 6)
        end
        updateText()
    end
end
   
function RemovePlayer(player, Table)
    textDisplayRemoveObserver(Display, player)
    for i, v in ipairs (Table) do
        if (v == player) then
            table.remove(Table, i)
            setElementData(player, "MissionProtection", false)
        end
    end
    updateText()
end
 
function getPlayerTable(player, Table)
    for i, v in ipairs (Table) do
        if (v == player) then
            return true
        end
    end
end
 
addEventHandler("onElementDataChange", root,
function(dataName)
    if dataName == "LegalStatus" and (getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable)) then
        local LegalStatus = getElementData(source, dataName)
        if LegalStatus == "Jailed" then
            if getPlayerTeam(source) ~= getTeamFromName("Police") then
                RemovePlayer(source, CrTable)
            elseif getPlayerTeam(source) == getTeamFromName("Police") then
                RemovePlayer(source, PoTable)
            end
            checkForWinner()
        end
    end
end)
 
setPlayerWantedLevel_ = setPlayerWantedLevel
 
function setPlayerWantedLevel(player, level)
    local stat = setPlayerWantedLevel_(player, level)
    if stat then
        setElementData(player, "WantLvl", level)
    end
    return stat
end
 
local CrM = createMarker(476.7, -1488.7, 19.2, "arrow", 2, 255, 0, 0, 150)
local PoM = createMarker(474.5, -1509, 19.5, "arrow", 2, 0, 0, 255, 150)
local CrDoor = createObject(1508, 4342.5, -1649.2, 26.4)
local PoDoor = createObject(1508, 4253.1, -1652.4, 26.4)
 
createBlip(475.4, -1501.57, 20.5, 32)
 
addEventHandler("onResourceStart", resourceRoot,
function()
    exports ["guimessages"] : outputServer(root, "* Go to the red house!!", 50, 0, 255)
    exports ["guimessages"] : outputServer(root, "Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Police : Enter at Blue Marker!", 0, 50, 255)
    standByMission = setTimer(function()
        moveObject(CrDoor, 3500, 4342.5, -1649.2, 29.4)
        moveObject(PoDoor, 3500, 4253.1, -1652.4, 29.4)
        exports ["guimessages"] : outputServer(root, "Sniper Mission Started!!!", 0, 150, 255)
        setTimer(checkForWinner, 1000, 1, true)
    end, 5*60*1000, 1)
end)
 
function getTimeLeft(Timer)
    if startTheMission == Timer then
        ms = getTimerDetails(Timer) + 300000
    else
        ms = getTimerDetails(Timer)
    end
    local m = math.floor(ms/60000)
    local s = math.floor((ms-m*60000)/1000)
    if m < 10 then m = ""..m end
    if s < 10 then s = ""..s end
    return "("..m.." Min and "..s.." Sec)"
end
 
addCommandHandler("snipertime",
function(player)
    if isTimer(standByMission) then
        exports ["guimessages"] : outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(standByMission), 0, 255, 0)
    elseif isTimer(startTheMission) then
        exports ["guimessages"] : outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(startTheMission),  0, 255, 0)
    else
        exports ["guimessages"] : outputServer(player, "Sniper Mission is in progress now!", 0, 255, 0)
    end
end)
 
local PolicePosition = {
    {7666.8, -914.6, 9.1},
    {7665.4, -909.1, 9.1},
    {7668.6, -904.8, 9.1},
    {7664.7, -897.9, 9.1},
    {7668.9, -894.3, 9.1},
    {7656.9, -895.9, 9.1},
    {7654.1, -904.5, 9.1},
    {7652.6, -914.1, 9.1}
}
 
local PoliceOutPosition = {
    {216.6, 76.57, 1005.2},
    {216.3, 80.5, 1005.2},
    {219.83, 79.8, 1005.2}
}
 
local CriminalPosition = {
    {7998.4, -916.3, 9.1},
    {7993.7, -916.1, 9.1},
    {7994.1, -910.6, 9.1},
    {7994.4, -899.1, 9.1},
    {8001.2, -899.2, 9.1},
    {8004.9, -906.1, 9.1},
    {8010.5, -915.2, 9.1}
}
 
local CriminalOutPosition = {
    {486.5, -1492.6, 20.2},
    {487.2, -1474.7, 19.2},
    {492.6, -1469.85, 18.55},
    {489.4, -1464.85, 18.3},
    {487.1, -1503.9, 20.4},
    {483.1, -1515.1, 20.3},
    {489.4, -1526.2, 19.77},
    {485.1, -1534.1, 19.4}
}
 
 
addEventHandler("onMarkerHit", root,
function(player)
    if getElementType(player) == "player" and not isPedInVehicle(player) then
        if isTimer(standByMission) then
            if source == CrM and getPlayerTeam(player) ~= getTeamFromName("Police") then
                local x, y, z = unpack(CriminalPosition[math.random(#CriminalPosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, CrTable)
            elseif source == PoM and getPlayerTeam(player) == getTeamFromName("Police") then
                local x, y, z = unpack(PolicePosition[math.random(#PolicePosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, PoTable)
            end
        end
    end
end)
 
TopKill = {}
 
function sortTop()
    sortedTopKill = {}
    for a, b in pairs(TopKill) do
        table.insert(sortedTopKill, {getPlayerName(a), b})
    end
    table.sort(sortedTopKill, function(a,b) return a[2] > b[2] end)
end
 
addEventHandler("onPlayerWasted", root,
function(_, killer)
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if killer and getElementType(killer) == "player" then
            exports ["guimessages"] : outputServer(root, getPlayerName(killer).." Killed "..getPlayerName(source).." in Sniper Mission!", 255, 0, 255)
            TopKill[killer] = (TopKill[killer] or 0) + 1
        else
            exports ["guimessages"] : outputServer(root, getPlayerName(source).." dead in Sniper Mission!", 255, 0, 255)
        end
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
addEventHandler("onPlayerQuit", root,
function()
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
function checkForWinner(cHk)
    if cHk then
        TopKill = {}
    end
    if not isTimer(standByMission) and not isTimer(startTheMission) then
        if #CrTable > 0 and #PoTable == 0 then
            if not cHk then
                exports ["guimessages"] : outputServer(root ,"The Criminals won the Sniper Mission!", 255, 100, 0)
                exports ["guimessages"] : outputServer(root ,"--| Top Kills of Sniper Mission |--", 255, 255, 0)
                sortTop()
                if sortedTopKill[1] then exports ["guimessages"] : outputServer(root ,"1. "..sortedTopKill[1][1]..": "..sortedTopKill[1][2], 255, 0, 255) end
                if sortedTopKill[2] then exports ["guimessages"] : outputServer(root ,"2. "..sortedTopKill[2][1]..": "..sortedTopKill[2][2], 255, 0, 255) end
                if sortedTopKill[3] then exports ["guimessages"] : outputServer(root ,"3. "..sortedTopKill[3][1]..": "..sortedTopKill[3][2], 255, 0, 255) end
            else
                exports ["guimessages"] : outputServer(root ,"The Sniper Mission was Draw!", 255, 0, 0)
            end
            for _, p in ipairs (CrTable) do
                textDisplayRemoveObserver(Display, p)
                if not cHk then
                    setElementData(player, "Money", (getElementData(player, "Money") + 30000 )
                end
                local x, y, z = unpack(CriminalOutPosition[math.random(#CriminalOutPosition)])
                setElementPosition(p, x, y, z)
                setElementData(p, "MissionProtection", false)
            end
            CrTable = {}
            PoTable = {}
            updateText()
            startTheMission = setTimer(function()
                    exports ["guimessages"] : outputServer(root ,"* Go to the red house!!", 50, 0, 255)
    exports ["guimessages"] : outputServer(root ,"Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports ["guimessages"] : outputServer(root ,"*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports ["guimessages"] : outputServer(root ,"*For Police : Enter at Blue Marker!", 0, 50, 255)
                moveObject(CrDoor, 3500, 4342.5, -1649.2, 26.4)
                moveObject(PoDoor, 3500, 4253.1, -1652.4, 26.4)
                standByMission = setTimer(function()
                    moveObject(CrDoor, 3500, 4342.5, -1649.2, 29.4)
                   
Link to comment

وين خطأ واحد طلع عندك 7 سطور ض1

local Display = textCreateDisplay() 
local CrText = textCreateTextItem("0 Criminal", 0.05, 0.65, "high", 255, 0, 0, 255, 1.2, "center", "center", 255)
local VsText = textCreateTextItem("Vs", 0.1, 0.65, "high", 255, 255, 255, 255, 1.2, "center", "center", 255)
local PoText = textCreateTextItem("0 Police", 0.15, 0.65, "high", 0, 0, 255, 255, 1.2, "center", "center", 255)
textDisplayAddText(Display, CrText)
textDisplayAddText(Display, VsText)
textDisplayAddText(Display, PoText)
 
CrTable = {}
PoTable = {}
 
function updateText()
    textItemSetText(CrText, #CrTable.." Criminal")
    textItemSetText(PoText, #PoTable.." Police")
end
 
function AddPlayer(player, Table)
    if not getPlayerTable(player, CrTable) and not getPlayerTable(player, PoTable) then
        textDisplayAddObserver(Display, player)
        table.insert(Table, player)
        setElementData(player, "MissionProtection", true)
        if Table == CrTable then
            setPlayerWantedLevel(player, 6)
        end
        updateText()
    end
end
   
function RemovePlayer(player, Table)
    textDisplayRemoveObserver(Display, player)
    for i, v in ipairs (Table) do
        if (v == player) then
            table.remove(Table, i)
            setElementData(player, "MissionProtection", false)
        end
    end
    updateText()
end
 
function getPlayerTable(player, Table)
    for i, v in ipairs (Table) do
        if (v == player) then
            return true
        end
    end
end
 
addEventHandler("onElementDataChange", root,
function(dataName)
    if dataName == "LegalStatus" and (getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable)) then
        local LegalStatus = getElementData(source, dataName)
        if LegalStatus == "Jailed" then
            if getPlayerTeam(source) ~= getTeamFromName("Police") then
                RemovePlayer(source, CrTable)
            elseif getPlayerTeam(source) == getTeamFromName("Police") then
                RemovePlayer(source, PoTable)
            end
            checkForWinner()
        end
    end
end)
 
setPlayerWantedLevel_ = setPlayerWantedLevel
 
function setPlayerWantedLevel(player, level)
    local stat = setPlayerWantedLevel_(player, level)
    if stat then
        setElementData(player, "WantLvl", level)
    end
    return stat
end
 
local CrM = createMarker(476.7, -1488.7, 19.2, "arrow", 2, 255, 0, 0, 150)
local PoM = createMarker(474.5, -1509, 19.5, "arrow", 2, 0, 0, 255, 150)
local CrDoor = createObject(1508, 4342.5, -1649.2, 26.4)
local PoDoor = createObject(1508, 4253.1, -1652.4, 26.4)
 
createBlip(475.4, -1501.57, 20.5, 32)
 
addEventHandler("onResourceStart", resourceRoot,
function()
    exports ["guimessages"] : outputServer(root, "* Go to the red house!!", 50, 0, 255)
    exports ["guimessages"] : outputServer(root, "Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Police : Enter at Blue Marker!", 0, 50, 255)
    standByMission = setTimer(function()
        moveObject(CrDoor, 3500, 4342.5, -1649.2, 29.4)
        moveObject(PoDoor, 3500, 4253.1, -1652.4, 29.4)
        exports ["guimessages"] : outputServer(root, "Sniper Mission Started!!!", 0, 150, 255)
        setTimer(checkForWinner, 1000, 1, true)
    end, 5*60*1000, 1)
end)
 
function getTimeLeft(Timer)
    if startTheMission == Timer then
        ms = getTimerDetails(Timer) + 300000
    else
        ms = getTimerDetails(Timer)
    end
    local m = math.floor(ms/60000)
    local s = math.floor((ms-m*60000)/1000)
    if m < 10 then m = ""..m end
    if s < 10 then s = ""..s end
    return "("..m.." Min and "..s.." Sec)"
end
 
addCommandHandler("snipertime",
function(player)
    if isTimer(standByMission) then
        exports ["guimessages"] : outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(standByMission), 0, 255, 0)
    elseif isTimer(startTheMission) then
        exports ["guimessages"] : outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(startTheMission),  0, 255, 0)
    else
        exports ["guimessages"] : outputServer(player, "Sniper Mission is in progress now!", 0, 255, 0)
    end
end)
 
local PolicePosition = {
    {7666.8, -914.6, 9.1},
    {7665.4, -909.1, 9.1},
    {7668.6, -904.8, 9.1},
    {7664.7, -897.9, 9.1},
    {7668.9, -894.3, 9.1},
    {7656.9, -895.9, 9.1},
    {7654.1, -904.5, 9.1},
    {7652.6, -914.1, 9.1}
}
 
local PoliceOutPosition = {
    {216.6, 76.57, 1005.2},
    {216.3, 80.5, 1005.2},
    {219.83, 79.8, 1005.2}
}
 
local CriminalPosition = {
    {7998.4, -916.3, 9.1},
    {7993.7, -916.1, 9.1},
    {7994.1, -910.6, 9.1},
    {7994.4, -899.1, 9.1},
    {8001.2, -899.2, 9.1},
    {8004.9, -906.1, 9.1},
    {8010.5, -915.2, 9.1}
}
 
local CriminalOutPosition = {
    {486.5, -1492.6, 20.2},
    {487.2, -1474.7, 19.2},
    {492.6, -1469.85, 18.55},
    {489.4, -1464.85, 18.3},
    {487.1, -1503.9, 20.4},
    {483.1, -1515.1, 20.3},
    {489.4, -1526.2, 19.77},
    {485.1, -1534.1, 19.4}
}
 
 
addEventHandler("onMarkerHit", root,
function(player)
    if getElementType(player) == "player" and not isPedInVehicle(player) then
        if isTimer(standByMission) then
            if source == CrM and getPlayerTeam(player) ~= getTeamFromName("Police") then
                local x, y, z = unpack(CriminalPosition[math.random(#CriminalPosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, CrTable)
            elseif source == PoM and getPlayerTeam(player) == getTeamFromName("Police") then
                local x, y, z = unpack(PolicePosition[math.random(#PolicePosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, PoTable)
            end
        end
    end
end)
 
TopKill = {}
 
function sortTop()
    sortedTopKill = {}
    for a, b in pairs(TopKill) do
        table.insert(sortedTopKill, {getPlayerName(a), b})
    end
    table.sort(sortedTopKill, function(a,b) return a[2] > b[2] end)
end
 
addEventHandler("onPlayerWasted", root,
function(_, killer)
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if killer and getElementType(killer) == "player" then
            exports ["guimessages"] : outputServer(root, getPlayerName(killer).." Killed "..getPlayerName(source).." in Sniper Mission!", 255, 0, 255)
            TopKill[killer] = (TopKill[killer] or 0) + 1
        else
            exports ["guimessages"] : outputServer(root, getPlayerName(source).." dead in Sniper Mission!", 255, 0, 255)
        end
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
addEventHandler("onPlayerQuit", root,
function()
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
function checkForWinner(cHk)
    if cHk then
        TopKill = {}
    end
    if not isTimer(standByMission) and not isTimer(startTheMission) then
        if #CrTable > 0 and #PoTable == 0 then
            if not cHk then
                exports ["guimessages"] : outputServer(root ,"The Criminals won the Sniper Mission!", 255, 100, 0)
                exports ["guimessages"] : outputServer(root ,"--| Top Kills of Sniper Mission |--", 255, 255, 0)
                sortTop()
                if sortedTopKill[1] then exports ["guimessages"] : outputServer(root ,"1. "..sortedTopKill[1][1]..": "..sortedTopKill[1][2], 255, 0, 255) end
                if sortedTopKill[2] then exports ["guimessages"] : outputServer(root ,"2. "..sortedTopKill[2][1]..": "..sortedTopKill[2][2], 255, 0, 255) end
                if sortedTopKill[3] then exports ["guimessages"] : outputServer(root ,"3. "..sortedTopKill[3][1]..": "..sortedTopKill[3][2], 255, 0, 255) end
            else
                exports ["guimessages"] : outputServer(root ,"The Sniper Mission was Draw!", 255, 0, 0)
            end
            for _, p in ipairs (CrTable) do
                textDisplayRemoveObserver(Display, p)
                if not cHk then
                    setElementData(player, "Money", (getElementData(player, "Money") + 30000 )
                    )
                local x, y, z = unpack(CriminalOutPosition[math.random(#CriminalOutPosition)])
                setElementPosition(p, x, y, z)
                setElementData(p, "MissionProtection", false)
            CrTable = {}
            PoTable = {}
            updateText()
            startTheMission = setTimer(function()
                    exports ["guimessages"] : outputServer(root ,"* Go to the red house!!", 50, 0, 255)
    exports ["guimessages"] : outputServer(root ,"Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports ["guimessages"] : outputServer(root ,"*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports ["guimessages"] : outputServer(root ,"*For Police : Enter at Blue Marker!", 0, 50, 255)
                moveObject(CrDoor, 3500, 4342.5, -1649.2, 26.4)
                moveObject(PoDoor, 3500, 4253.1, -1652.4, 26.4)
                standByMission = setTimer(function()
                    moveObject(CrDoor, 3500, 4342.5, -1649.2, 29.4)
                    moveObject(PoDoor, 3500, 4253.1, -1652.4, 29.4)
                    exports ["guimessages"] : outputServer(root ,"Sniper Mission Started!!!", 0, 150, 255)
                   
Link to comment

كودك خطا

وين خطأ واحد طلع عندك 7 سطور ض1

local Display = textCreateDisplay() 
local CrText = textCreateTextItem("0 Criminal", 0.05, 0.65, "high", 255, 0, 0, 255, 1.2, "center", "center", 255)
local VsText = textCreateTextItem("Vs", 0.1, 0.65, "high", 255, 255, 255, 255, 1.2, "center", "center", 255)
local PoText = textCreateTextItem("0 Police", 0.15, 0.65, "high", 0, 0, 255, 255, 1.2, "center", "center", 255)
textDisplayAddText(Display, CrText)
textDisplayAddText(Display, VsText)
textDisplayAddText(Display, PoText)
 
CrTable = {}
PoTable = {}
 
function updateText()
    textItemSetText(CrText, #CrTable.." Criminal")
    textItemSetText(PoText, #PoTable.." Police")
end
 
function AddPlayer(player, Table)
    if not getPlayerTable(player, CrTable) and not getPlayerTable(player, PoTable) then
        textDisplayAddObserver(Display, player)
        table.insert(Table, player)
        setElementData(player, "MissionProtection", true)
        if Table == CrTable then
            setPlayerWantedLevel(player, 6)
        end
        updateText()
    end
end
   
function RemovePlayer(player, Table)
    textDisplayRemoveObserver(Display, player)
    for i, v in ipairs (Table) do
        if (v == player) then
            table.remove(Table, i)
            setElementData(player, "MissionProtection", false)
        end
    end
    updateText()
end
 
function getPlayerTable(player, Table)
    for i, v in ipairs (Table) do
        if (v == player) then
            return true
        end
    end
end
 
addEventHandler("onElementDataChange", root,
function(dataName)
    if dataName == "LegalStatus" and (getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable)) then
        local LegalStatus = getElementData(source, dataName)
        if LegalStatus == "Jailed" then
            if getPlayerTeam(source) ~= getTeamFromName("Police") then
                RemovePlayer(source, CrTable)
            elseif getPlayerTeam(source) == getTeamFromName("Police") then
                RemovePlayer(source, PoTable)
            end
            checkForWinner()
        end
    end
end)
 
setPlayerWantedLevel_ = setPlayerWantedLevel
 
function setPlayerWantedLevel(player, level)
    local stat = setPlayerWantedLevel_(player, level)
    if stat then
        setElementData(player, "WantLvl", level)
    end
    return stat
end
 
local CrM = createMarker(476.7, -1488.7, 19.2, "arrow", 2, 255, 0, 0, 150)
local PoM = createMarker(474.5, -1509, 19.5, "arrow", 2, 0, 0, 255, 150)
local CrDoor = createObject(1508, 4342.5, -1649.2, 26.4)
local PoDoor = createObject(1508, 4253.1, -1652.4, 26.4)
 
createBlip(475.4, -1501.57, 20.5, 32)
 
addEventHandler("onResourceStart", resourceRoot,
function()
    exports ["guimessages"] : outputServer(root, "* Go to the red house!!", 50, 0, 255)
    exports ["guimessages"] : outputServer(root, "Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Police : Enter at Blue Marker!", 0, 50, 255)
    standByMission = setTimer(function()
        moveObject(CrDoor, 3500, 4342.5, -1649.2, 29.4)
        moveObject(PoDoor, 3500, 4253.1, -1652.4, 29.4)
        exports ["guimessages"] : outputServer(root, "Sniper Mission Started!!!", 0, 150, 255)
        setTimer(checkForWinner, 1000, 1, true)
    end, 5*60*1000, 1)
end)
 
function getTimeLeft(Timer)
    if startTheMission == Timer then
        ms = getTimerDetails(Timer) + 300000
    else
        ms = getTimerDetails(Timer)
    end
    local m = math.floor(ms/60000)
    local s = math.floor((ms-m*60000)/1000)
    if m < 10 then m = ""..m end
    if s < 10 then s = ""..s end
    return "("..m.." Min and "..s.." Sec)"
end
 
addCommandHandler("snipertime",
function(player)
    if isTimer(standByMission) then
        exports ["guimessages"] : outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(standByMission), 0, 255, 0)
    elseif isTimer(startTheMission) then
        exports ["guimessages"] : outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(startTheMission),  0, 255, 0)
    else
        exports ["guimessages"] : outputServer(player, "Sniper Mission is in progress now!", 0, 255, 0)
    end
end)
 
local PolicePosition = {
    {7666.8, -914.6, 9.1},
    {7665.4, -909.1, 9.1},
    {7668.6, -904.8, 9.1},
    {7664.7, -897.9, 9.1},
    {7668.9, -894.3, 9.1},
    {7656.9, -895.9, 9.1},
    {7654.1, -904.5, 9.1},
    {7652.6, -914.1, 9.1}
}
 
local PoliceOutPosition = {
    {216.6, 76.57, 1005.2},
    {216.3, 80.5, 1005.2},
    {219.83, 79.8, 1005.2}
}
 
local CriminalPosition = {
    {7998.4, -916.3, 9.1},
    {7993.7, -916.1, 9.1},
    {7994.1, -910.6, 9.1},
    {7994.4, -899.1, 9.1},
    {8001.2, -899.2, 9.1},
    {8004.9, -906.1, 9.1},
    {8010.5, -915.2, 9.1}
}
 
local CriminalOutPosition = {
    {486.5, -1492.6, 20.2},
    {487.2, -1474.7, 19.2},
    {492.6, -1469.85, 18.55},
    {489.4, -1464.85, 18.3},
    {487.1, -1503.9, 20.4},
    {483.1, -1515.1, 20.3},
    {489.4, -1526.2, 19.77},
    {485.1, -1534.1, 19.4}
}
 
 
addEventHandler("onMarkerHit", root,
function(player)
    if getElementType(player) == "player" and not isPedInVehicle(player) then
        if isTimer(standByMission) then
            if source == CrM and getPlayerTeam(player) ~= getTeamFromName("Police") then
                local x, y, z = unpack(CriminalPosition[math.random(#CriminalPosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, CrTable)
            elseif source == PoM and getPlayerTeam(player) == getTeamFromName("Police") then
                local x, y, z = unpack(PolicePosition[math.random(#PolicePosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, PoTable)
            end
        end
    end
end)
 
TopKill = {}
 
function sortTop()
    sortedTopKill = {}
    for a, b in pairs(TopKill) do
        table.insert(sortedTopKill, {getPlayerName(a), b})
    end
    table.sort(sortedTopKill, function(a,b) return a[2] > b[2] end)
end
 
addEventHandler("onPlayerWasted", root,
function(_, killer)
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if killer and getElementType(killer) == "player" then
            exports ["guimessages"] : outputServer(root, getPlayerName(killer).." Killed "..getPlayerName(source).." in Sniper Mission!", 255, 0, 255)
            TopKill[killer] = (TopKill[killer] or 0) + 1
        else
            exports ["guimessages"] : outputServer(root, getPlayerName(source).." dead in Sniper Mission!", 255, 0, 255)
        end
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
addEventHandler("onPlayerQuit", root,
function()
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
function checkForWinner(cHk)
    if cHk then
        TopKill = {}
    end
    if not isTimer(standByMission) and not isTimer(startTheMission) then
        if #CrTable > 0 and #PoTable == 0 then
            if not cHk then
                exports ["guimessages"] : outputServer(root ,"The Criminals won the Sniper Mission!", 255, 100, 0)
                exports ["guimessages"] : outputServer(root ,"--| Top Kills of Sniper Mission |--", 255, 255, 0)
                sortTop()
                if sortedTopKill[1] then exports ["guimessages"] : outputServer(root ,"1. "..sortedTopKill[1][1]..": "..sortedTopKill[1][2], 255, 0, 255) end
                if sortedTopKill[2] then exports ["guimessages"] : outputServer(root ,"2. "..sortedTopKill[2][1]..": "..sortedTopKill[2][2], 255, 0, 255) end
                if sortedTopKill[3] then exports ["guimessages"] : outputServer(root ,"3. "..sortedTopKill[3][1]..": "..sortedTopKill[3][2], 255, 0, 255) end
            else
                exports ["guimessages"] : outputServer(root ,"The Sniper Mission was Draw!", 255, 0, 0)
            end
            for _, p in ipairs (CrTable) do
                textDisplayRemoveObserver(Display, p)
                if not cHk then
                    setElementData(player, "Money", (getElementData(player, "Money") + 30000 )
                    )
                local x, y, z = unpack(CriminalOutPosition[math.random(#CriminalOutPosition)])
                setElementPosition(p, x, y, z)
                setElementData(p, "MissionProtection", false)
            CrTable = {}
            PoTable = {}
            updateText()
            startTheMission = setTimer(function()
                    exports ["guimessages"] : outputServer(root ,"* Go to the red house!!", 50, 0, 255)
    exports ["guimessages"] : outputServer(root ,"Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports ["guimessages"] : outputServer(root ,"*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports ["guimessages"] : outputServer(root ,"*For Police : Enter at Blue Marker!", 0, 50, 255)
                moveObject(CrDoor, 3500, 4342.5, -1649.2, 26.4)
                moveObject(PoDoor, 3500, 4253.1, -1652.4, 26.4)
                standByMission = setTimer(function()
                   
Link to comment
local Display = textCreateDisplay() 
local CrText = textCreateTextItem("0 Criminal", 0.05, 0.65, "high", 255, 0, 0, 255, 1.2, "center", "center", 255)
local VsText = textCreateTextItem("Vs", 0.1, 0.65, "high", 255, 255, 255, 255, 1.2, "center", "center", 255)
local PoText = textCreateTextItem("0 Police", 0.15, 0.65, "high", 0, 0, 255, 255, 1.2, "center", "center", 255)
textDisplayAddText(Display, CrText)
textDisplayAddText(Display, VsText)
textDisplayAddText(Display, PoText)
 
CrTable = {}
PoTable = {}
 
function updateText()
    textItemSetText(CrText, #CrTable.." Criminal")
    textItemSetText(PoText, #PoTable.." Police")
end
 
function AddPlayer(player, Table)
    if not getPlayerTable(player, CrTable) and not getPlayerTable(player, PoTable) then
        textDisplayAddObserver(Display, player)
        table.insert(Table, player)
        setElementData(player, "MissionProtection", true)
        if Table == CrTable then
            setPlayerWantedLevel(player, 6)
        end
        updateText()
    end
end
   
function RemovePlayer(player, Table)
    textDisplayRemoveObserver(Display, player)
    for i, v in ipairs (Table) do
        if (v == player) then
            table.remove(Table, i)
            setElementData(player, "MissionProtection", false)
        end
    end
    updateText()
end
 
function getPlayerTable(player, Table)
    for i, v in ipairs (Table) do
        if (v == player) then
            return true
        end
    end
end
 
addEventHandler("onElementDataChange", root,
function(dataName)
    if dataName == "LegalStatus" and (getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable)) then
        local LegalStatus = getElementData(source, dataName)
        if LegalStatus == "Jailed" then
            if getPlayerTeam(source) ~= getTeamFromName("Police") then
                RemovePlayer(source, CrTable)
            elseif getPlayerTeam(source) == getTeamFromName("Police") then
                RemovePlayer(source, PoTable)
            end
            checkForWinner()
        end
    end
end)
 
setPlayerWantedLevel_ = setPlayerWantedLevel
 
function setPlayerWantedLevel(player, level)
    local stat = setPlayerWantedLevel_(player, level)
    if stat then
        setElementData(player, "WantLvl", level)
    end
    return stat
end
 
local CrM = createMarker(476.7, -1488.7, 19.2, "cylinder", 2, 255, 0, 0, 150)
local PoM = createMarker(474.5, -1509, 19.5, "cylinder", 2, 0, 0, 255, 150)
local CrDoor = createObject(1508, 4342.5, -1649.2, 26.4)
local PoDoor = createObject(1508, 4253.1, -1652.4, 26.4)
 
createBlip(475.4, -1501.57, 20.5, 32)
 
addEventHandler("onResourceStart", resourceRoot,
function()
    exports ["guimessages"] : outputServer(root, "* Go to the red house!!", 50, 0, 255)
    exports ["guimessages"] : outputServer(root, "Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Police : Enter at Blue Marker!", 0, 50, 255)
    standByMission = setTimer(function()
        moveObject(CrDoor, 3500, 4342.5, -1649.2, 29.4)
        moveObject(PoDoor, 3500, 4253.1, -1652.4, 29.4)
        exports ["guimessages"] : outputServer(root, "Sniper Mission Started!!!", 0, 150, 255)
        setTimer(checkForWinner, 1000, 1, true)
    end, 5*60*1000, 1)
end)
 
function getTimeLeft(Timer)
    if startTheMission == Timer then
        ms = getTimerDetails(Timer) + 300000
    else
        ms = getTimerDetails(Timer)
    end
    local m = math.floor(ms/60000)
    local s = math.floor((ms-m*60000)/1000)
    if m < 10 then m = ""..m end
    if s < 10 then s = ""..s end
    return "("..m.." Min and "..s.." Sec)"
end
 
addCommandHandler("snipertime",
function(player)
    if isTimer(standByMission) then
        exports.guimessages:outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(standByMission), 0, 255, 0)
    elseif isTimer(startTheMission) then
        exports.guimessages:outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(startTheMission), 0, 255, 0)
    else
        exports.guimessages:outputServer(player, "Sniper Mission is in progress now!", 0, 255, 0)
    end
end)
 
local PolicePosition = {
    {4233.3, -1644.6, 25.8},
    {4233.1, -1653.1, 25.8},
    {4232.8, -1662.4, 25.8},
    {4239.1, -1666.2, 25.8},
    {4239.8, -1655.7, 25.8},
    {4241.1, -1645.6, 25.8},
    {4244.3, -1653.9, 25.8},
    {4246.3, -1665.9, 25.8},
    {4240.6, -1655.5, 25.8}
}
 
local PoliceOutPosition = {
    {216.6, 76.57, 1005.2},
    {216.3, 80.5, 1005.2},
    {219.83, 79.8, 1005.2}
}
 
local CriminalPosition = {
    {4364.8, -1657.7, 25.8},
    {4364.3, -1648.5, 25.8},
    {4362.5, -1637.6, 25.8},
    {4357.4, -1637.4, 25.8},
    {4356.8, -1646.3, 25.8},
    {4354.4, -1656.1, 25.8},
    {4348.2, -1657.5, 25.8},
    {4347.4, -1647.1, 25.8},
    {4348.1, -1636.9, 25.8}
}
 
local CriminalOutPosition = {
    {486.5, -1492.6, 20.2},
    {487.2, -1474.7, 19.2},
    {492.6, -1469.85, 18.55},
    {489.4, -1464.85, 18.3},
    {487.1, -1503.9, 20.4},
    {483.1, -1515.1, 20.3},
    {489.4, -1526.2, 19.77},
    {485.1, -1534.1, 19.4}
}
 
addEventHandler("onMarkerHit", root,
function(player)
    if getElementType(player) == "player" and not isPedInVehicle(player) then
        if isTimer(standByMission) then
            if source == CrM and getPlayerTeam(player) ~= getTeamFromName("Police") then
                local x, y, z = unpack(CriminalPosition[math.random(#CriminalPosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, CrTable)
            elseif source == PoM and getPlayerTeam(player) == getTeamFromName("Police") then
                local x, y, z = unpack(PolicePosition[math.random(#PolicePosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, PoTable)
            end
        end
    end
end)
 
TopKill = {}
 
function sortTop()
    sortedTopKill = {}
    for a, b in pairs(TopKill) do
        table.insert(sortedTopKill, {getPlayerName(a), b})
    end
    table.sort(sortedTopKill, function(a,b) return a[2] > b[2] end)
end
 
addEventHandler("onPlayerWasted", root,
function(_, killer)
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if killer and getElementType(killer) == "player" then
            exports.guimessages:outputServer(root, getPlayerName(killer).." Killed "..getPlayerName(source).." in Sniper Mission!", 255, 0, 255)
            TopKill[killer] = (TopKill[killer] or 0) + 1
        else
            exports.guimessages:outputServer(root, getPlayerName(source).." dead in Sniper Mission!", 255, 0, 255)
        end
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
addEventHandler("onPlayerQuit", root,
function()
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
function checkForWinner(cHk)
    if cHk then
        TopKill = {}
    end
    if not isTimer(standByMission) and not isTimer(startTheMission) then
        if #CrTable > 0 and #PoTable == 0 then
            if not cHk then
                exports.guimessages:outputServer(root, "The Criminals won the Sniper Mission!", 255, 100, 0)
                exports.guimessages:outputServer(root, "--| Top Kills of Sniper Mission |--", 255, 255, 0)
                sortTop()
                if sortedTopKill[1] then exports.guimessages:outputServer(root, "1. "..sortedTopKill[1][1]..": "..sortedTopKill[1][2], 255, 0, 255) end
                if sortedTopKill[2] then exports.guimessages:outputServer(root, "2. "..sortedTopKill[2][1]..": "..sortedTopKill[2][2], 255, 0, 255) end
                if sortedTopKill[3] then exports.guimessages:outputServer(root, "3. "..sortedTopKill[3][1]..": "..sortedTopKill[3][2], 255, 0, 255) end
            else
                exports.guimessages:outputServer(root, "The Sniper Mission was Draw!", 255, 0, 0)
            end
            for _, p in ipairs (CrTable) do
                textDisplayRemoveObserver(Display, p)
                if not cHk then
                setElementData(player, "Money", (getElementData(player, "Money") + 30000 ))
                end
                local x, y, z = unpack(CriminalOutPosition[math.random(#CriminalOutPosition)])
                setElementPosition(p, x, y, z)
                setElementData(p, "MissionProtection", false)
            end
            CrTable = {}
            PoTable = {}
            updateText()
            startTheMission = setTimer(function()
                    exports.guimessages:outputServer(root, "* Go to the red house!!", 50, 0, 255)
    exports.guimessages:outputServer(root, "Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports.guimessages:outputServer(root, "*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports.guimessages:outputServer(root, "*For Police : Enter at Blue Marker!", 0, 50, 255)
                moveObject(CrDoor, 3500, 4342.5, -1649.2, 26.4)
                moveObject(PoDoor, 3500, 4253.1, -1652.4, 26.4)
                standByMission =
Link to comment

جرب

local Display = textCreateDisplay() 
local CrText = textCreateTextItem("0 Criminal", 0.05, 0.65, "high", 255, 0, 0, 255, 1.2, "center", "center", 255)
local VsText = textCreateTextItem("Vs", 0.1, 0.65, "high", 255, 255, 255, 255, 1.2, "center", "center", 255)
local PoText = textCreateTextItem("0 Police", 0.15, 0.65, "high", 0, 0, 255, 255, 1.2, "center", "center", 255)
textDisplayAddText(Display, CrText)
textDisplayAddText(Display, VsText)
textDisplayAddText(Display, PoText)
 
CrTable = {}
PoTable = {}
 
function updateText()
    textItemSetText(CrText, #CrTable.." Criminal")
    textItemSetText(PoText, #PoTable.." Police")
end
 
function AddPlayer(player, Table)
    if not getPlayerTable(player, CrTable) and not getPlayerTable(player, PoTable) then
        textDisplayAddObserver(Display, player)
        table.insert(Table, player)
        setElementData(player, "MissionProtection", true)
        if Table == CrTable then
            setPlayerWantedLevel(player, 6)
        end
        updateText()
    end
end
   
function RemovePlayer(player, Table)
    textDisplayRemoveObserver(Display, player)
    for i, v in ipairs (Table) do
        if (v == player) then
            table.remove(Table, i)
            setElementData(player, "MissionProtection", false)
        end
    end
    updateText()
end
 
function getPlayerTable(player, Table)
    for i, v in ipairs (Table) do
        if (v == player) then
            return true
        end
    end
end
 
addEventHandler("onElementDataChange", root,
function(dataName)
    if dataName == "LegalStatus" and (getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable)) then
        local LegalStatus = getElementData(source, dataName)
        if LegalStatus == "Jailed" then
            if getPlayerTeam(source) ~= getTeamFromName("Police") then
                RemovePlayer(source, CrTable)
            elseif getPlayerTeam(source) == getTeamFromName("Police") then
                RemovePlayer(source, PoTable)
            end
            checkForWinner()
        end
    end
end)
 
setPlayerWantedLevel_ = setPlayerWantedLevel
 
function setPlayerWantedLevel(player, level)
    local stat = setPlayerWantedLevel_(player, level)
    if stat then
        setElementData(player, "WantLvl", level)
    end
    return stat
end
 
local CrM = createMarker(476.7, -1488.7, 19.2, "cylinder", 2, 255, 0, 0, 150)
local PoM = createMarker(474.5, -1509, 19.5, "cylinder", 2, 0, 0, 255, 150)
local CrDoor = createObject(1508, 4342.5, -1649.2, 26.4)
local PoDoor = createObject(1508, 4253.1, -1652.4, 26.4)
 
createBlip(475.4, -1501.57, 20.5, 32)
 
addEventHandler("onResourceStart", resourceRoot,
function()
    exports ["guimessages"] : outputServer(root, "* Go to the red house!!", 50, 0, 255)
    exports ["guimessages"] : outputServer(root, "Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Police : Enter at Blue Marker!", 0, 50, 255)
    standByMission = setTimer(function()
        moveObject(CrDoor, 3500, 4342.5, -1649.2, 29.4)
        moveObject(PoDoor, 3500, 4253.1, -1652.4, 29.4)
        exports ["guimessages"] : outputServer(root, "Sniper Mission Started!!!", 0, 150, 255)
        setTimer(checkForWinner, 1000, 1, true)
    end, 5*60*1000, 1)
end)
 
function getTimeLeft(Timer)
    if startTheMission == Timer then
        ms = getTimerDetails(Timer) + 300000
    else
        ms = getTimerDetails(Timer)
    end
    local m = math.floor(ms/60000)
    local s = math.floor((ms-m*60000)/1000)
    if m < 10 then m = ""..m end
    if s < 10 then s = ""..s end
    return "("..m.." Min and "..s.." Sec)"
end
 
addCommandHandler("snipertime",
function(player)
    if isTimer(standByMission) then
        exports.guimessages:outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(standByMission), 0, 255, 0)
    elseif isTimer(startTheMission) then
        exports.guimessages:outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(startTheMission), 0, 255, 0)
    else
        exports.guimessages:outputServer(player, "Sniper Mission is in progress now!", 0, 255, 0)
    end
end)
 
local PolicePosition = {
    {4233.3, -1644.6, 25.8},
    {4233.1, -1653.1, 25.8},
    {4232.8, -1662.4, 25.8},
    {4239.1, -1666.2, 25.8},
    {4239.8, -1655.7, 25.8},
    {4241.1, -1645.6, 25.8},
    {4244.3, -1653.9, 25.8},
    {4246.3, -1665.9, 25.8},
    {4240.6, -1655.5, 25.8}
}
 
local PoliceOutPosition = {
    {216.6, 76.57, 1005.2},
    {216.3, 80.5, 1005.2},
    {219.83, 79.8, 1005.2}
}
 
local CriminalPosition = {
    {4364.8, -1657.7, 25.8},
    {4364.3, -1648.5, 25.8},
    {4362.5, -1637.6, 25.8},
    {4357.4, -1637.4, 25.8},
    {4356.8, -1646.3, 25.8},
    {4354.4, -1656.1, 25.8},
    {4348.2, -1657.5, 25.8},
    {4347.4, -1647.1, 25.8},
    {4348.1, -1636.9, 25.8}
}
 
local CriminalOutPosition = {
    {486.5, -1492.6, 20.2},
    {487.2, -1474.7, 19.2},
    {492.6, -1469.85, 18.55},
    {489.4, -1464.85, 18.3},
    {487.1, -1503.9, 20.4},
    {483.1, -1515.1, 20.3},
    {489.4, -1526.2, 19.77},
    {485.1, -1534.1, 19.4}
}
 
addEventHandler("onMarkerHit", root,
function(player)
    if getElementType(player) == "player" and not isPedInVehicle(player) then
        if isTimer(standByMission) then
            if source == CrM and getPlayerTeam(player) ~= getTeamFromName("Police") then
                local x, y, z = unpack(CriminalPosition[math.random(#CriminalPosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, CrTable)
            elseif source == PoM and getPlayerTeam(player) == getTeamFromName("Police") then
                local x, y, z = unpack(PolicePosition[math.random(#PolicePosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, PoTable)
            end
        end
    end
end)
 
TopKill = {}
 
function sortTop()
    sortedTopKill = {}
    for a, b in pairs(TopKill) do
        table.insert(sortedTopKill, {getPlayerName(a), b})
    end
    table.sort(sortedTopKill, function(a,b) return a[2] > b[2] end)
end
 
addEventHandler("onPlayerWasted", root,
function(_, killer)
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if killer and getElementType(killer) == "player" then
            exports.guimessages:outputServer(root, getPlayerName(killer).." Killed "..getPlayerName(source).." in Sniper Mission!", 255, 0, 255)
            TopKill[killer] = (TopKill[killer] or 0) + 1
        else
            exports.guimessages:outputServer(root, getPlayerName(source).." dead in Sniper Mission!", 255, 0, 255)
        end
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
addEventHandler("onPlayerQuit", root,
function()
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
function checkForWinner(cHk)
    if cHk then
        TopKill = {}
    end
    if not isTimer(standByMission) and not isTimer(startTheMission) then
        if #CrTable > 0 and #PoTable == 0 then
            if not cHk then
                exports.guimessages:outputServer(root, "The Criminals won the Sniper Mission!", 255, 100, 0)
                exports.guimessages:outputServer(root, "--| Top Kills of Sniper Mission |--", 255, 255, 0)
                sortTop()
                if sortedTopKill[1] then exports.guimessages:outputServer(root, "1. "..sortedTopKill[1][1]..": "..sortedTopKill[1][2], 255, 0, 255) end
                if sortedTopKill[2] then exports.guimessages:outputServer(root, "2. "..sortedTopKill[2][1]..": "..sortedTopKill[2][2], 255, 0, 255) end
                if sortedTopKill[3] then exports.guimessages:outputServer(root, "3. "..sortedTopKill[3][1]..": "..sortedTopKill[3][2], 255, 0, 255) end
            else
                exports.guimessages:outputServer(root, "The Sniper Mission was Draw!", 255, 0, 0)
            end
            for _, p in ipairs (CrTable) do
                textDisplayRemoveObserver(Display, p)
                if not cHk then
                setElementData(player, "Money", (getElementData(player, "Money") + 30000 ))
                end
                local x, y, z = unpack(CriminalOutPosition[math.random(#CriminalOutPosition)])
                setElementPosition(p, x, y, z)
                setElementData(p, "MissionProtection", false)
            end
            CrTable = {}
            PoTable = {}
            updateText()
            startTheMission = setTimer(function()
                    exports.guimessages:outputServer(root, "* Go to the red house!!", 50, 0, 255)
    exports.guimessages:outputServer(root, "Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports.guimessages:outputServer(root, "*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports.guimessages:outputServer(root, "*For Police : Enter at Blue Marker!", 0, 50, 255)
                moveObject(CrDoor, 3500, 4342.5, -1649.2, 26.4)
                moveObject(PoDoor, 3500, 4253.1, -1652.4, 26.4)
                standByMission =
Link to comment
local Display = textCreateDisplay() 
local CrText = textCreateTextItem("0 Criminal", 0.05, 0.65, "high", 255, 0, 0, 255, 1.2, "center", "center", 255)
local VsText = textCreateTextItem("Vs", 0.1, 0.65, "high", 255, 255, 255, 255, 1.2, "center", "center", 255)
local PoText = textCreateTextItem("0 Police", 0.15, 0.65, "high", 0, 0, 255, 255, 1.2, "center", "center", 255)
textDisplayAddText(Display, CrText)
textDisplayAddText(Display, VsText)
textDisplayAddText(Display, PoText)
 
CrTable = {}
PoTable = {}
 
function updateText()
    textItemSetText(CrText, #CrTable.." Criminal")
    textItemSetText(PoText, #PoTable.." Police")
end
 
function AddPlayer(player, Table)
    if not getPlayerTable(player, CrTable) and not getPlayerTable(player, PoTable) then
        textDisplayAddObserver(Display, player)
        table.insert(Table, player)
        setElementData(player, "MissionProtection", true)
        if Table == CrTable then
            setPlayerWantedLevel(player, 6)
        end
        updateText()
    end
end
   
function RemovePlayer(player, Table)
    textDisplayRemoveObserver(Display, player)
    for i, v in ipairs (Table) do
        if (v == player) then
            table.remove(Table, i)
            setElementData(player, "MissionProtection", false)
        end
    end
    updateText()
end
 
function getPlayerTable(player, Table)
    for i, v in ipairs (Table) do
        if (v == player) then
            return true
        end
    end
end
 
addEventHandler("onElementDataChange", root,
function(dataName)
    if dataName == "LegalStatus" and (getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable)) then
        local LegalStatus = getElementData(source, dataName)
        if LegalStatus == "Jailed" then
            if getPlayerTeam(source) ~= getTeamFromName("Police") then
                RemovePlayer(source, CrTable)
            elseif getPlayerTeam(source) == getTeamFromName("Police") then
                RemovePlayer(source, PoTable)
            end
            checkForWinner()
        end
    end
end)
 
setPlayerWantedLevel_ = setPlayerWantedLevel
 
function setPlayerWantedLevel(player, level)
    local stat = setPlayerWantedLevel_(player, level)
    if stat then
        setElementData(player, "WantLvl", level)
    end
    return stat
end
 
local CrM = createMarker(476.7, -1488.7, 19.2, "cylinder", 2, 255, 0, 0, 150)
local PoM = createMarker(474.5, -1509, 19.5, "cylinder", 2, 0, 0, 255, 150)
local CrDoor = createObject(1508, 4342.5, -1649.2, 26.4)
local PoDoor = createObject(1508, 4253.1, -1652.4, 26.4)
 
createBlip(475.4, -1501.57, 20.5, 32)
 
addEventHandler("onResourceStart", resourceRoot,
function()
    exports ["guimessages"] : outputServer(root, "* Go to the red house!!", 50, 0, 255)
    exports ["guimessages"] : outputServer(root, "Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports ["guimessages"] : outputServer(root, "*For Police : Enter at Blue Marker!", 0, 50, 255)
    standByMission = setTimer(function()
        moveObject(CrDoor, 3500, 4342.5, -1649.2, 29.4)
        moveObject(PoDoor, 3500, 4253.1, -1652.4, 29.4)
        exports ["guimessages"] : outputServer(root, "Sniper Mission Started!!!", 0, 150, 255)
        setTimer(checkForWinner, 1000, 1, true)
    end, 5*60*1000, 1)
end)
 
function getTimeLeft(Timer)
    if startTheMission == Timer then
        ms = getTimerDetails(Timer) + 300000
    else
        ms = getTimerDetails(Timer)
    end
    local m = math.floor(ms/60000)
    local s = math.floor((ms-m*60000)/1000)
    if m < 10 then m = ""..m end
    if s < 10 then s = ""..s end
    return "("..m.." Min and "..s.." Sec)"
end
 
addCommandHandler("snipertime",
function(player)
    if isTimer(standByMission) then
        exports.guimessages:outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(standByMission), 0, 255, 0)
    elseif isTimer(startTheMission) then
        exports.guimessages:outputServer(player, "Time left before Sniper Mission Start: "..getTimeLeft(startTheMission), 0, 255, 0)
    else
        exports.guimessages:outputServer(player, "Sniper Mission is in progress now!", 0, 255, 0)
    end
end)
 
local PolicePosition = {
    {4233.3, -1644.6, 25.8},
    {4233.1, -1653.1, 25.8},
    {4232.8, -1662.4, 25.8},
    {4239.1, -1666.2, 25.8},
    {4239.8, -1655.7, 25.8},
    {4241.1, -1645.6, 25.8},
    {4244.3, -1653.9, 25.8},
    {4246.3, -1665.9, 25.8},
    {4240.6, -1655.5, 25.8}
}
 
local PoliceOutPosition = {
    {216.6, 76.57, 1005.2},
    {216.3, 80.5, 1005.2},
    {219.83, 79.8, 1005.2}
}
 
local CriminalPosition = {
    {4364.8, -1657.7, 25.8},
    {4364.3, -1648.5, 25.8},
    {4362.5, -1637.6, 25.8},
    {4357.4, -1637.4, 25.8},
    {4356.8, -1646.3, 25.8},
    {4354.4, -1656.1, 25.8},
    {4348.2, -1657.5, 25.8},
    {4347.4, -1647.1, 25.8},
    {4348.1, -1636.9, 25.8}
}
 
local CriminalOutPosition = {
    {486.5, -1492.6, 20.2},
    {487.2, -1474.7, 19.2},
    {492.6, -1469.85, 18.55},
    {489.4, -1464.85, 18.3},
    {487.1, -1503.9, 20.4},
    {483.1, -1515.1, 20.3},
    {489.4, -1526.2, 19.77},
    {485.1, -1534.1, 19.4}
}
 
addEventHandler("onMarkerHit", root,
function(player)
    if getElementType(player) == "player" and not isPedInVehicle(player) then
        if isTimer(standByMission) then
            if source == CrM and getPlayerTeam(player) ~= getTeamFromName("Police") then
                local x, y, z = unpack(CriminalPosition[math.random(#CriminalPosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, CrTable)
            elseif source == PoM and getPlayerTeam(player) == getTeamFromName("Police") then
                local x, y, z = unpack(PolicePosition[math.random(#PolicePosition)])
                setElementPosition(player, x, y, z)
                AddPlayer(player, PoTable)
            end
        end
    end
end)
 
TopKill = {}
 
function sortTop()
    sortedTopKill = {}
    for a, b in pairs(TopKill) do
        table.insert(sortedTopKill, {getPlayerName(a), b})
    end
    table.sort(sortedTopKill, function(a,b) return a[2] > b[2] end)
end
 
addEventHandler("onPlayerWasted", root,
function(_, killer)
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if killer and getElementType(killer) == "player" then
            exports.guimessages:outputServer(root, getPlayerName(killer).." Killed "..getPlayerName(source).." in Sniper Mission!", 255, 0, 255)
            TopKill[killer] = (TopKill[killer] or 0) + 1
        else
            exports.guimessages:outputServer(root, getPlayerName(source).." dead in Sniper Mission!", 255, 0, 255)
        end
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
addEventHandler("onPlayerQuit", root,
function()
    if getPlayerTable(source, CrTable) or getPlayerTable(source, PoTable) then
        if getPlayerTeam(source) ~= getTeamFromName("Police") then
            RemovePlayer(source, CrTable)
        elseif getPlayerTeam(source) == getTeamFromName("Police") then
            RemovePlayer(source, PoTable)
        end
    end
    checkForWinner()
end)
 
function checkForWinner(cHk)
    if cHk then
        TopKill = {}
    end
    if not isTimer(standByMission) and not isTimer(startTheMission) then
        if #CrTable > 0 and #PoTable == 0 then
            if not cHk then
                exports.guimessages:outputServer(root, "The Criminals won the Sniper Mission!", 255, 100, 0)
                exports.guimessages:outputServer(root, "--| Top Kills of Sniper Mission |--", 255, 255, 0)
                sortTop()
                if sortedTopKill[1] then exports.guimessages:outputServer(root, "1. "..sortedTopKill[1][1]..": "..sortedTopKill[1][2], 255, 0, 255) end
                if sortedTopKill[2] then exports.guimessages:outputServer(root, "2. "..sortedTopKill[2][1]..": "..sortedTopKill[2][2], 255, 0, 255) end
                if sortedTopKill[3] then exports.guimessages:outputServer(root, "3. "..sortedTopKill[3][1]..": "..sortedTopKill[3][2], 255, 0, 255) end
            else
                exports.guimessages:outputServer(root, "The Sniper Mission was Draw!", 255, 0, 0)
            end
            for _, p in ipairs (CrTable) do
                textDisplayRemoveObserver(Display, p)
                if not cHk then
                setElementData(p, "Money", (getElementData(p, "Money") + 30000 ))
                end
                local x, y, z = unpack(CriminalOutPosition[math.random(#CriminalOutPosition)])
                setElementPosition(p, x, y, z)
                setElementData(p, "MissionProtection", false)
            end
            CrTable = {}
            PoTable = {}
            updateText()
            startTheMission = setTimer(function()
                    exports.guimessages:outputServer(root, "* Go to the red house!!", 50, 0, 255)
    exports.guimessages:outputServer(root, "Sniper Mission will begin after 5 minutes!", 255, 50, 0)
    exports.guimessages:outputServer(root, "*For Gangster : Enter at Red Marker !", 255, 50, 0)
    exports.guimessages:outputServer(root, "*For Police : Enter at Blue Marker!", 0, 50, 255)
                moveObject(CrDoor, 3500, 4342.5, -1649.2, 26.4)
                moveObject(PoDoor, 3500, 4253.1, -1652.4, 26.4)
                standByMission =
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...