Baseplate Posted February 14, 2013 Share Posted February 14, 2013 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
csiguusz Posted February 14, 2013 Share Posted February 14, 2013 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
Baseplate Posted February 15, 2013 Author Share Posted February 15, 2013 I meant, I wanted to use the players who's in this table to do something else. Link to comment
Moderators IIYAMA Posted February 15, 2013 Moderators Share Posted February 15, 2013 Then you also have to put the table in pairs. for i, v in ipairs( robbing ) do givePlayerMoney (v, 20000) end Link to comment
Baseplate Posted February 15, 2013 Author Share Posted February 15, 2013 Aha, thanks! Another question, how to count how much elements/players are in this table? Link to comment
Baseplate Posted February 15, 2013 Author Share Posted February 15, 2013 Any example? Link to comment
TAPL Posted February 15, 2013 Share Posted February 15, 2013 Any example? outputChatBox(#robbing) Link to comment
Baseplate Posted February 15, 2013 Author Share Posted February 15, 2013 Ah, I didn't get him much, thanks Link to comment
Baseplate Posted February 15, 2013 Author Share Posted February 15, 2013 Again a new question, anyway to count how much players in that marker? Link to comment
TAPL Posted February 15, 2013 Share Posted February 15, 2013 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 IIYAMA Posted February 15, 2013 Moderators Share Posted February 15, 2013 -- 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
Anderl Posted February 15, 2013 Share Posted February 15, 2013 I recommend you using iteration statements to find the length of an array, since the symbol '#' does not count anything else than number indexes. Just in case you don't know what an iteration statement is: it's a for loop. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now