Jump to content

Tables


Baseplate

Recommended Posts

robbing = {} 
tehMarker = createMarker(x, y, z, "cylinder") 
  
function MarkerHit( hitElement, matchingDimension )  
if getElementType( hitElement ) == "player" then 
table.insert(robbing, hitElement) 
end 
end 
addEventHandler( "onMarkerHit", myMarker, MarkerHit ) 
  
function markerLeave( leaveElement, matchingDimension ) 
if getElementType( leaveElement ) == "player" then 
table.remove(robbing, leaveElement) 
end 
end 
addEventHandler( "onMarkerLeave", myMarker, markerLeave ) 

Will this work and how to get players from this table?

Link to comment

With table.remove you can remove elements from tabke by index:

function markerLeave( leaveElement, matchingDimension ) 
    if getElementType( leaveElement ) == "player" then 
        for i, v in ipairs( robbing ) do 
            if v == leaveElement then 
                table.remove( robbing, i ) 
            end 
        end 
    end 
end 

And what do you mean by getting players from the table? Use a for loop for example...

Link to comment

Not tested, and not sure if it will work or not.

function getPlayersCountInMarker(marker) 
    if isElement(marker) and getElementType(marker) == "marker" then 
        local col = getElementColShape(marker) 
        if col then 
            local count = getElementsWithinColShape(col, "player") 
            if count and type(count) == "table" then 
                return #count 
            end 
        end 
    end 
end 

Link to comment
  • Moderators

-- not sure when a player leavesthe server, the onMarkerLeave will be triggered.

local inside = {} 
function MarkerHit( hitElement, matchingDimension ) 
if getElementType( hitElement, ) == "player" then 
table.insert (inside,{hitElement,source}) 
end 
end 
addEventHandler( "onMarkerHit", myMarker, MarkerHit )  
  
function markerLeave( leaveElement, matchingDimension ) 
if getElementType( leaveElement, ) == "player" then 
        for i, v in ipairs( inside ) do 
            if v[2] == leaveElement then 
                table.remove( inside, i ) 
                --v[1]) player 
            end 
        end 
end 
end 
addEventHandler( "onMarkerLeave", myMarker, markerLeave ) 
  

--#inside this shows you how many people are inside

-- source is the marker.

-- btw not sure if it works 100%, I made it in a hurry....

The structure of this table will look like this:

local inside = { 
    {player,marker}, --<<< 
    {player,marker}, 
    {player,marker}, 
    {player,marker} 
} 
  
v = inside[1] -- take the first position <<< 
  
player,marker = unpack (v) 
--  or 
player = v[1]  
marker = v[2] 
  

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