Jump to content

HELP - ColShape not detecting team


Backsage

Recommended Posts

Hi guys. I need some help. I have a script here and I've created a colshape for an arena of some sort. It's below the ground, so if you want to test it, you'll need to change the coordinates of the colshape and the spawn positions, or just create some ground objects. In the script, I have created some teams and I'm trying to make it so that if you're not in "Duel Team 1", then it spawns you outside the colshape. Otherwise, if you are in "Duel Team 1", then you should be allowed in the colshape. The problem with the script is that it's not detecting if I'm actually in the team, so even though I'm in "Duel Team 1", it still spawns me outside the colshape. If you could help me, that'd be great. :D

  
local colshape = createColCuboid(950.19, 1566.74, -23.13, 53.2, 53, 8.7) 
  
function Arena_Enter ( thePlayer, matchingDimension ) 
        if getElementType ( thePlayer ) == "player" then --if the element that entered was player 
                --let's get the name of the player 
                local nameOfThePlayer = getPlayerName ( thePlayer ) 
            --announce to everyone that the player entered the hill 
            outputChatBox ( nameOfThePlayer.." entered the zone!", getRootElement(), 255, 255, 109 ) 
        end 
end 
addEventHandler ( "onColShapeHit", colshape, Arena_Enter ) 
  
local team = {} 
  
local teamTable = { 
-- createTeam(Team name, R, G, B) 
{"Unemployed", 255, 255, 0}, 
{"Unoccupied", 255, 182, 193}, 
{"Civilian Workers", 255, 215, 0}, 
{"Police Service", 30, 144, 255}, 
{"Criminals", 0, 255, 0}, 
{"Gangsters", 148, 0, 211}, 
{"Duel Team 1", 10, 34, 29}, 
{"Duel Team 2", 244, 0, 29}, 
} 
  
for i=1, #teamTable do 
        local _team, _r, _g, _b = teamTable[i][1], teamTable[i][2], teamTable[i][3] 
                team[i] = createTeam( _team, _r, _g, _b) 
end 
  
local teamspawn = {} 
  
local teamSpawnTable = { 
{934.74, 1586.27, -17.50, 0, 0, 1} 
} 
  
for i=1, #teamSpawnTable do 
        local _x, _y, _z, _r, _int, _dim = teamSpawnTable[i][1], teamSpawnTable[i][2], teamSpawnTable[i][3], teamSpawnTable[i][4], teamSpawnTable[i][5], teamSpawnTable[i][6] 
end 
  
-- lp = getLocalPlayer() 
-- _team = getPlayerTeam(thePlayer) 
-- name = getPlayerName(thePlayer) 
-- local _thePlayer = getPlayerName(source) 
-- local playerTeam = getPlayerTeam(source) 
  
function kicknotdueler ( source, matchingDimension) 
        local playerTeam = getPlayerTeam(source) 
                if getElementType ( source ) == "player" and playerTeam ~= teamTable[7] then 
                spawnPlayer(source, 934.74, 1586.27, -17.50, 0, plrSkin, 0, 1) 
                outputChatBox("You are not allowed to be in the arena", getRootElement(), 255, 255, 109) 
                else 
                cancelEvent() 
                end 
end 
addEventHandler("onColShapeHit", colshape, kicknotdueler) 

Link to comment

Well, the main problem is that you're using the table 'teamTable' in your 'if', but you should be using 'team' instead.

function kicknotdueler ( hitElement, matchingDimension ) 
    if ( matchingDimension and getElementType ( hitElement ) == "player" ) then 
        local playerTeam = getPlayerTeam ( hitElement ) 
        if ( playerTeam ~= team [ 7 ] ) then 
            setElementPosition ( hitElement, 934.74, 1586.27, -17.50 ) 
            setElementDimension ( hitElement, 1 ) 
            outputChatBox ( "You are not allowed to be in the arena", getRootElement(), 255, 255, 109 ) 
        end 
    end 
end 
addEventHandler ( "onColShapeHit", colshape, kicknotdueler ) 

Link to comment

Now the question is, how do I make it work for a range of teams and not just one?

I've been trying like crazy, trying to figure out how to make it work for a range of teams, but I just don't know how:

  
local teamTable = { 
-- createTeam(Team name, R, G, B) 
{"Unemployed", 255, 255, 0}, 
{"Unoccupied", 255, 182, 193}, 
{"Civilian Workers", 255, 215, 0}, 
{"Police Service", 30, 144, 255}, 
{"Criminals", 0, 255, 0}, 
{"Gangsters", 148, 0, 211}, 
{"Duel Team 1", 10, 34, 29}, 
{"Duel Team 2", 244, 0, 29}, 
{"Duel Team 3", 255, 255, 255}, 
{"Duel Team 4", 255, 255, 255}, 
{"Duel Team 5", 255, 255, 255}, 
{"Duel Team 6", 255, 255, 255}, 
{"Duel Team 7", 255, 255, 255}, 
{"Duel Team 8", 255, 255, 255}, 
} 
  

I'm gonna keep trying to figure out how.

Link to comment
for placeNumber, tableData in ipairs(teamTable) do 
    createTeam(tableData[1]--[[= Team Name]], tableData[2]--[[= R]], tableData[3]--[[= G]], tableData[4]--[[= B]]) 
end 

EDIT: You can also use the code 'unpack'.

for placeNumber, tableData in ipairs(teamTable) do 
    local tName, tR, tG, tB = unpack(tableData) 
    createTeam(tName, tR, tG, tB) 
end 

Link to comment
for placeNumber, tableData in ipairs(teamTable) do 
    createTeam(tableData[1]--[[= Team Name]], tableData[2]--[[= R]], tableData[3]--[[= G]], tableData[4]--[[= B]]) 
end 

EDIT: You can also use the code 'unpack'.

for placeNumber, tableData in ipairs(teamTable) do 
    local tName, tR, tG, tB = unpack(tableData) 
    createTeam(tName, tR, tG, tB) 
end 

Ok, thank you for trying to help, but that first for loop statement is essentially the same thing as

for i=1, #teamTable do 
    local _team, _r, _g, _b = teamTable[i][1], teamTable[i][2], teamTable[i][3], teamTable[i][4] 
        team[i] = createTeam( _team, _r, _g, _b) 
end 

only, you didn't specify it for team[placeNumber]. But it is a different coding style, so I thank you for that.

And the second for loop statement was helpful when trying to use it in cmd, but they still don't tell me how to specify a range of teams that should be allowed in the colshape.

Edited by Guest
Link to comment
allowedTeams = { 
    "Team1", 
    "Team2", 
} 
  
function test() 
    local teamIsAllowed = false 
    for numberData, teamData in ipairs(team) do 
        for placeNumber, tableData in ipairs(allowedTeams) do 
            if (getTeamName(teamData) == teamName) then 
                teamIsAllowed = true 
            end 
        end 
    end 
    if (teamIsAllowed == true) then 
        --Stuff 
    else 
        --Stuff 
    end 
end 

You can do something like this. :P

Link to comment

Ehh, I tried doing what you posted, but to no avail, I couldn't get the script to work properly.

  
function kicknotdueler(source, matchingDimension) 
    local teamisAllowed = false 
    for numberData, teamData in ipairs(team) do 
        for placeNumber, tableData in ipairs(allowedTeams) do 
            if (getTeamName(teamData) == teamName) then 
                teamIsAllowed = true 
            end 
        end 
    end 
    if getElementType ( source ) == "player" then  
        if (teamisAllowed ~= true) then 
            setElementPosition ( source, 934.74, 1586.27, -17.50 ) 
            setElementDimension (source, 1) 
            outputChatBox("You are not allowed to be in the arena!", source, 255, 0, 0)          
        else 
            -- spawnPlayer(source, 949.14, 1613.63, -22.11, 0, plrSkin, 0, 1) 
            cancelEvent() 
            setElementDimension (source, 1) 
        end 
    end 
end 
addEventHandler("onColShapeHit", colshape, kicknotdueler)    
  

Even if I was on one of the allowed teams, it still wouldn't let me in the colshape no matter what. Back to square 1 :/

Link to comment

Why do I always get table index is nil error, line 21? I had this working previously and now it don't work.

  
function kicknotdueler(source, matchingDimension) 
  
local teamtype1 = getTeamFromName("Unemployed") 
local teamtype2 = getTeamFromName("Unoccupied") 
local teamtype3 = getTeamFromName("Civilian Workers") 
local teamtype4 = getTeamFromName("Police Service") 
local teamtype5 = getTeamFromName("Criminals") 
local teamtype6 = getTeamFromName("Gangsters") 
local teamtype7 = getTeamFromName("Duel Team 1") 
local teamtype8 = getTeamFromName("Duel Team 2") 
local teamtype9 = getTeamFromName("Duel Team 3") 
local teamtype10 = getTeamFromName("Duel Team 4") 
local teamtype11 = getTeamFromName("Duel Team 5") 
local teamtype12 = getTeamFromName("Duel Team 6") 
local teamtype13 = getTeamFromName("Duel Team 7") 
local teamtype14 = getTeamFromName("Duel Team 8") 
  
--duelTeamTable = {teamtype7, teamtype8, teamtype9, teamtype10, teamtype11, teamtype12, teamtype13, teamtype14} 
--normalsTeamTable = {teamtype1, teamtype2, teamtype3, teamtype4, teamtype5, teamtype6} 
duelTeamTable = {} 
duelTeamTable[a] = teamtype1, teamtype2, teamtype3, teamtype4, teamtype5, teamtype6 
duelTeamTable[b] = teamtype7, teamtype8, teamtype9, teamtype10, teamtype11, teamtype12, teamtype13, teamtype14 
  
  
--duelTeamTable["tea"] = teamtype1, teamtype2, teamtype3, teamtype4, teamtype5, teamtype6 
--duelTeamTable["tea2"] = teamtype7, teamtype8, teamtype9, teamtype10, teamtype11, teamtype12, teamtype13, teamtype14 
local team = getPlayerTeam(source) 
     
    if getElementType ( source ) == "player" then  
            if (team == duelTeamTable[b]) then 
                cancelEvent() 
                setElementDimension (source, 1) 
            elseif (team == duelTeamTable[a]) then 
                setElementPosition ( source, 934.74, 1586.27, -17.50 ) 
                setElementDimension (source, 1) 
                outputChatBox("You are not allowed to be in the arena!", source, 255, 0, 0) 
            else 
                setElementPosition ( source, 934.74, 1586.27, -17.50 ) 
                setElementDimension (source, 1) 
                outputChatBox("You are not allowed to be in the arena!", source, 255, 0, 0) 
            end 
        end 
    end 
addEventHandler("onColShapeHit", colshape, kicknotdueler) 
  

If I set the keys to ["a"] and ["b"] respectively, the script only works if I'm on "Duel Team 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...