Jump to content

TURF


MaRcell

Recommended Posts

 
I created a turf system wit
local TurfsTable = {
  [1] = {rx=2306.26440,ry= 551.96600 ,sx=150,sy=100,bx=2306.26440,by=551.96600,bz=10,bsx=197.5,bsy=92,bheight=30,red=255,green=255,blue=255} 
    
}

function CriarTurf(rx,ry,sx,sy,bx,by,bz,bsx,bsy,bheight,red,green,blue)
    local turf = createRadarArea(rx,ry,sx,sy,red,green,blue)
    local cubo = createColCuboid(bx,by,bz,bsx,bsy,bheight)
    setElementData(cubo,"Turf-area",turf)
    setElementData(cubo,"Turf-team",false)
    setElementData(cubo,"Turf-inAttack",false)
    setElementData(cubo,"Turf-attackedPlayer",false)
    setElementData(cubo,"Turf-time",false)
end

function CriarTodasTurfs()
    for i=1,#TurfsTable do
        local rx,ry,sx,sy,bx,by,bz,bsx,bsy,bheight,red,green,blue = TurfsTable[i].rx,TurfsTable[i].ry,TurfsTable[i].sx,TurfsTable[i].sy,TurfsTable[i].bx,TurfsTable[i].by,TurfsTable[i].bz,TurfsTable[i].bsx,TurfsTable[i].bsy,TurfsTable[i].bheight,TurfsTable[i].red,TurfsTable[i].green,TurfsTable[i].blue
        CriarTurf(rx,ry,sx,sy,bx,by,bz,bsx,bsy,bheight,red,green,blue)
    end
end
CriarTodasTurfs()

function onHit(player)
    local turfArea = getElementData(source,"Turf-area") or false
    if(turfArea==false)then return end
    if(getElementType(player)~="player")then return end
    
    local turfTeam = getElementData(source,"Turf-team") or ""
    local playerTeam = getPlayerTeam(player) or false
    
    if(playerTeam==false)then return outputChatBox("Voce nao tem time pra dominar turf",player) end
    
    if(turfTeam == "")then -- essa turn nao tem dono, o que fazer quando o player entrar nela? 
    -- começa o atk e aparece o timer
    outputChatBox("Espere 5 segundos para dominar essa area vazia, nao sai dela")
    setTimer(timerTurfVazia,5000,1,source,player)
    else -- essa turf tem dono
    if(turfTeam == playerTeam)then -- time amigo
    outputChatBox("Bem vindo a sua turf",player)
    else -- inimigo
    local defensores = getPlayersTeamInArea(turfTeam)
    if(#defensores == 0)then-- nao tem nenhum player defensor na area e agora?
    setTurfInAtack(source,player)
else -- tem 1 ou mais defensores os defensores e os palyers da gang que vai la defender kk
     setTurfInAtack(source,player)
            end
        end
    end
end
addEventHandler('onColShapeHit', root,onHit)

function DominarTurf(turf,player)
    local team = getPlayerTeam(player)
    local area = getElementData(turf,"Turf-area")
    setElementData(turf,"Turf-team",team)
    local r,g,b = getTeamColor(team)
    setRadarAreaColor(area,r,g,b,255)
    outputChatBox("Area dominada pela gang: "..getTeamName(team).." Pelo Jogador: "..getPlayerName(player))
end

function timerTurfVazia(t,p)
     if(isElementWithinColShape(p,t))then 
          DominarTurf(t,p)
      else
         outputChatBox("Voce saiu da turf",p) 
    end
end

function getPlayersTeamInArea(team)
local t = {}
local players = getElementsByType("player")
for k,v in ipairs(players)do
    local te = getPlayerTeam(v)
    if(te and te == team)then 
    table.insert(t,v)
       end
end
return t
end

function setTurfInAtack(turf,atackPlayer)
    local area = getElementData(turf,"Turf-area")
    local turfTeam = getElementData(turf,"Turf-team")
    setElementData(turf,"Turf-inAttack",true)
    setRadarAreaFlashing(area,true)
    
    local playersDefensores = getPlayersInTeam(turfTeam)
    for k,v in ipairs(playersDefensores)do
     outputChatBox("Sua area foi atacada pelo jogador: "..getPlayerName(atackPlayer),v)
    end
    
    local timer = setTimer(atacanteDominarArea,30*1000,1,turf,atackPlayer)
    setElementData(turf,"Turf-time",timer)
end

function atacanteDominarArea(turf,player)
if(isElementWithinColShape(player,turf))then -- se o player atacante permaneceu 30 seg na turf
    DominarTurf(turf,player)
    end
end

function onPlayerWasted(_,killer) -- aki que o bixo pega
  local turfsAtacadas = getAllAtackedTurfs() -- aki tem uma tabela com todas as turfs atacadas
  if(#turfsAtacadas==0)then return end
  for k,v in ipairs(turfsAtacadas) do
  local jogadorAtacante = getElementData(v,"Turf-inAttack")
  local timerTurf = getElementData(v,"Turf-time") 
  if(jogadorAtacante == source and timerTurf and isTimer(timerTurf))then 
  -- jogador atacante morreu
  killTimer(timerTurf)
  setElementData(v,"Turf-inAttack",false) 
  setElementData(v,"Turf-attackedPlayer",false) 
    end
  end
end
addEventHandler("onPlayerWasted",root,onPlayerWasted)

function getAllAtackedTurfs()
local t = {}    
local cubos = getElementsByType("colshape")
for k,v in ipairs(cubos)do
local inAtack = getElementData(v,"Turf-inAttack")
if(inAtack==true)then 
table.insert(t,v)
end
end
end
h a problem when the other gang dominates the turf keeps blinking and does not show that the gang dominated anyone could help me?
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...