Jump to content

Help with login Panel.


Pedro001

Recommended Posts

Hi Guys. Could someone help me with this please! 

Basically, this login panel is linked to an sql database, but the problem is, when someone register in this panel, it is registered in the database but not to the mta. I don't know if I'm being clear. I see that the functions 'addAccount' and 'logIn' are missing. For example, even if the player logs in in this panel, he's shown as guest in the admin panel, thus I can't add a player in an acl for example.  

Help me Please!

local connection = dbConnect("mysql",exports['ne_mysql']:getSQLData())
local key = ""

addEvent("onCharacterLogin", false)
addEvent("onClientCharacterRequest", true)
addEventHandler("onClientCharacterRequest", getRootElement(),
	function(charname)
		playerSource = client
		local id = getElementData(client, "char.accountID")
		local qh = dbQuery(connection, "SELECT * FROM `players` WHERE `account` = ?", id)
		local row = dbPoll(qh, -1)
		if row then
			for k, row in ipairs (row) do
				local id = tonumber(row["id"])
				local x = tonumber(row["x"])
				local y = tonumber(row["y"])
				local z = tonumber(row["z"])
				local rot = tonumber(row["rot"])
				local interior = tonumber(row["intID"])
				local dimension = tonumber(row["dimID"])
				local health = tonumber(row["health"])
				local hunger = tonumber(row["hunger"])
				local armor = tonumber(row["armor"])
				local skin = tonumber(row["skin"])
				local money = tonumber(row["money"])
				local npoints = tonumber(row["npoints"])
				local nsujo = tonumber(row["nsujo"])
				local carlicense = tostring(row["drivinglicense"])
				local bankmoney = tonumber(row["bankMoney"])
				local playedMinutes = tonumber(row["playedMinutes"])
				local lastLogin = tonumber(row["lastlogin"])
				local gender = tonumber(row["gender"])
				local age = tonumber(row["age"])
				local weight = tonumber(row["weight"])
				local height = tonumber(row["height"])
				local adminnick = tostring(row["adminnick"])
				local charname = tostring(row["charname"])
				charname = string.gsub(tostring(charname), " ", "_")
				local walkingstyle = tonumber(row["walkingstyle"])
				local jobID = tonumber(row["jobID"])
				local jobName = tostring(row["jobName"])
				local radiochannel = tonumber(row["radiochannel"])
				local factionID = tonumber(row["factionID"])
				local factionLeader = tonumber(row["factionLeader"])
				local factionRank = tonumber(row["factionRank"])
				local badgeNumber = tonumber(row["badgeNumber"])
				local dutySkin = tonumber(row["dutySkin"])
				local showHUD = tonumber(row["showHUD"])
				local showOOC = tonumber(row["showOOC"])
				local showRadar = tonumber(row["showRadar"])
				local payTime = tonumber(row["payTime"])
				local adminlevel = getElementData(playerSource, "char.adminlevel")
				local adminduty = getElementData(playerSource, "char.adminduty")
				
				setElementData(playerSource, "char.factionID", tonumber(factionID))
				setElementData(playerSource, "char.factionLeader", tonumber(factionLeader))
				setElementData(playerSource, "char.factionRank", tonumber(factionRank))
				setElementData(playerSource, "char.badgeNumber", tonumber(badgeNumber))
				setElementData(playerSource, "char.dutySkin", tonumber(dutySkin))
				setElementData(playerSource, "age", tonumber(age))
				setElementData(playerSource, "weight", tonumber(weight))
				setElementData(playerSource, "height", tonumber(height))
				setElementData(playerSource, "walkingstyle", tonumber(walkingstyle))
				setElementData(playerSource, "char.jobID", tonumber(jobID))
				setElementData(playerSource, "char.jobName", tostring(jobName))
				if carlicense == "true" then
				setElementData(playerSource, "char.drivingLicense", true)
				else 
                setElementData(playerSource, "char.drivingLicense", false)
				end
				setElementData(playerSource, "charname", tostring(charname))
				setElementData(playerSource, "char.playedMinutes", tonumber(playedMinutes))
				setElementData(playerSource, "char.lastLogin", tonumber(lastLogin))
				setElementData(playerSource, "char.UID", tonumber(id))
				setElementData(playerSource, "char.skin", tonumber(skin))
				setElementData(playerSource, "char.adminlevel", tonumber(adminlevel))
				setElementData(playerSource, "char.adminnick", adminnick)
				setElementData(playerSource, "char.bankMoney", tonumber(bankmoney))
				setElementData(playerSource, "char.money",tonumber(money))
				setElementData(playerSource, "char.diamante",tonumber(npoints))
				setElementData(playerSource, "char.moneysujo",tonumber(nsujo))
				setElementData(playerSource, "char.radio",tonumber(radiochannel))
				setElementData(playerSource, "char.payTime",tonumber(payTime))
				setElementData(playerSource, "gender", tonumber(gender))
				setElementData(playerSource, "visibleName", tostring(charname))
				setElementData(playerSource, "char.phoneNumber", tonumber(id))
				setElementData(playerSource, "showHUD", tonumber(showHUD))
				setElementData(playerSource, "showOOC", tonumber(showOOC))
				setElementData(playerSource, "showRadar", tonumber(showRadar))						
				setPlayerName(playerSource, tostring(charname))
				local name = string.gsub(tostring(charname), "_", " ")
				setPlayerNametagText(source, tostring(name))
				setElementData(playerSource,"char.hunger",hunger)
				setElementData(playerSource, "dbid", getElementData(playerSource, "char.UID"))
				setElementData(playerSource, "char.health", tonumber(health))
				setPedAnimation(playerSource, false)
				setElementHealth(playerSource, health)
				setPedArmor(playerSource, armor)
				setPedSkin(playerSource, skin)
				spawnPlayer(playerSource, x, y, z+2, rot, skin, interior, dimension)
				setPedWalkingStyle(client, walkingstyle)					
				dbExec(connection,"UPDATE `players` SET `lastlogin`=NOW() WHERE `id`=?",id)
				toggleAllControls(playerSource, true, true, true)
				fadeCamera(playerSource, true)
				triggerEvent("onCharacterLogin", playerSource, charname)
				
			if getElementData(playerSource, "char.jailTime") > 0 then
				setElementDimension(playerSource, 60000 + getElementData(playerSource, "charID"))
				setElementInterior(playerSource, 6)
				setElementPosition(playerSource, 263.821807, 77.848365, 1001.0390625)
				setPedRotation(playerSource, 267.438446)	
				setElementData(playerSource, "char.jailTime", getElementData(playerSource, "char.jailTime"))
				setElementData(playerSource, "char.jailReason", getElementData(playerSource, "char.jailReason"))
				setElementData(playerSource, "char.adminJail", true)
				outputChatBox("[Prisão]: Você está na cadeia, motivo: "..getElementData(playerSource, "char.jailReason")..".", playerSource, 124, 9, 9, true)
				outputChatBox("[Prisão]: Tempo: "..getElementData(playerSource, "char.jailTime")..".", playerSource, 124, 9, 9, true)
				exports.vz_bans:loginPlayerJailed()
			else
				setElementData(playerSource, "char.jailTime", 0)
				setElementData(playerSource, "char.jailReason", nil)
				setElementData(playerSource, "char.adminJail", false)
			    end
			end
		else
			outputDebugString( "Conexão com o MySQL falhou!")
		end
	end
)

addEvent("onPlayerLogin", false)
addEvent("onClientLoginRequest", true)
addEventHandler("onClientLoginRequest", getRootElement(),
	function(username, password)
		if (string.len(password)~=64) then
			password = string.reverse((key) .. (password))
		end	
		local lgnQuery = dbQuery(connection, "SELECT * FROM `users` WHERE `username`=? AND `password`=?", username, password )
		playerSource = client
		local lgnResult = dbPoll ( lgnQuery, -1 )
		if #lgnResult > 0 then
			for k, row in ipairs ( lgnResult ) do
				triggerEvent("onPlayerLogin", playerSource, username, password)
				local id = tonumber(row["id"])
				local pass = tonumber(row["password"])
				local found = false
				for key, v in ipairs(getElementsByType("player")) do
					local accid = tonumber(getElementData(v, "char.accountID"))
					if (accid) then
						if (accid==id) and (v~=playerSource) then
							found = true
							break
						end
					end
				end
				if not (found) then
					local admin = tonumber(row["admin"])
					local adminduty = tonumber(row["adminduty"])
					local adminjail = tonumber(row["adminjail"])
					local adminJailTime = tonumber(row["adminjail_time"])
					local adminJailBy = tostring(row["adminjail_by"])
					local adminJailReason = row["adminjail_reason"]
					local banned = tonumber(row["banned"])
					if tonumber(admin) == 0 then adminduty = 0 end
					setElementData(playerSource, "char.adminlevel", tonumber(admin))
					
					local lasethp = tonumber(row["asethp"])
			        local lasetarmor = tonumber(row["asetarmor"])
					local lasethunger = tonumber(row["asethunger"])
			        local lagoto = tonumber(row["agoto"])
			        local lagethere = tonumber(row["agethere"])
			        local lagivemoney = tonumber(row["agivemoney"])
			        local lasetmoney = tonumber(row["asetmoney"])
					local lagiveitem = tonumber(row["agiveitem"])
			        local laadutyminute = tonumber(row["adutyminute"])
			        local lafuelveh = tonumber(row["afuelveh"])	
			        local lafixveh = tonumber(row["afixveh"])
			        local lareply = tonumber(row["areply"])
			        local lapm = tonumber(row["apm"])
			        local lamakeveh = tonumber(row["amakeveh"])
			        local lajail = tonumber(row["ajail"])
			        local laban = tonumber(row["aban"])
					if (banned==1) then
						kickPlayer(source,"Server Name","Sua conta está bloqueada")
					else
						setElementData(playerSource, "char.defaultUserName", username)
						setElementData(playerSource, "char.accountID", tonumber(id))
						setElementData(playerSource, "char.adminduty", tonumber(adminduty))
	                    setElementData(playerSource, "char.jailTime", adminJailTime)
						setElementData(playerSource, "char.jailReason", adminJailReason)
						setElementData(playerSource, "admin.sethp", lasethp)
			            setElementData(playerSource, "admin.setarmor", lasetarmor)
			            setElementData(playerSource, "admin.sethunger", lasethunger)
			            setElementData(playerSource, "admin.goto", lagoto)
			            setElementData(playerSource, "admin.gethere", lagethere)
			            setElementData(playerSource, "admin.givemoney", lagivemoney)
			            setElementData(playerSource, "admin.setmoney", lasetmoney)
						setElementData(playerSource, "admin.giveitem", lagiveitem)
			            setElementData(playerSource, "admin.adutyminute", laadutyminute)
			            setElementData(playerSource, "admin.fuelveh", lafuelveh)	
			            setElementData(playerSource, "admin.fixveh", lafixveh)
			            setElementData(playerSource, "admin.reply", lareply)
			            setElementData(playerSource, "admin.pm", lapm)
			            setElementData(playerSource, "admin.makeveh", lamakeveh)
			            setElementData(playerSource, "admin.jail", lajail)
			            setElementData(playerSource, "admin.ban", laban)
						
						fadeCamera(playerSource, true)
						requestAccounts(playerSource, id)
						local ip = getPlayerIP(playerSource)
						local serial = getPlayerSerial(playerSource)
						dbExec(connection,"UPDATE `users` SET `ip`=?, serial=? WHERE `id`=?",ip,serial,id)
					end
				end
			end
		else
		exports.vz_info:showBoxS(playerSource, "Nome de usuário ou senha inválidos", "error")
	end
end
)

addEvent("onClientTryToCreateAccount", true)
addEventHandler("onClientTryToCreateAccount", getRootElement(),
	function(username, password)
		local value = dbQuery(connection, "SELECT * FROM `users`")
		local result = dbPoll (value, -1 )
		local serial = getPlayerSerial(source)
		password = string.reverse((key) .. (password))
		if result then
			for _, row in ipairs ( result ) do
				if string.lower(row["username"]) == username then
				   exports.vz_info:showBoxS(source, "Esse nome de usuário já existe", "error")
					return
				end
				if row["mtaserial"] == serial then
					exports.vz_info:showBoxS(source, "Você já tem uma conta", "error")
					return
				end
			end
		end
		exports.vz_info:showBoxS(source, "Registro bem sucedido!", "info")
		local data = dbExec(connection, "INSERT INTO users SET username = ?, password = ?, mtaserial = ?", username, password, serial)
		triggerClientEvent(source,"onRegisterFinish",source)
	end
)

addEvent("OnClientTryToCreateCharacter", true)
addEventHandler("OnClientTryToCreateCharacter", getRootElement(),
	function(charname, skins, age, sex)
		local value = dbQuery(connection, "SELECT `charname` FROM `players` WHERE `charname` = ?", tostring(charname))
		local result = dbPoll (value, -1)
		local count = 0
		local pw
		cname = nil
		if result then
			for _, row in ipairs ( result ) do
				cname = string.lower(row["charname"])
			end
			if cname ~= nil then 
				exports.vz_info:showBoxS(source, "O nome desse personagem já existe", "error")
				return
			end
		end
		dbFree(value)
		local accountID = getElementData(source, "char.accountID")
		data = dbExec( connection, "INSERT INTO `players` SET charname=?, account=?, intID=0, dimID=0, x=1481.06226, y=-1770.94824, z=18.79576, skin=0, age=?, gender=?", charname, accountID, age, sex)
		setPlayerName(source, charname)
		triggerClientEvent(source,"onSuccessLogin",source)
		requestAccounts(source, accountID)
		triggerClientEvent(source, "createCharacterLogin", source)
	end
)

function requestAccounts(playerSource, id)
	local requestAcc = {}
	local query = dbQuery(connection, "SELECT id, charname,money, age, gender, skin, DATEDIFF(NOW(), lastlogin) FROM players WHERE account=?", id)
	local result = dbPoll(query, -1)
	if (#result>0) then
		for k, data in ipairs (result) do
			local i = 1
			requestAcc[i] = {}
			requestAcc[i][0] = tonumber(data["id"])
			requestAcc[i][1] = tostring(data["charname"])
			requestAcc[i][2] = tonumber(data["skin"])
			requestAcc[i][3] = tonumber(data["money"])
			i = i + 1
		end
	end
	triggerClientEvent(playerSource, "createCharacterLogin", playerSource, requestAcc, true, true)
end
addEvent("requestAccounts", true)
addEventHandler("requestAccounts", getRootElement(), requestAccounts)

function saveChar()
	if getElementData(source, "CharLoggedIn") then
		local x, y, z = getElementPosition(source)
		local rot = getPedRotation(source)
		local health = getElementHealth(source)
		local hunger = getElementData(source, "char.hunger") or 0
		local age = getElementData(source, "age")
		local gender = getElementData(source, "gender")
		local armor = getPedArmor(source)
		local interior = getElementInterior(source)
		local dimension = getElementDimension(source)
		local charname = getElementData(source, "charname")
		local skin = getElementData(source, "char.skin")
		local playedMinutes = getElementData(source, "char.playedMinutes")
		local money = getElementData(source, "char.money")
		local npoints = getElementData(source,"char.diamante")
		local nsujo = getElementData(source,"char.moneysujo")
		local factionID = getElementData(source,"char.factionID")
		local factionLeader = getElementData(source,"char.factionLeader")
		local factionRank = getElementData(source,"char.factionRank")
		local badgeNumber = getElementData(source,"char.badgeNumber")
		local dutySkin = getElementData(source,"char.dutySkin")
		local bankMoney = getElementData(source, "char.bankMoney")
		local adminlevel = getElementData(source, "char.adminlevel")
		local jobID = getElementData(source, "char.jobID")
		local jobName = getElementData(source, "char.jobName")
		local radio = getElementData(source, "char.radio")
		local showHUD = getElementData(source, "showHUD")
		local showOOC = getElementData(source, "showOOC")
		local showRadar = getElementData(source, "showRadar")
		local drivingLicense =  tostring(getElementData(source, "char.drivingLicense"))
		local jailTime = getElementData(source, "char.jailTime")
		local jailReason = getElementData(source, "char.jailReason") or "null"
		local adminJail = getElementData(source, "char.adminJail")
		local payTime = getElementData(source, "char.payTime")
		local asethp = getElementData(source, "admin.sethp")
		local asetarmor = getElementData(source, "admin.setarmor")
		local asethunger = getElementData(source, "admin.sethunger")
		local agoto = getElementData(source, "admin.goto")
		local agethere = getElementData(source, "admin.gethere")
		local agivemoney = getElementData(source, "admin.givemoney")
		local agiveitem = getElementData(source, "admin.giveitem")
		local asetmoney = getElementData(source, "admin.setmoney")
		local aadutyminute = getElementData(source, "admin.adutyminute")
		local afuelveh = getElementData(source, "admin.fuelveh")
		local afixveh = getElementData(source, "admin.fixveh")
		local areply = getElementData(source, "admin.reply")
		local apm = getElementData(source, "admin.pm")
		local amakeveh = getElementData(source, "admin.makeveh")
		local ajail = getElementData(source, "admin.jail")
		local aban = getElementData(source, "admin.ban")
		local update = dbExec(connection,"UPDATE players SET x=?, y=?, z=?, rot=?, health=?,hunger=?, armor=?, dimID=?, intID=?, money=?, npoints=?, nsujo=?, factionID=?, factionLeader=?, factionRank=?, badgeNumber=?, dutySkin=?, lastlogin=NOW(), playedMinutes=?, skin=?, charname=?, jobID=?, jobName=?, bankMoney=?, drivinglicense=?, radiochannel=?, showHUD=?, showOOC=?, showRadar=?, payTime=?, age=?, gender=? WHERE id=?",x,y,z,rot,health,hunger,armor,dimension,interior,money,npoints,nsujo,factionID,factionLeader,factionRank,badgeNumber,dutySkin,playedMinutes,skin,charname,jobID,jobName,bankMoney,drivingLicense,radio,showHUD,showOOC,showRadar,payTime,age,gender,getElementData(source, "char.UID"))	
		local update2 = dbExec(connection,"UPDATE users SET lastlogin=NOW(), `admin`=?, adminjail_time=?, adminjail_reason=?, adminjail=? WHERE id = " .. getElementData(source,"char.accountID"),adminlevel, jailTime, jailReason, adminJail)
		local update3 = dbExec(connection,"UPDATE users SET asethp=?, asetarmor=?, asethunger=?, agoto=?, agethere=?, agivemoney=?, asetmoney=?, agiveitem=?, adutyminute=?, afuelveh=?, afixveh=?, areply=?, apm=?, amakeveh=? WHERE id = " .. getElementData(source,"char.accountID"), asethp, asetarmor, asethunger, agoto, agethere, agivemoney, asetmoney, agiveitem, aadutyminute, afuelveh, afixveh, areply, apm, amakeveh, ajail, aban)
	end
end
addEvent("saveChar", true)
addEventHandler("saveChar",getRootElement(),saveChar)
addEventHandler("onPlayerQuit", getRootElement(), saveChar)

addCommandHandler("ban",
function(playerSource,commandName,targetPlayer,ttime,...)
	if getElementData(playerSource, "char.adminlevel") >= 5 then -- Administrador acima do nivel *5 pode banir
		local ttime = tonumber ( ttime )
		if targetPlayer and ttime then
		local targetPlayer, targetPlayerName = exports.vz_main:findPlayerByPartialNick(source, targetPlayer)
			if (getElementData(targetPlayer, "char.adminlevel") or 0) < getElementData(playerSource, "char.adminlevel") then
				local pSerialC = getPlayerSerial(targetPlayer)
				local duration = (ttime*60)*60
				local reason = table.concat({...}, " ")
				local adminName = getElementData(playerSource,"char.adminnick")
				if ttime == 0 then
					dbExec(connection ,"INSERT INTO bans SET accountid=?, bannedBy=?, timeZone=?, playerSerial=?, reason = ?, playername=?",getElementData(targetPlayer, "char.accountID"), adminName ,23414590357, pSerialC, reason, targetPlayerName)
				else
					dbExec(connection ,"INSERT INTO bans SET accountid=?, bannedBy=?, timeZone=?, playerSerial=?, reason = ?, playername=?",getElementData(targetPlayer, "char.accountID"), adminName ,getRealTime()["timestamp"]+duration, pSerialC, reason, targetPlayerName)
				end
				if ttime == 0 then
					text = "Eterno"
				else
					text = ttime .. " hora"
				end
				dbExec(connection, "UPDATE users SET banned=1, banned_by=?, banned_reason=? WHERE id=?", adminName, reason, getElementData(targetPlayer, "char.accountID"))
				kickPlayer(targetPlayer, adminName, reason )
				setElementData(playerSource, "admin.ban", getElementData(playerSource, "admin.ban") + 1)
				outputChatBox("#4169E1[Ban]: #ffffff" ..adminName .. " baniu o jogador " .. targetPlayerName .. "", root, 255, 255, 255, true)
				outputChatBox("#4169E1[Ban]: #ffffffHora do banimento: " .. text .. " - Motivo: #4169E1" .. reason .. "", root, 255, 255, 255, true)
			else
			    outputChatBox("#ff0000[Error]: #ffffffVocê não pode banir um administrador superior a você", playerSource, 255, 255, 255, true)
				outputChatBox("#4169E1[Ban]: #ffffff"..getElementData(playerSource,"char.adminnick").." tentou banir um administrador do servidor", targetPlayer, 255, 255, 255, true)
			end
			else
			outputChatBox("#4169E1[Use]:#ffffff /" .. commandName .. " [ID] [hora (0 - eterno)] [motivo]", playerSource, 208, 101, 29, true)
		end
	end
end
)

addCommandHandler("offban", -- Administrador acima do nivel *5 pode banir jogadores offline
function (thePlayer, commandName, targetPlayer, tttime, ...)
	if getElementData(thePlayer, "char.adminlevel") >= 5 then
	    local tttime = tonumber(tttime)
		if not (targetPlayer) or not (tttime) or not (...) then
			outputChatBox("#4169E1[Use]: #ffffff/" .. commandName .. " [Nome Completo] [hora (0 - eterno)] [Motivo]", thePlayer , 255, 255, 255, true)
		else
		    
			local targetPlayer = targetPlayer:gsub(" ", "_")
			local targetPlayerName = targetPlayer:gsub("_", " ")
			local adminName = getElementData(thePlayer,"char.adminnick")
			local reason = table.concat({...}, " ")
			local duration = (tttime*60)*60
			
			if targetPlayer then
			  if (getElementData(targetPlayer, "char.adminlevel") or 0) < getElementData(thePlayer, "char.adminlevel") then
				local qh = dbQuery(connection, "SELECT * FROM players WHERE charname='" .. targetPlayer .. "'")
				local result, num = dbPoll (qh, -1)
 
				if num == 0 then outputChatBox("#ff0000[Falha]: #ffffffEsse banimento não existe", thePlayer, 255, 255, 255, true) return end
				if result then
					for _, row in ipairs ( result ) do
					
						id = tonumber(row["id"])
						accountid = tonumber(row["account"])
					
					end
					
					if (accountid) then
						local qh2 = dbQuery(connection, "SELECT * FROM users WHERE id='" .. accountid .. "'")
						local result2 = dbPoll ( qh2, -1 )
						if result2 then
							for _2, row2 in ipairs ( result2 ) do
							
								admin = tonumber(row2["admin"])
								serial = row2["mtaserial"]
								ip = row2["ip"]							
							end						
							if (admin) > (getElementData(thePlayer, "char.adminlevel")) then
								outputChatBox("#ff0000[Falha]: #ffffffVocê não tem permissão", thePlayer,  255, 255, 255, true)
								return
							end
							
							    if tttime == 0 then
					                text = "Eterno"
			             	    else
					               text = tttime .. " Hora"
				                end
						    if tttime == 0 then
					            dbExec(connection ,"INSERT INTO bans SET accountid=?, bannedBy=?, timeZone=?, playerSerial=?, reason = ?, playername=?", accountid, adminName ,23414590357, serial, reason, targetPlayer)
				            else
				              	dbExec(connection ,"INSERT INTO bans SET accountid=?, bannedBy=?, timeZone=?, playerSerial=?, reason = ?, playername=?", accountid, adminName ,getRealTime()["timestamp"]+duration, serial, reason, targetPlayer)
				            end
								
								setElementData(thePlayer, "admin.ban", getElementData(thePlayer, "admin.ban") + 1)
								dbExec(connection, "UPDATE users SET banned=1, banned_by=?, banned_reason=? WHERE id=?", adminName, reason, accountid)
								
				                outputChatBox("#4169E1[BAN Offline]: #ffffff" ..adminName .. " baniu " .. targetPlayerName .. "", root,  255, 255, 255, true)
				                outputChatBox("#4169E1[BAN Offline]: #ffffff" .. text .. " - Motivo: #4169E1" .. reason .. "", root,  255, 255, 255, true)
						end
					end
				else
					outputChatBox("#ff0000[Error]: #ffffffNenhum resultado encontrado", thePlayer, 255, 255, 255, true)
			   end
			else
			outputChatBox("#ff0000[Error]: #ffffffVocê não pode banir um administrador superior a você", thePlayer, 124, 9, 9, true)
		    outputChatBox("[BAN]:#ffffff "..adminName.." tentou banir um administrador do servidor", targetPlayer, 124, 9, 9, true) -- Quando um administrador tentar banir outro administrador, então aparece para todos administradores essa mensaguem
			end
		 end
	  end
   end
end)

addCommandHandler( "desbanir", 
	function (playerSource, cmd, target, ...)
		if getElementData(playerSource, "char.adminlevel") >= 5 then
			local reason = table.concat ( { ... }, " " )
			local acc
			local bannedNames = {}
			local bannedSerials = {}
			local bannedAccs = {}
			local bannedBy = {}
			if target and reason then
				local query = dbQuery ( connection, "SELECT * FROM `bans`" )
				local result = dbPoll ( query, -1 )
				if result then
					for k, rows in ipairs ( result ) do
						if string.find( rows["playername"]:lower(), target:lower() ) then
							table.insert ( bannedNames, rows["playername"] )
							table.insert ( bannedSerials, rows["playerSerial"] )
							table.insert ( bannedAccs, rows["accountid"] )
							table.insert ( bannedBy, rows["bannedBy"] )
						end
					end
				else
					outputChatBox("#ff0000[Error]: #ffffffNão foi possível encontrar uma punição no nome dado", playerSource, 255, 255, 255, true)
				end
				if #bannedNames > 1 then
					outputChatBox("#4169E1[SERVER NAME]: #ffffffTodas punições existentes do servidor", playerSource, 255, 255, 255, true)
					for k, bans in ipairs ( bannedNames ) do
					    outputChatBox(bans, playerSource, 208, 101, 29, true)
					end
					bannedName = nil
					bannedSerial = nil
					bannedAccs = nil
					bannedBy = nil
					return
				end
				if #bannedNames == 0 then
					outputChatBox("#ff0000[Error]: #ffffffNenhuma punição encontrada", playerSource, 124, 9, 9, true)
					return
				end
				local exec = dbExec ( connection, "DELETE FROM bans WHERE playername = ?", bannedNames[1])
				local exec = dbExec ( connection, "UPDATE `users` SET banned = 0 WHERE `id` = ?", bannedAccs[1])
				outputChatBox("#4169E1[SERVER NAME]: #ffffffVocê desbaniu o jogador com sucesso", playerSource, 255, 255, 255, true)
				bannedName = nil
				bannedSerial = nil
				bannedAccs = nil
				bannedBy = nil
			else
				outputChatBox ("#4169E1[Use]: #ffffff/" .. cmd .. " [Nome Completo] [Motivo]", playerSource, 255, 255, 255, true)
			end
		end
	end
)

 

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