Jump to content

Custom unban command


Dzsozi (h03)

Recommended Posts

Hello guys! I would like to make my own admin system, and I bumped into a little problem. I would like to make an unban command, so I can unban banned players if I want to. I made these commands:

function banPlayerCommand(thePlayer, commandName, targetPlayer, hours, ...)
	if (exports.vice_core:isSuperAdmin(thePlayer)) then
		local target = exports.vice_core:getPlayerFromPartialName(targetPlayer)
		if not (target) or not (hours) or (tonumber(hours)<0) or not (...) then
			outputChatBox("[USAGE]:#FFFFFF /"..commandName.." [player] [hours] [reason]", thePlayer, 0, 180, 255,true)
		else
			hours = tonumber(hours)
			if (hours>168) then
				outputChatBox("Maximum 7 days. #00B4FF(168 hours).", thePlayer, 255, 255, 255, true)
			else
				local thePlayerPower = exports.vice_core:getPlayerAdminLevel(thePlayer)
				local targetPlayerPower = exports.vice_core:getPlayerAdminLevel(targetPlayer)
				banReason = table.concat({...}, " ")
				
				if (targetPlayerPower <= thePlayerPower) then
					local playerName = getPlayerName(thePlayer)
					
					local seconds = ((hours*30)) -- ((hours*60)*60) lowered it because of testing
					local rhours = hours
					-- text value
					if (hours==0) then
						hours = "Permanent"
					elseif (hours==1) then
						hours = "1 hour"
					else
						hours = hours .. " hours"
					end
					
					banReason = banReason .. ""
					local ban = banPlayer(target,true, false,true, thePlayer, banReason, seconds)
				else
					outputChatBox("#00B4FF"..getPlayerName(thePlayer).."#FFFFFF wanted to ban you.", targetPlayer, 255, 255, 255,true)
					exports.vice_notification:addNotification(thePlayer, "Access denied", "warning")
				end
			end
		end
	else
		exports.vice_notification:addNotification(thePlayer, "Access denied", "warning")
	end
end
addCommandHandler("ban", banPlayerCommand, false, false)

----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------

function unbanPlayerCommand(thePlayer, commandName, nickName)
	if (exports.vice_core:isSuperAdmin(thePlayer)) then
		local target = getBanNick(nickName)
		if not (target) then
			outputChatBox("[USAGE]:#FFFFFF /"..commandName.." [player]", thePlayer, 0, 180, 255,true)
		else
			outputChatBox("#00B4FF"..getPlayerName(target).."#FFFFFF successfully unbanned.", thePlayer, 255, 255, 255,true)
			for _,ban in ipairs(getBans())do
				if getBanNick(ban) == target then
					removeBan(target)
				end
			end
		end
	else
		exports.vice_notification:addNotification(thePlayer, "Access denied", "warning")
	end
end
addCommandHandler("unban", unbanPlayerCommand, false, false)

There's no problem with the exports, isSuperAdmin is defined, getPlayerFromPartialName works as well, the problem is that if I ban somebody, whose name is for example testguy1234, I can't unban him, because I get this error: Bad argument @ 'getBanNick' [Expected ban at argument 1, got string 'testguy1234'] or whatever name I write in instead of testguy1234. How to make a working unban command, so I can unban banned players' IP/serial depending on their nickname, or something like this, so they can join on the server again?

Link to comment

Try this 

function unbanPlayerCommand(thePlayer, commandName, nickName)
   if (exports.vice_core:isSuperAdmin(thePlayer)) then
       if nickName then
            local bans = getBans()
            for _,ban in ipairs(bans)do
                if getBanNick(ban) == nickName then
                   removeBan(ban)
                end
            end
            outputChatBox("#00B4FF"..nickName.."#FFFFFF successfully unbanned.", thePlayer, 255, 255, 255,true)
        else
            outputChatBox("[USAGE]:#FFFFFF /"..commandName.." [player]", thePlayer, 0, 180, 255,true)
        end
    else
        exports.vice_notification:addNotification(thePlayer, "Access denied", "warning")
    end
end
addCommandHandler("unban", unbanPlayerCommand, false, false)

 

Link to comment

I have got one more little problem, not related to the unban, but related to my admin system. I would like to make temporary vehicles that admins can create, and I would like to make a command for that, so admins can also delete the specified vehicle. Only problem with the delete command is that if I create for example 2 vehicles, so there are a vehicle with dbid -1 and dbid -2, I can't delete the vehicle with dbid -1, only if I delete dbid -2, so I can always delete only the last vehicle created, not the vehicle I would like to delete. Why is this happening? Here's my commands:

totalTempVehicles = 0

function createTempVehicle(thePlayer, commandName, ...)
	if (exports.vice_core:isHarmasAdmin(thePlayer)) then
		local args = {...}
		if (#args < 1) then
			outputChatBox("[USAGE]:#FFFFFF /"..commandName.." [vehicle] [color 1] [color 2]", thePlayer, 0, 180, 255,true)
		else
			local vehicleID = tonumber(args[1])
			
			local col1 = #args ~= 1 and tonumber(args[#args - 1]) or -1
			local col2 = #args ~= 1 and tonumber(args[#args]) or -1
			
			if not vehicleID then -- vehicle is specified as name
				local vehicleEnd = #args
				repeat
					vehicleID = getVehicleModelFromName(table.concat(args, " ", 1, vehicleEnd))
					vehicleEnd = vehicleEnd - 1
				until vehicleID or vehicleEnd == -1
				if vehicleEnd == -1 then
					exports.vice_notification:addNotification(thePlayer, "There is no vehicle with this name", "error")
					return
				elseif vehicleEnd == #args - 2 then
					col2 = math.random(0,100)
				elseif vehicleEnd == #args - 1 then
					col1 = math.random(0,100)
					col2 = math.random(0,100)
				end
			end
			
			local r = getPedRotation(thePlayer)
			local x, y, z = getElementPosition(thePlayer)
			x = x + ( ( math.cos ( math.rad ( r ) ) ) * 5 )
			y = y + ( ( math.sin ( math.rad ( r ) ) ) * 5 )
			
			local letter1 = string.char(math.random(65,90))
			local letter2 = string.char(math.random(65,90))
			local plate = letter1 .. letter2 .. math.random(0, 9) .. " " .. math.random(1000, 9999)
			
			if vehicleID then
				local veh = createVehicle(vehicleID, x, y, z, 0, 0, r, plate)
				
				if not (veh) then
					exports.vice_notification:addNotification(thePlayer, "There is no vehicle with this ID", "error")
				else
					setVehicleDamageProof(veh, false)

					totalTempVehicles = totalTempVehicles + 1
					local dbid = (-totalTempVehicles)
					
					setVehicleColor(veh, col1, col2, col1, col2)
					
					setElementInterior(veh, getElementInterior(thePlayer))
					setElementDimension(veh, getElementDimension(thePlayer))
					
					setVehicleOverrideLights(veh, 1)
					setVehicleEngineState(veh, false)
					setVehicleFuelTankExplodable(veh, false)
					
					setElementData(veh, "dbid", dbid)
					exports.vice_chat:sendMessageToAdmins("#00FFB4" .. getPlayerName(thePlayer) .. "#FFFFFF Created a temporary vehicle. #00FFB4(Vehicle: " .. getVehicleName(veh) .. " - ID: " .. dbid .. ")")
				end
			else
				exports.vice_notification:addNotification(thePlayer, "There is no vehicle with this ID", "error")
			end
		end
	end
end
addCommandHandler("veh", createTempVehicle, false, false)

----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------

function deleteVehicle(thePlayer, commandName, id)
	if (exports.vice_core:isSysAdmin(thePlayer)) then
		local dbid = tonumber(id)
		if not (dbid) then
			outputChatBox("[USAGE]:#FFFFFF /"..commandName.." [vehicle ID]", thePlayer, 0, 180, 255,true)
		else
			for _, v in ipairs(getElementsByType("vehicle")) do
				vehicleDBID = getElementData(v, "dbid")
				theVehicle = v
			end
			if (vehicleDBID == dbid) then
				if (vehicleDBID<0) then
					destroyElement(theVehicle)
				end
				exports.vice_notification:addNotification(thePlayer, "Vehicle successfully deleted", "success")
			else
				exports.vice_notification:addNotification(thePlayer, "There is no existing vehicle with this ID", "error")
			end
		end
	end
end
addCommandHandler("delveh", deleteVehicle, false, false)

 

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