Jump to content

Turf System Problem


Axel

Recommended Posts

Hey guys i am making an turfs system, but i got some problems. Here's the code:

 mysql = exports.mysql 
  
addEventHandler( "onResourceStart", getResourceRootElement( ), 
function( ) 
local result = mysql:query("SELECT id, factionid, c1, c2, c3, alpha, x, y, sx, sy FROM turfs") 
    if (result) then 
    local continue = true 
    while continue do 
    row = mysql:fetch_assoc(result) 
    if not (row) then 
       break 
    end 
    local id = tonumber(row["id"])         
    local gang = row["factionid"] 
    local x = tonumber(row["x"])         
    local y = tonumber(row["y"]) 
    local sx = tonumber(row["sx"]) 
    local sy = tonumber(row["sy"])                               
    local c1 = tonumber(row["c1"]) 
    local c2 = tonumber(row["c2"]) 
    local c3 = tonumber(row["c3"])         
    local alpha = tonumber(row["alpha"]) 
    local shape = createColRectangle(x, y, sx, sy) 
    local turf = createRadarArea(x,y,sx,sy,c1,c2,c3,alpha) 
    exports['armour']:changeProtectedElementDataEx(shape, "isShape", "true") 
    exports['armour']:changeProtectedElementDataEx(turf, "isTurf", "true") 
    exports['armour']:changeProtectedElementDataEx(shape, "gang", gang) 
    exports['armour']:changeProtectedElementDataEx(turf, "gang", gang) 
    exports['armour']:changeProtectedElementDataEx(shape, "dbid", id) 
    exports['armour']:changeProtectedElementDataEx(turf, "dbid", id) 
    end 
    mysql:free_result(result) 
    end 
end 
)  
  
addEventHandler( 
    'onColShapeHit', getRootElement(), 
    function( player ) 
        local shapeid = getElementData(source,"dbid") 
        local gang = tonumber(getElementData(source,"gang")) 
            for index, value in ipairs (getElementsByType("team")) do 
                local facid = tonumber(getElementData(value, "id")) 
                if (facid == gang) then 
                    local teamName = getTeamName(value) 
                end 
            end 
        if (getElementType ( player ) == "player") then  
            local faction = tonumber(getElementData(player,"faction")) 
            local team = getPlayerTeam(player) 
            local factionType = getElementData(team,"type") 
            if (getElementType(source) == "colshape") and (getElementData(source,"isShape") == "true") then 
                for i, v in ipairs (getElementsByType("radararea")) do 
                local turfid = getElementData(v,"dbid") 
                    if (turfid == shapeid) then 
                        if (factionType == 0) then               
                            if (gang == faction) then 
                                outputChatBox( "Bine ai revenit in turful gangului '"..teamName.."'!", player, 0, 255, 0, true ); 
                                if (isTimer(turftimer)) then 
                                    killTimer(turftimer) 
                                else 
                                    return 
                                end 
                                for l, o in ipairs (getElementsByType("player")) do 
                                local x, y, z = getElementPosition(o) 
                                    if not (isInsideRadarArea(v, x, y)) then 
                                        if not getPlayerTeam(o) == team then 
                                            recuperaretimer = setTimer ( function() 
                                                local ttt = tonumber(getElementData(v,"timer")) 
                                                setElementData(v,"timer",ttt-1) 
                                                outputChatBox( "Recuperarea turfului a ajuns la '"..ttt.."'!", player, 0, 255, 0, true ); 
                                                if (ttt == 0) then 
                                                    setRadarAreaFlashing( v, false ) 
                                                    if isTimer( recuperaretimer ) then 
                                                        killTimer( recuperaretimer ) 
                                                    end  
                                                    if isTimer( rectimer ) then 
                                                        killTimer( rectimer ) 
                                                    end  
                                                end 
                                            end, 600, 0 ) 
                                        else 
                                            return 
                                            outputChatBox( "Trebuie sã elimini toti inamicii din turf!", player, 0, 255, 0, true ); 
                                        end 
                                    else 
                                        return 
                                        outputChatBox( "Trebuie sã elimini toti inamicii din turf!", player, 0, 255, 0, true ); 
                                    end 
                                end 
                            elseif (gang ~= faction) then 
                                outputChatBox( "Ai intrat pe turful gangului '"..teamName.."'! Va incepe ciordirea turfului!", player, 0, 255, 0, true );                
                                setRadarAreaFlashing( v, true )      
                    turftimer = setTimer ( function() 
                                local tt = getElementData(v,"timer") or 1 
                                exports['armour']:changeProtectedElementDataEx(v, "timer", tt+1) 
                                outputChatBox( "Furtul turfului a ajuns la '"..tt.."'!", player, 0, 255, 0, true ); 
                                    if (tt == 10) then 
                                        local r, g, b = getTeamColor(team) 
                                        local query = mysql:query_free("UPDATE turfs SET factionid = "..faction..", c1 = "..r..", c2 = "..g..", c3 = "..b.." WHERE id = " .. shapeid) 
                                            if (query) then 
                                                setRadarAreaFlashing( v, false ) 
                                                setRadarAreaColor(v,r,g,b,60) 
                                                exports['armour']:changeProtectedElementDataEx(v, "timer", 1) 
                                                for b, n in ipairs(getElementsByType("colshape")) do 
                                                    if ((getElementData(v,"gang") == (getElementData(n,"gang")))) then 
                                                        setElementData(n, "gang", faction) 
                                                        setElementData(v, "gang", faction) 
                                                    end 
                                                end 
                                            end 
                                        outputChatBox( "Ai ciordit turful gangului '"..teamName.."'!", player, 0, 255, 0, true );    
                                        for masa, rasa in ipairs (getElementsByType("player")) do 
                                        local x, y, z = getElementPosition(rasa) 
                                            if (isInsideRadarArea(v, x, y)) then 
                                                if getPlayerTeam(rasa) == team then 
                                                    exports.global:giveMoney(rasa, 1000) 
                                                end 
                                            end 
                                        end 
                                        if (isTimer(turftimer)) then 
                                            killTimer(turftimer) 
                                        end 
                                    end 
                                end, 600, 0) 
                            end 
                        else 
                            outputChatBox( "Ai intrat pe un terenul unui gang! Ai grija sa nu fii atacat!", player, 0, 255, 0, true ); 
                        end 
                    end 
                end 
            end 
        end 
    end 
) 
  
addEventHandler( 
    'onColShapeLeave', getRootElement(),    
    function( player ) 
        local shapeid = tonumber(getElementData(source,"dbid")) 
        local gang = tonumber(getElementData(source,"gang")) 
        if (getElementType ( player ) == "player") then  
            local faction = tonumber(getElementData(player,"faction")) 
            local team = getPlayerTeam(player) 
            local factionType = getElementData(team,"type") 
                        for index, value in ipairs (getElementsByType("team")) do 
                            local factionID = tonumber(getElementData(value, "id")) 
                            if (factionID == gang) then 
                                local teamName = getTeamName(value) 
                            end 
                        end 
            if (factionType == 0) then 
                if (getTeamName(team) ~= teamName) then 
                    if (getElementType(source) == "colshape") and (getElementData(source,"isShape") == "true") then 
                        for i, v in ipairs (getElementsByType("radararea")) do 
                            local radarid = tonumber(getElementData(v,"dbid")) 
                            local radargang = tonumber(getElementData(v,"gang")) 
                            if (shapeid == radarid) then 
                                if (gang ~= radargang) then 
                                    rectimer = setTimer ( function() 
                                        local tt = tonumber(getElementData(v,"timer")) 
                                        setElementData(v,"timer",tt-1) 
                                        outputChatBox( "Recuperarea turfului echipei '"..teamName.."'a ajuns la '"..tt.."'!", player, 0, 255, 0, true ); 
                                        if (tt == 0) then 
                                            setRadarAreaFlashing( v, false ) 
                                            if isTimer( rectimer ) then 
                                                killTimer( rectimer ) 
                                            end  
                                        end 
                                    end, 600, 0 ) 
                                elseif (gang == radargang) then 
                                    setRadarAreaFlashing( v, false ) 
                                    local tt = tonumber(getElementData(v,"timer")) or 0 
                                    outputChatBox( "Te-ai oprit din furtul turfului gangului '"..teamName.."' la '"..tt.."", player, 0, 255, 0, true ); 
                                end 
                            end 
                        end 
                    else 
                        outputChatBox( "Ai ieșit de pe turfului gangului '"..teamName.."'", player, 0, 255, 0, true ); 
                    end 
                end 
            end 
        end 
    end 
) 
  

Anything works fine instead of teamName, it returns a nil value and when i enter the turf and exit i get this 2 errors:

s_gang.lua:92 attempt to concate global 'teamName' (a nil value)

s_gang.lua:174 attempt to concate global 'teamName' (a nil value)

Thanks for help!

Link to comment

That fixed the problem, thanks. But i don't really find a way to make it like: When someone from a team enters it it starts taking the turf, but when more in the same team enters the turf is taken quickly, and when the gang that owns the turf enters it stops and depending on who remains in it is taken or protected. I'm trying to do it with timers but i don't really know how to start, end it. Also i got this problem that timers doesn't stop..

Link to comment

you can divide/subtract the timer time that it takes for 1 person to take the turf, but multiply/add the time when someone from other team goes in the turf. but you can get elements within the colshape and then if its equal you can simply stop the ticking of the timer

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