Помощь, решение ошибок

Здравствуйте, предлагаю вам свою помощь, можете писать что вам нужно прям в этой теме или мне в личку

Привет! Я хочу убрать полиции возможность выдавать лицензии игрокам через c меню и команду /givelicence ( Выдавать может только Мэр)
Есть код

function DarkRP.hooks:canGiveLicense(ply, target)
    -- Mayors can hand out licenses
    if ply:isMayor() then return true end

          
    local reason = DarkRP.getPhrase("incorrect_job", "/givelicense")

          
    local players = player.GetAll()
    -- Chiefs can if there is no mayor
    local mayorExists = #fn.Filter(plyMeta.isMayor, players) > 0
    if mayorExists then return false, reason end

          
    if ply:isChief() then return true end

          
    -- CPs can if there are no chiefs nor mayors
    local chiefExists = #fn.Filter(plyMeta.isChief, players) > 0
    if chiefExists then return false, reason end

          
    if ply:isCP() then return true end

          
    return false, reason
end

По пути E:\ServerGmod\steamapps\common\GarrysModDS\garrysmod\gamemodes\darkrp\gamemode\modules\police/sv.init.lua
Я этот код заменил на

function DarkRP.hooks:canGiveLicense(ply, target)
    local reason = DarkRP.getPhrase("incorrect_job", "/givelicense")

    -- Mayors can hand out licenses
    if ply:isMayor() then return true end
    
    return false, reason
end

Но ничего не работает. Как исправить?

local function GiveLicense(ply)
    local noMayorExists = fn.Compose{fn.Null, fn.Curry(fn.Filter, 2)(ply.isMayor), player.GetAll}

    local canGiveLicense = fn.FOr{
        ply.isMayor, -- Mayors can hand out licenses
    }

    if not canGiveLicense(ply) then
        DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("incorrect_job", "/givelicense"))
        return ""
    end

    local LookingAt = ply:GetEyeTrace().Entity
    if not IsValid(LookingAt) or not LookingAt:IsPlayer() or LookingAt:GetPos():DistToSqr(ply:GetPos()) > 10000 then
        DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", "player"))
        return ""
    end

    DarkRP.notify(LookingAt, 0, 4, DarkRP.getPhrase("gunlicense_granted", ply:Nick(), LookingAt:Nick()))
    DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("gunlicense_granted", ply:Nick(), LookingAt:Nick()))
    LookingAt:setDarkRPVar("HasGunlicense", true)

    return ""
end
DarkRP.defineChatCommand("givelicense", GiveLicense)

Это вставить вместо?

function DarkRP.hooks:canGiveLicense(ply, target)
    local reason = DarkRP.getPhrase("incorrect_job", "/givelicense")

    -- Mayors can hand out licenses
    if ply:isMayor() then return true end
    
    return false, reason
end

а ты используешь darkrpmodification?

Использую

можешь сразу в cmenu сделать в принципе В клиент часть

Option("Выдать лицензию", "icon16/page_add.png", function(self)
	RunConsoleCommand("darkrp", "givelicense")
end, function()
	local ply = LocalPlayer()
	local noMayorExists = fn.Compose{fn.Null, fn.Curry(fn.Filter, 2)(ply.isMayor), player.GetAll}
	local canGiveLicense = fn.FOr{ply.isMayor, fn.FAnd{noMayorExists}, fn.FAnd{noMayorExists}}

	return canGiveLicense(ply)
end)

в sh часть

properties.Add("givelicense", {
	MenuLabel = "Дать лицензию",
	Order = 80,
	MenuIcon = "icon16/page_add.png",

	Filter = function( self, ent, ply )
		local noMayorExists = fn.Compose{fn.Null, fn.Curry(fn.Filter, 2)(ply.isMayor), player.GetAll}

		local canGiveLicense = fn.FOr{
			ply.isMayor, -- Mayors can hand out licenses
		}

		if !canGiveLicense(ply) then
			return false
		end

		return IsValid( ent ) && ent:IsPlayer() && !ent:getDarkRPVar("HasGunlicense")
	end,
	Action = function( self, ent )
		self:MsgStart()
			net.WriteEntity(ent)
		self:MsgEnd()
	end,
	Receive = function( self, length, ply )
		local ent = net.ReadEntity()

		if !(self:Filter(ent, ply)) then return end

		DarkRP.notify(ent, 0, 4, DarkRP.getPhrase("gunlicense_granted", ply:Nick(), ent:Nick()))
		DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("gunlicense_granted", ply:Nick(), ent:Nick()))
		ent:setDarkRPVar("HasGunlicense", true)
	end
})

все пробуй код выше

Это работает.Но теперь Мэр тоже не может выдавать лицензии

Как исправить что мэру нельзя?

попробуй обновил код

Мэр все еще не может выдавать лицензии. Кстати кнопки выдачи лицензии появилось 2

старую то удали… а в професии стоит
mayor = true,
?

Стоит, и код я заменил

так ожидай щас

No problem

function DarkRP.hooks:canGiveLicense(ply, target)
    
    if ply:isMayor() then return true end

    local reason = DarkRP.getPhrase("incorrect_job", "/givelicense")

    local players = player.GetAll()

    return false, reason
end

в sv_init

В E:\ServerGmod\steamapps\common\GarrysModDS\garrysmod\gamemodes\darkrp\gamemode\modules\police/sv.init.lua?

где ты и писал
E:\ServerGmod\steamapps\common\GarrysModDS\garrysmod\gamemodes\darkrp\gamemode\modules\police/sv.init.lua

Я уже нашел,но спасибо
Ща чекну

Не работает. В конец кода это добавлять же надо? И + до сих пор 2 кнопки выдачи лицензии

убери одну
нет не в конец
нужно заменить на этот




function DarkRP.hooks:canGiveLicense(ply, target)
    -- Mayors can hand out licenses
    if ply:isMayor() then return true end

          
    local reason = DarkRP.getPhrase("incorrect_job", "/givelicense")

          
    local players = player.GetAll()
    -- Chiefs can if there is no mayor
    local mayorExists = #fn.Filter(plyMeta.isMayor, players) > 0
    if mayorExists then return false, reason end

          
    if ply:isChief() then return true end

          
    -- CPs can if there are no chiefs nor mayors
    local chiefExists = #fn.Filter(plyMeta.isChief, players) > 0
    if chiefExists then return false, reason end

          
    if ply:isCP() then return true end

          
    return false, reason
end