Jump to content

Groups System


ShayF2

Recommended Posts

Posted

I'm working on an advanced groups system, Here is a clip of what I already have done. I plan on adding a GUI in the future.

Spoiler

groups = {}

addEventHandler('onResourceStart',resourceRoot,function()
	loadAndUpdateGroups()
end)

function loadTeams()
	for ii,gg in pairs(groups) do
		for iii,ggg in pairs(getElementsByType('team')) do
			if getTeamName(ggg) == gg[1] then
				destroyElement(ggg)
			end
		end
		createTeam(gg[1],unpack(gg['color']))
	end
end

function loadAndUpdateGroups()
	if not fileExists('groups.json') then
		local file = fileOpen('groups.json')
	end
	local file = fileOpen('groups.json')
	fileWrite(file,toJSON(groups))
	fileClose(file)
	local file = fileOpen('groups.json')
	local size = fileGetSize(file)
	local buffer = fileRead(file,size)
	groups = fromJSON(buffer)
	fileClose(file)
	outputChatBox('Group data saved successfully!',root,0,255,255)
end
setTimer(loadAndUpdateGroups,10000,0)

function getPlayerGroup(player)
	local serial = getPlayerSerial(player)
	for e,y in pairs(groups) do
		for ee,yy in pairs(y['members']) do
			if yy == serial then
				return y[1]
			end
		end
	end
end

function getPlayerGroupRank(player)
	local serial = getPlayerSerial(player)
	local group = getPlayerGroup(player)
	if group then
		return groups[group]['members'][serial][1]
	end
end

function createGroup(player,cmd,name,r,g,b)
	if getPlayerRank(player,"Admin") or getPlayerGroup(player) then
		local r,g,b = tonumber(r),tonumber(g),tonumber(b)
		if name then
			if r then
				if g then
					if b then
						groups[name] = {}
						groups[name]['color'] = {r,g,b}
						outputChatBox('Group created successfully!',player,0,255,255)
					else
						groups[name] = {}
						groups[name]['color'] = {r,g,0}
						outputChatBox('Group created successfully!',player,0,255,255)
					end
				else
					groups[name] = {}
					groups[name]['color'] = {r,0,0}
					outputChatBox('Group created successfully!',player,0,255,255)
				end
			else
				groups[name] = {}
				groups[name]['color'] = {255,0,0}
				outputChatBox('Group created successfully!',player,0,255,255)
			end
		end
		loadTeams()
		loadAndUpdateGroups()
	end
end
addCommandHandler('gcreate',createGroup)

function addToGroup(player,cmd,other)
	if other then
		if getPlayerRank(player,"Admin") then
			local otherPlayer = getPlayerFromPartialName(other)
			if otherPlayer then
				local team = getTeamName(getPlayerTeam(player))
				if groups[team] then
					local serial = getPlayerSerial(otherPlayer)
					for u,n in pairs(groups[team]) do
						if not n == serial then
							table.insert(groups[team],serial)
						end
					end
				end
			end
		end
	end
end
addCommandHandler('gadd',addToGroup)

 

 

Posted

Honestly, you guys are dicks. Like half this :~ doesn't even matter to you. If you wanna be that way then you shouldn't do it here. This is a place were people ask for help and show off what they got. That's commonly what this forum is used for. So I'll rebel, against forum rules, keep this post here.

Posted

This is not a finished script. I'd like help on it, but making a post wouldn't matter because half the people on here look at them and then never reply.

Would you mind telling me what this says?
81UhzvV.png

Posted

Is it a working script? Yes, it is. You just released it as a not finished script, and this section is not for this. This is asking for help, when a script is not working as it should, or it's not working at all. (Not finished script, but still at Resources, because this is how it should be.) What help does this script need?

Posted
Just now, NeXuS™ said:

Is it a working script? Yes, it is. You just released it as a not finished script, and this section is not for this. This is asking for help, when a script is not working as it should, or it's not working at all. (Not finished script, but still at Resources, because this is how it should be.) What help does this script need?

81UhzvV.png
"All Lua scripting topics related to Multi Theft Auto"

Posted
1 minute ago, NeXuS™ said:

This is not a scripting topic, this is a show off of one of your resources.

It is a script, it contains Lua code. Therefor it belongs in the SCRIPTING topic..

Posted (edited)

Finished it here, because you cannot understand what this section of the forum is for.

Edited by NeXuS™
  • Like 1
  • MTA Team
Posted (edited)

@shay103 This is a progress show-off, even when it's not finished yet that belongs in the Resources section. It would only be appropiate for Scripting section if you also ask a set of concrete scripting questions on how to proceed/finish it, which you didn't. There's no need for that attitude, and those reporting the post to be moved were right. I suggest you cut off this argument or else it will be locked, and hope that you understand better now you're not right.

No more fights after this (my) comment.

Edited by Dutchman101

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