Array problem


#1

Hey guys,

my array dont work :frowning:

here the code (Server)

Users = {}

RegisterServerEvent(“onPlayerConnect”)
AddEventHandler(‘onPlayerConnect’, function()
Users[GetPlayerName(source)] = GetPlayerName(source)
Users[GetPlayerName(source)][‘Fraktion’] = 0;
Users[GetPlayerName(source)][‘Leader’] = 0;
Users[GetPlayerName(source)][‘Rank’] = 0;
Users[GetPlayerName(source)][‘Admin’] = 0;
end)

Whats the problem with the code?

Commands (Server)

if(command[1] == “/giveadmin”) then
if(command[2] ~= 0) then
Users[GetPlayerName(source)][‘Admin’] = tonumber(command[2]);
SendClientMessage(source, "You are now admin "… tonumber(command[2]))
return

	else
		SendClientMessage(source, "Failed: /giveadmin [Level]")
		return			
	end
elseif(command[1] == "/givefrak") then
	if(Users[GetPlayerName(source)]['Admin'] ~= 0) then		
		if(command[2] ~= 0) then			
			Users[GetPlayerName(source)]['Fraktion'] = command[2]
			Users[GetPlayerName(source)]['Leader'] = 1
			SendClientMessage(source, "You are now in faction ".. command[2])
			return
		else
			SendClientMessage(source, "Failed: /givefrak [Fraktion]") 
			return
		end
	
	else
		SendClientMessage(source, "Failed: You are not a Admin! ") 			
		return
	end		
end

#2

@m4a_X OK First, this:

Users[GetPlayerName(source)] = GetPlayerName(source)

That wont work properely because you just made a value point to a not-array value. So when you do

Users[GetPlayerName(source)]['Fraktion'] = 0;

You try to set a multi-dimensional table value of a string. Which won’t work. Instead you can replace the first thing with

Users[GetPlayerName(source)] = {}

And if you desperately want the playername just add it to the array.

Users[GetPlayerName(source)]['Username'] = GetPlayerName(source)

I hope i clarified a bit on why it doesn’t work.


#3

now i have a problem with command

elseif(command[1] == “/giveadmin”) then
if(command[2] ~= 0) then

			Users[GetPlayerName(source)]['Admin'] = tonumber(command[2]);
			SendClientMessage(source, "Du bist jetzt Administrator Stufe ".. tonumber(command[2]))
			return
	
	else
		SendClientMessage(source, "Fehler: /giveadmin [Level]")
		return			
	end
elseif(command[1] == "/givefrak") then
	if(Users[GetPlayerName(source)]['Admin'] ~= 0) then		
		if(command[2] ~= 0) then			
			Users[GetPlayerName(source)]['Fraktion'] = command[2]
			Users[GetPlayerName(source)]['Leader'] = 1
			SendClientMessage(source, "Du bist jetzt in der Fraktion ".. command[2])
			return
		else
			SendClientMessage(source, "Fehler: /givefrak [Fraktion]") 
			return
		end
	
	else
		SendClientMessage(source, "Fehler: Du bist kein Admin!") 			
		return
	end		
end