Ulysses

General => Developers Corner => Topic started by: TheMilkMan on June 08, 2019, 06:12:41 PM

Title: Toggle between !admin and !unadmin
Post by: TheMilkMan on June 08, 2019, 06:12:41 PM
1. Toggle for !admin to also do !unadmin when pressing it again
Also How do I restrict admin powers unless you're in admin mode

Current Code for this:
Code: [Select]
function ulx.admin( calling_ply, should_revoke )

if not should_revoke then
calling_ply:GodEnable()
else
calling_ply:GodDisable()
end

if not should_revoke then
calling_ply:SetModel( "models/player/combine_super_soldier.mdl" )
end

if not should_revoke then
ulx.fancyLogAdmin( calling_ply, true, "#A is now administrating" )
end
end
local admin = ulx.command( "Admin", "ulx admin", ulx.admin, { "!admin", "!admin"}, true )
admin:addParam{ type=ULib.cmds.BoolArg, invisible=true }
admin:defaultAccess( ULib.ACCESS_SUPERADMIN )
admin:help( "Noclip, & God Mode yourself" )
admin:setOpposite( "ulx unadmin", { _, true }, "!unadmin", true )


function ulx.unadmin( calling_ply, should_revoke )
if not should_revoke then
ulx.fancyLogAdmin( calling_ply, true, "#A has stopped administrating" )
end

if not should_revoke then
local jobTable = calling_ply:getJobTable()

    if not jobTable then return self.Sandbox.PlayerSetModel(ply) end

    if jobTable.PlayerSetModel then
        local model = jobTable.PlayerSetModel(ply)
        if model then ply:SetModel(model) return end
    end

    local EndModel = ""
    if GAMEMODE.Config.enforceplayermodel then
        if istable(jobTable.model) then
            local ChosenModel = string.lower(calling_ply:getPreferredModel(calling_ply:Team()) or "")

            local found
            for _, Models in pairs(jobTable.model) do
                if ChosenModel == string.lower(Models) then
                    EndModel = Models
                    found = true
                    break
                end
            end

            if not found then
                EndModel = jobTable.model[math.random(#jobTable.model)]
            end
        else
            EndModel = jobTable.model
        end

        calling_ply:SetModel(EndModel)
    else
        local cl_playermodel = ply:GetInfo("cl_playermodel")
        local modelname = player_manager.TranslatePlayerModel(cl_playermodel)
        calling_ply:SetModel(calling_ply:getPreferredModel(calling_ply:Team()) or modelname)
    end

    calling_ply.darkrp.PlayerSetModel( ply )

    calling_ply:SetupHands()
end
end
local admin = ulx.command( "Unadmin", "ulx unadmin", ulx.unadmin, { "!unadmin", "!unadmin"}, true)
unadmin:addParam{ type=ULib.cmds.BoolArg, invisible=true }
unadmin:defaultAccess( ULib.ACCESS_SUPERADMIN )
unadmin:help( "Noclip, & God Mode yourself" )
unadmin:setOpposite( "ulx admin", { _, true }, "!admin", true )
Title: Re: Toggle between !admin and !unadmin
Post by: nated0708gqiaa on June 10, 2019, 11:58:13 PM
Are you trying to make it so where the command needs to be on a certain job or...
Title: Re: Toggle between !admin and !unadmin
Post by: I_AM_TOOD on June 18, 2019, 09:25:42 PM
For some reason "!unadmin" isn't revoking godmode. It should, but isn't...
Title: Re: Toggle between !admin and !unadmin
Post by: mark272 on June 26, 2019, 08:39:22 AM
I think you didn’t set the should_revoke or how its called to false.