Jump to content

[HELP] Resource lags all server


joaosilva099

Recommended Posts

Hi community.

I made my own jobs resource for my server but it has a problem.

It works good but passing 5--10min its start it starts consuming about 50% CPU and all player ping gets to about 600ms and i have to restart it and returns all again happening.

Codes are at the end of the post and i hope you can help me

* I checked CPU consumption at server's web page

* I checked ping at default admin panel of the server and at scoreboard

* When the player get 600 ping then returns network trouble message and he has to reconnect.

Codes:

Server-side:

ped = { } 
weapon = { }
function getBlipAttachedTo( thePlayer )
    local blips = getElementsByType( "blip" )
    for k, theBlip in ipairs( blips ) do
        if getElementAttachedTo( theBlip ) == thePlayer then
            return theBlip
        end
    end
    return false
end
addEventHandler("onResourceStart", getRootElement(),
    function()
        ped["Staff"] = createPed(217, 853.7255859375, -2385.216796875, 12.906106948853, 0, false)
        setTimer( setElementHealth, 50, 0, ped["Staff"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Staff"], 853.7255859375, -2385.216796875, 12.906106948853 )
        function job1(mouse, state, player)
            if(mouse == "left" and state == "down") then
                if(isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin"))) then
                r, g, b = getTeamColor(getTeamFromName("Staff"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Staff", "As a Staff Member you need to manage STORM:RPG Players: Attend to their problems/questions and solve the Bugs. You have to Punish the ones that dont follow the Rules!", r, g, b)
                else
                exports.ac_message:outputTopbar(player, 255, 0, 0, "Job: You cannot take this Job!")
                end
            end
        end
        addEventHandler("onElementClicked", ped["Staff"], job1)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Staff", 0xFF390874, 853.7255859375, -2385.216796875, 12.906106948853, 20, 0, "default-bold", 2)
        end)
        --
        ped["Criminal"] = createPed(0, 438.4970703125, -1733.09765625, 9.421875, 0, false)
        createBlipAttachedTo(ped["Criminal"], 59, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Criminal"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Criminal"], 438.4970703125, -1733.09765625, 9.421875 )
        function job2(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Criminal"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Criminal", "As a Criminal you will be the real protagonist of STORM:RPG. Being a Criminal means that you will be aable to: Rob Houes, Rob Stores, Rob Banks, Hack ATM's and much more as you will discove in this new adventure!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Criminal"], job2)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Criminal", 0xFFEB6767, 438.4970703125, -1733.09765625, 9.421875, 20, 0, "default-bold", 2)
         end)
        --
        ped["Trashman"] = createPed(132, -76.7373046875, -1136.515625, 1.078125, 50.0, false)
        createBlipAttachedTo(ped["Trashman"], 60, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Trashman"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Trashman"], -76.7373046875, -1136.515625, 1.078125 )
        function job3(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Trashman"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Trashman", "As a TrashMan you need to go arround SA to catch some trash bags that will be bliped into your radar!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Trashman"], job3)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Trashman", 0xFFFFFF00, -76.7373046875, -1136.515625, 1.078125, 20, 0, "default-bold", 2)
         end)
        --
        ped["Police"] = createPed(280, 1553.033203125, -1677.6357421875, 16.1953125, 0, false)
        weapon["Police"] = 3
        createBlipAttachedTo(ped["Police"], 61, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Police"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Police"], 1553.033203125, -1677.6357421875, 16.1953125 )
        function job4(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Police"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Police", "As a Police man you need to drive around San Andreas to catch Wanted Criminals. You will level up by ammount of Arrests you have!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Police"], job4)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Police", 0xFF2572FF, 1553.033203125, -1677.6357421875, 16.1953125, 20, 0, "default-bold", 2)
         end)
        --
        ped["TrafficUnit"] = createPed(284, 1582.0888671875, -1683.302734375, 6.21875, 0, false)
        weapon["TrafficUnit"] = 43
        createBlipAttachedTo(ped["TrafficUnit"], 61, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["TrafficUnit"], 100 )
        setTimer( setElementPosition, 50, 0, ped["TrafficUnit"], 1582.0888671875, -1683.302734375, 6.21875 )
        function job5(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("TrafficUnit"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "TrafficUnit", "As a Traffic Unit you need to catch the Speeders of STORM:RPG!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["TrafficUnit"], job5)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("TrafficUnit", 0xFF2572FF, 1582.0888671875, -1683.302734375, 6.21875, 20, 0, "default-bold", 2)
         end)
        --
        ped["Criminal1"] = createPed(0, 1632.458984375, -1521.83984375, 13.609195709229, 180, false)
        createBlipAttachedTo(ped["Criminal1"], 59, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Criminal1"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Criminal1"], 1632.458984375, -1521.83984375, 13.609195709229 )
        function job6(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Criminal"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Criminal", "As a Criminal you will be the real protagonist of STORM:RPG. Being a Criminal means that you will be aable to: Rob Houes, Rob Stores, Rob Banks, Hack ATM's and much more as you will discove in this new adventure!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Criminal1"], job6)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Criminal", 0xFFEB6767, 1632.458984375, -1521.83984375, 13.609195709229, 20, 0, "default-bold", 2)
         end)
        --
        ped["Pilot"] = createPed(255, 2122.1162109375, -2412.15234375, 13.546875, 180.0, false)
        createBlipAttachedTo(ped["Pilot"], 60, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Pilot"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Pilot"], 2122.1162109375, -2412.15234375, 13.546875 )
        function job7(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Pilot"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Pilot", "As a Pilot you must drive the people to their selected destination!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Pilot"], job7)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Pilot", 0xFFFFFF00, 2122.1162109375, -2412.15234375, 13.5468755, 20, 0, "default-bold", 2)
         end)
        --
        ped["Criminal2"] = createPed(0, 2434.25, -2056.2509765625, 13.549994468689, 90, false)
        createBlipAttachedTo(ped["Criminal2"], 59, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Criminal2"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Criminal2"], 2434.25, -2056.2509765625, 13.549994468689 )
        function job8(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Criminal"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Criminal", "As a Criminal you will be the real protagonist of STORM:RPG. Being a Criminal means that you will be aable to: Rob Houes, Rob Stores, Rob Banks, Hack ATM's and much more as you will discove in this new adventure!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Criminal2"], job8)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Criminal", 0xFFEB6767, 2434.25, -2056.2509765625, 13.549994468689, 20, 0, "default-bold", 2)
         end)
        --
        ped["Hobo"] = createPed(239, 2438.427734375, -1885.396484375, 13.553356170654, 270.0, false)
        createBlipAttachedTo(ped["Hobo"], 60, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Hobo"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Hobo"], 2438.427734375, -1885.396484375, 13.553356170654 )
        function job9(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Hobo"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Hobo", "As a Hobo you dont need to do nothing... just walk forthere searching food and money!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Hobo"], job9)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Hobo", 0xFFFFFF00, 2438.427734375, -1885.396484375, 13.553356170654, 20, 0, "default-bold", 2)
         end)
        --
        ped["Medic"] = createPed(275, 2035.73828125, -1401.685546875, 17.309717178345, 180.0, false)
        weapon["Medic"] = 14
        createBlipAttachedTo(ped["Medic"], 60, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Medic"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Medic"], 2035.73828125, -1401.685546875, 17.309717178345 )
        function job10(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Medic"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Medic", "As a Medic you will get Flower that you should hit player with it so they take health!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Medic"], job10)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Medic", 0xFF00FFFF, 2035.73828125, -1401.685546875, 17.309717178345, 20, 0, "default-bold", 2)
         end)
        --
        ped["Medic1"] = createPed(275, 1173.220703125, -1312.7294921875, 13.983285903931, 270.0, false)
        createBlipAttachedTo(ped["Medic1"], 60, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Medic1"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Medic1"], 1173.220703125, -1312.7294921875, 13.983285903931 )
        function job11(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Medic"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Medic", "As a Medic you will get Flower that you should hit player with it so they take health!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Medic1"], job11)
         addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Medic", 0xFF00FFFF, 1173.220703125, -1312.7294921875, 13.983285903931, 20, 0, "default-bold", 2)
         end)
        --
        ped["Taxi"] = createPed(220, 1624.8583984375, -1137.515625, 23.90625, 0.0, false)
        createBlipAttachedTo(ped["Taxi"], 60, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Taxi"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Taxi"], 1624.8583984375, -1137.515625, 23.90625 )
        function job12(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Taxi"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Taxi", "As a Taxist you need to drive arround SA with your taxi finding people to transport and then transport them to selected destination!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Taxi"], job12)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Taxi", 0xFFFFFF00, 1624.8583984375, -1137.515625, 23.90625, 20, 0, "default-bold", 2)
         end)
        --
        ped["Trucker"] = createPed(125, 123.326171875, -296.8349609375, 1.578125, 90.0, false)
        createBlipAttachedTo(ped["Trucker"], 60, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Trucker"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Trucker"], 123.326171875, -296.8349609375, 1.578125 )
        function job13(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Trucker"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Trucker", "As a Trucker you need to deliver charges to the selected destination!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Trucker"], job13)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Trucker", 0xFFFFFF00, 123.326171875, -296.8349609375, 1.578125, 20, 0, "default-bold", 2)
         end)
        --
        ped["PizzaDelivery"] = createPed(155, 2105.4541015625, -1808.9091796875, 13.5546875, 90.0, false)
        createBlipAttachedTo(ped["PizzaDelivery"], 60, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["PizzaDelivery"], 100 )
        setTimer( setElementPosition, 50, 0, ped["PizzaDelivery"], 2105.4541015625, -1808.9091796875, 13.5546875 )
        function job14(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("PizzaDelivery"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "PizzaDelivery", "As a Pizza Delivery man you need to deliver the pizza's to the indicaded location in the map (blip)!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["PizzaDelivery"], job14)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("PizzaDelivery", 0xFFFFFF00, 2105.4541015625, -1808.9091796875, 13.5546875, 20, 0, "default-bold", 2)
         end)
        --
        ped["Mechanic"] = createPed(50, 1035.291015625, -1024.533203125, 32.1015625, 180.0, false)
        createBlipAttachedTo(ped["Mechanic"], 60, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Mechanic"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Mechanic"], 1035.291015625, -1024.533203125, 32.1015625 )
        function job15(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b = getTeamColor(getTeamFromName("Mechanic"))
                triggerClientEvent(player, "PedClicked", getRootElement(), "Mechanic", "As a Mechanic you have to drive arround SA and find people that needs repairing on their cars. You have to drive Towtruck too and find broken vehicles and take them to the delivery point!", r, g, b)
            end
        end
        addEventHandler("onElementClicked", ped["Mechanic"], job15)
        addEventHandler("onPlayerLogin", getRootElement(), function()
        exports.TextLabel:create3DTextLabel("Mechanic", 0xFFFFFF00, 1035.291015625, -1024.533203125, 32.1015625, 20, 0, "default-bold", 2)
         end)
        -- LV JOBS
        ped["Medic2"] = createPed(275, 1612.2548828125, 1815.2421875, 10.8203125, 0.0, false)
        createBlipAttachedTo(ped["Medic2"], 60, 2, 0, 0, 0, 0, 0, 200)
        setTimer( setElementHealth, 50, 0, ped["Medic2"], 100 )
        setTimer( setElementPosition, 50, 0, ped["Medic2"], 1612.2548828125, 1815.2421875, 10.8203125 )
        function job16(mouse, state, player)
            if(mouse == "left" and state == "down") then
                r, g, b =
  • Like 1
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...