Jump to content

Restringuir comando a Admin


Finijumper

Recommended Posts

¿Como podría restringir el comando de este script para que solo los usen los Admins?

function allvehiclesaredoomed() 
    -- get a table of all the vehicles that exist and loop through it 
    vehicles = getElementsByType("vehicle") 
    for i,v in ipairs(vehicles) do 
        -- destroy every vehicle. 
        destroyElement(v) 
    end 
end 
--The command handler below will destroy all vehicles once 
--you enter /vdoom in the chat box or vdoom in the game console. 
addCommandHandler("vdoom", allvehiclesaredoomed) 
--This is very useful if you use the freeroam resource and some 
--heartless players start spawn spamming. 
--You can also set it on a timer to have your server clear all 
--vehicles ever 60 minutes, (1 hour).  Timer below: 
-- (treure --)setTimer(allvehiclesaredoomed, 3600000, 0) 

Se que no es difícil pero no consigo hacerlo :(

Link to comment
  
    function allvehiclesaredoomed(player) 
 local accName = getAccountName ( getPlayerAccount ( player ) ) 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then  
        vehicles = getElementsByType("vehicle") 
        for i,v in ipairs(vehicles) do 
            destroyElement(v) 
        end 
end 
    end 
    addCommandHandler("vdoom", allvehiclesaredoomed) 
  

Link to comment

Muchísimas gracias :D También necesito restringir esto. Te agradecería que me ayudaras.

local thisResourceRoot = getResourceRootElement(getThisResource()) 
  
function setCarSpeed ( cmd, boosts, speeds ) 
    local boost = tonumber(boosts) 
    local speed = tonumber(speeds) 
    if boost >= 1 and boost <= 100 then 
        outputChatBox ( "Speed boost set to " ..boosts.. ". Use /carspeed 0 0 to disable." ) 
        carboost = (boost * 0.002) + 1 
        carbrake = (boost * 0.005) + 1 
        if speed ~= nil then  
            local speedk = math.ceil(speed * 1.609344) 
            local speedks = tostring(speedk) 
            outputChatBox ( "Max speed set to " ..speeds.. "MPH / " ..speedks.. " KM/H. Use /carspeed [boost] [maxspeed]  to change." ) 
            carspeed = speed 
        end 
        addEventHandler ( "onClientRender", getLocalPlayer(), checkSpeed ) 
    elseif boost == 0 then 
        removeEventHandler ( "onClientRender", getLocalPlayer(), checkSpeed ) 
        outputChatBox ( "Speed boost disabled." ) 
        carboost = nil 
        carspeed = 500 
    end 
end 
addCommandHandler ( "carspeed" , setCarSpeed ) 
  
function getPlayerSpeed( source, mode ) 
    if (isPedInVehicle( source ) == true) then 
        vehicle = getPedOccupiedVehicle( source ) 
        if (mode == "MPH" or mode == 1) then 
            return math.floor(getDistanceBetweenPoints3D(0,0,0,getElementVelocity(vehicle)) * 100 * 1.14) 
        end 
        if (mode == "KMH" or mode == 2) then 
            return math.floor(getDistanceBetweenPoints3D(0,0,0,getElementVelocity(vehicle)) * 100 * 1.61 * 1.14) 
        end 
    else 
        return 0 
    end 
end 
  
function checkSpeed() 
    local vehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    if ( getControlState ( "accelerate") ) then 
        local speed = getPlayerSpeed (getLocalPlayer(), 1) 
        if speed >= 1 and speed <= carspeed then 
                local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
            local x, y, z = getElementVelocity(vehicle) 
            setElementVelocity(vehicle, x*carboost, y*carboost, z) 
        end 
    end 
    if ( getControlState ( "brake_reverse") ) then       
        local speed = getPlayerSpeed (getLocalPlayer(), 1) 
        if speed >= 38 then 
                local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
            local x, y, z = getElementVelocity(vehicle) 
            setElementVelocity(vehicle, x/carbrake, y/carbrake, z) 
        end 
    end 
end 
  
function thisResourceStart () 
    if carboost ~= nil then carboost = nil end 
    carspeed = 500 
end 
addEventHandler ( "onClientResourceStart", thisResourceRoot, thisResourceStart ) 

Link to comment

Intenta con esto

local thisResourceRoot = getResourceRootElement(getThisResource()) 
  
function setCarSpeed ( cmd, boosts, speeds, player ) 
    local accName = getAccountName ( getPlayerAccount ( player ) ) 
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then 
        local boost = tonumber(boosts) 
        local speed = tonumber(speeds) 
        if boost >= 1 and boost <= 100 then 
            outputChatBox ( "Speed boost set to " ..boosts.. ". Use /carspeed 0 0 to disable." ) 
            carboost = (boost * 0.002) + 1 
            carbrake = (boost * 0.005) + 1 
            if speed ~= nil then 
                local speedk = math.ceil(speed * 1.609344) 
                local speedks = tostring(speedk) 
                outputChatBox ( "Max speed set to " ..speeds.. "MPH / " ..speedks.. " KM/H. Use /carspeed [boost] [maxspeed]  to change." ) 
                carspeed = speed 
            end 
            addEventHandler ( "onClientRender", getLocalPlayer(), checkSpeed ) 
        elseif boost == 0 then 
            removeEventHandler ( "onClientRender", getLocalPlayer(), checkSpeed ) 
            outputChatBox ( "Speed boost disabled." ) 
            carboost = nil 
            carspeed = 500 
        end 
    else 
        outputChatBox("No eres Administrador") 
    end 
end 
addCommandHandler ( "carspeed" , setCarSpeed ) 
  
function getPlayerSpeed( source, mode ) 
    if (isPedInVehicle( source ) == true) then 
        vehicle = getPedOccupiedVehicle( source ) 
        if (mode == "MPH" or mode == 1) then 
            return math.floor(getDistanceBetweenPoints3D(0,0,0,getElementVelocity(vehicle)) * 100 * 1.14) 
        end 
        if (mode == "KMH" or mode == 2) then 
            return math.floor(getDistanceBetweenPoints3D(0,0,0,getElementVelocity(vehicle)) * 100 * 1.61 * 1.14) 
        end 
    else 
        return 0 
    end 
end 
  
function checkSpeed() 
    local vehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    if ( getControlState ( "accelerate") ) then 
        local speed = getPlayerSpeed (getLocalPlayer(), 1) 
        if speed >= 1 and speed <= carspeed then 
                local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
            local x, y, z = getElementVelocity(vehicle) 
            setElementVelocity(vehicle, x*carboost, y*carboost, z) 
        end 
    end 
    if ( getControlState ( "brake_reverse") ) then      
        local speed = getPlayerSpeed (getLocalPlayer(), 1) 
        if speed >= 38 then 
                local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
            local x, y, z = getElementVelocity(vehicle) 
            setElementVelocity(vehicle, x/carbrake, y/carbrake, z) 
        end 
    end 
end 
  
function thisResourceStart () 
    if carboost ~= nil then carboost = nil end 
    carspeed = 500 
end 
addEventHandler ( "onClientResourceStart", thisResourceRoot, thisResourceStart ) 

No lo probé, dime si te funcionó

Link to comment
Intenta con esto
local thisResourceRoot = getResourceRootElement(getThisResource()) 
  
function setCarSpeed ( cmd, boosts, speeds, player ) 
    local accName = getAccountName ( getPlayerAccount ( player ) ) 
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then 
        local boost = tonumber(boosts) 
        local speed = tonumber(speeds) 
        if boost >= 1 and boost <= 100 then 
            outputChatBox ( "Speed boost set to " ..boosts.. ". Use /carspeed 0 0 to disable." ) 
            carboost = (boost * 0.002) + 1 
            carbrake = (boost * 0.005) + 1 
            if speed ~= nil then 
                local speedk = math.ceil(speed * 1.609344) 
                local speedks = tostring(speedk) 
                outputChatBox ( "Max speed set to " ..speeds.. "MPH / " ..speedks.. " KM/H. Use /carspeed [boost] [maxspeed]  to change." ) 
                carspeed = speed 
            end 
            addEventHandler ( "onClientRender", getLocalPlayer(), checkSpeed ) 
        elseif boost == 0 then 
            removeEventHandler ( "onClientRender", getLocalPlayer(), checkSpeed ) 
            outputChatBox ( "Speed boost disabled." ) 
            carboost = nil 
            carspeed = 500 
        end 
    else 
        outputChatBox("No eres Administrador") 
    end 
end 
addCommandHandler ( "carspeed" , setCarSpeed ) 
  
function getPlayerSpeed( source, mode ) 
    if (isPedInVehicle( source ) == true) then 
        vehicle = getPedOccupiedVehicle( source ) 
        if (mode == "MPH" or mode == 1) then 
            return math.floor(getDistanceBetweenPoints3D(0,0,0,getElementVelocity(vehicle)) * 100 * 1.14) 
        end 
        if (mode == "KMH" or mode == 2) then 
            return math.floor(getDistanceBetweenPoints3D(0,0,0,getElementVelocity(vehicle)) * 100 * 1.61 * 1.14) 
        end 
    else 
        return 0 
    end 
end 
  
function checkSpeed() 
    local vehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    if ( getControlState ( "accelerate") ) then 
        local speed = getPlayerSpeed (getLocalPlayer(), 1) 
        if speed >= 1 and speed <= carspeed then 
                local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
            local x, y, z = getElementVelocity(vehicle) 
            setElementVelocity(vehicle, x*carboost, y*carboost, z) 
        end 
    end 
    if ( getControlState ( "brake_reverse") ) then      
        local speed = getPlayerSpeed (getLocalPlayer(), 1) 
        if speed >= 38 then 
                local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
            local x, y, z = getElementVelocity(vehicle) 
            setElementVelocity(vehicle, x/carbrake, y/carbrake, z) 
        end 
    end 
end 
  
function thisResourceStart () 
    if carboost ~= nil then carboost = nil end 
    carspeed = 500 
end 
addEventHandler ( "onClientResourceStart", thisResourceRoot, thisResourceStart ) 

No lo probé, dime si te funcionó

El scipt funciona, pero igualmente lo pueden hacer todos. Yo quiero que solo lo puedan hacer los Admins.

Link to comment

Me había equivocado, era esa parte del script la que quería restringir por eso no funcionaba :/

local root = getRootElement() 
boostTimer = false 
local currentlyBoosting = false 
  
function onCarDownResourceStart(resource) 
    bindKey("lalt", "down", startBoost) 
    bindKey("lalt", "up", stopBoost) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onCarDownResourceStart) 
  
  
function startBoost (key, keyState) 
    local vehicle = getPedOccupiedVehicle ( getLocalPlayer () ) 
    if ( vehicle ) then 
        if ( getVehicleController ( vehicle ) == getLocalPlayer () ) then 
            boostTimer = setTimer(startCarBoost, 50, 0, vehicle) 
            --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
            currentlyBoosting = true 
        else 
            outputChatBox( "You need to be the driver!", 255, 0, 0 ) 
        end 
    end 
end 
  
function startCarBoost(vehicle) 
    local vehSpeedX, vehSpeedY, vehSpeedZ = getElementVelocity ( vehicle ) 
    setElementVelocity ( vehicle, vehSpeedX*1.05, vehSpeedY*1.05, vehSpeedZ*1.05) 
end 
  
function stopBoost( key, keystate ) 
    if ( currentlyBoosting ) then 
        --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
        killTimer( boostTimer ) 
        currentlyBoosting = false 
    end 
end 

Link to comment

Debes ponerlo al inicio de la función. Por ejemplo acá:

function VerifiCar( cmd, boosts, speeds, player ) 
    local accName = getAccountName ( getPlayerAccount ( player ) ) -- Definimos accName como cuenta de usuario 
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then --- Verificamos si player es igual a accname 
         outputChatBox("Respuesta afirmativa") -- Si el player es igual a accname aparece este chat 
    else --- Ponemos un else, que funciona para saber si player no es igual a accName 
         outputChatBox("Respuesta Negativa") --- Aparece un chat que dice que es negativo 
    end --- cerramos el if 
end --- cerramos la funcion 
addCommandHandler ( "prueba" , VerifiCar) 

Creo que está bien explicado, si tienes alguna pregunta dime.

PD: Esto es para ayudarte con las variables y los if con tal de que aprendas a utilizarlos.

Link to comment

No se que estoy haciendo mal :(

local root = getRootElement() 
boostTimer = false 
local currentlyBoosting = false 
  
function onCarDownResourceStart(resource) 
     local accName = getAccountName ( getPlayerAccount ( player ) ) 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then 
    bindKey("lalt", "down", startBoost) 
    bindKey("lalt", "up", stopBoost) 
end 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onCarDownResourceStart) 
  
  
function startBoost (key, keyState) 
    local vehicle = getPedOccupiedVehicle ( getLocalPlayer () ) 
    if ( vehicle ) then 
        if ( getVehicleController ( vehicle ) == getLocalPlayer () ) then 
            boostTimer = setTimer(startCarBoost, 50, 0, vehicle) 
            --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
            currentlyBoosting = true 
        else 
            outputChatBox( "You need to be the driver!", 255, 0, 0 ) 
        end 
    end 
end 
  
function startCarBoost(vehicle) 
    local vehSpeedX, vehSpeedY, vehSpeedZ = getElementVelocity ( vehicle ) 
    setElementVelocity ( vehicle, vehSpeedX*1.05, vehSpeedY*1.05, vehSpeedZ*1.05) 
end 
  
function stopBoost( key, keystate ) 
    if ( currentlyBoosting ) then 
        --outputChatBox ( "boostTimer=" .. tostring(boostTimer) ) 
        killTimer( boostTimer ) 
        currentlyBoosting = false 
    end 
end 

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...