Jump to content

Counting Group Members


Snow-Man

Recommended Posts

Posted (edited)

i'm making group system and i have got a problem to count group member using 

setElementData

getElementData


 

function getGroupMembers(group)
    if (not group) then return false end
    local memberCount = getElementData(group, "Members") or 0
    return tonumber(memberCount)                                                            
end

 

Edited by Snow-Man
Posted
function createGroup(groupName)
	local account = getPlayerAccount(client)
	if (isGuestAccount(account)) then return end
	if (groupName) then
		outputChatBox(groupName.." is already an existing group", client, 255, 0, 0)
			return
		end
		setElementData(client, "Group", groupName)
		setElementData(client, "Rank", "Founder")
		setElementData(groupName, "Members", 1)
		outputChatBox("You have succesfully made a group called "..groupName, client, 0, 255, 0)
	end
addEvent("createGroup", true)
addEventHandler("createGroup", root, createGroup)

that's a part of creating Group

Posted (edited)
createTeam
Why not use it?

 

and what do you want to do with

if (groupName) then
outputChatBox(groupName.." is already an existing group", client, 255, 0, 0)
return
end

?

 

Answer to you question: it's a data bound to the player, you are not passing the player in the first post. You are passing "group", is it a string or what?

Edited by LoPollo
Posted

ok, sorry i didn't understand.

I think you should keep track of the group as a separate element, instead of setting a player data. I'm not sure, i never used it, but createElement can be used to create an element right? create an element in which you store all the necessary data, if you really need an element. 

Another solution is to make a table that stores all the informations, it will be easier to manage also.

local groups = {
  --["yourGroupName"] = { members = {somePlayer1, somePlayer2}, color = {255,255,255}, whatever = someValue },
}

--member count of "yourGroupName" = #groups.yourGroupName.members

 

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