Jump to content

Need HELP at script [only admin resource]


Timiimit

Recommended Posts

Hi!

I have made script and i dont know how to make it that only I (Admin) would be able to use it. this is what i have:

  
function setElementSpeed(element, unit, speed) 
    if (unit == nil) then unit = 0 end 
    if (speed == nil) then speed = 0 end 
    speed = tonumber(speed) 
    local acSpeed = getElementSpeed(element, unit) 
    if (acSpeed~=false) then 
        local diff = speed/acSpeed 
        local x,y,z = getElementVelocity(element) 
        setElementVelocity(element,x*diff,y*diff,z*diff) 
        return true 
    end 
  
    return false 
end 
  
function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 
------ 
function turn(thePlayer) 
    local vehicle = getPedOccupiedVehicle(thePlayer) 
    if (not vehicle) then return end 
    local rX, rY, rZ = getVehicleRotation(vehicle) 
    local Speeds = getElementSpeed(vehicle, "mph") 
    setElementRotation(vehicle, rX, rY, rZ + 180) 
    local Boost = 0 -- You Can set this to 0  if You Dont Need it ! 
    setTimer(setElementSpeed,50,1,vehicle,1,-Speeds+Boost 
    outputChatBox("You turned your vehicle with " .. tostring(Speeds) .. " mph", thePlayer) 
end 
  
function bindTheKey() 
    for index, player in pairs(getElementsByType("player")) do 
        bindKey(player, "lctrl", "down", turn) 
        outputChatBox("#00FF00You can press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, bindTheKey) 
  
addEventHandler("onPlayerJoin", root, 
function() 
    bindKey(source, "lctrl", "down", turn) 
end) 

Link to comment
  
function setElementSpeed(element, unit, speed) 
    if (unit == nil) then unit = 0 end 
    if (speed == nil) then speed = 0 end 
    speed = tonumber(speed) 
    local acSpeed = getElementSpeed(element, unit) 
    if (acSpeed~=false) then 
        local diff = speed/acSpeed 
        local x,y,z = getElementVelocity(element) 
        setElementVelocity(element,x*diff,y*diff,z*diff) 
        return true 
    end 
  
    return false 
end 
  
function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 
------ 
function turn(thePlayer) 
    if not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(thePlayer)), aclGetGroup ( "Admin" ) ) then return end 
    local vehicle = getPedOccupiedVehicle(thePlayer) 
    if (not vehicle) then return end 
    local rX, rY, rZ = getVehicleRotation(vehicle) 
    local Speeds = getElementSpeed(vehicle, "mph") 
    setElementRotation(vehicle, rX, rY, rZ + 180) 
    local Boost = 0 -- You Can set this to 0  if You Dont Need it ! 
    setTimer(setElementSpeed,50,1,vehicle,1,-Speeds+Boost 
    outputChatBox("You turned your vehicle with " .. tostring(Speeds) .. " mph", thePlayer) 
end 
  
function bindTheKey() 
    for index, player in pairs(getElementsByType("player")) do 
        bindKey(player, "lctrl", "down", turn) 
        outputChatBox("#00FF00You can press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, bindTheKey) 
  
addEventHandler("onPlayerJoin", root, 
function() 
    bindKey(source, "lctrl", "down", turn) 
end) 

Link to comment

Try this, im not sure if it works, but give it a try.

function setElementSpeed(element, unit, speed) 
    if (unit == nil) then unit = 0 end 
    if (speed == nil) then speed = 0 end 
    speed = tonumber(speed) 
    local acSpeed = getElementSpeed(element, unit) 
    if (acSpeed~=false) then 
        local diff = speed/acSpeed 
        local x,y,z = getElementVelocity(element) 
 local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
        if isObjectInACLGroup ( "user." .. playerName, aclGetGroup ( "Admin" ) ) then 
        setElementVelocity(element,x*diff,y*diff,z*diff) 
        return true 
    end 
  
    return false 
end 
  
function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 
------ 
function turn(thePlayer) 
    local vehicle = getPedOccupiedVehicle(thePlayer) 
    if (not vehicle) then return end 
    local rX, rY, rZ = getVehicleRotation(vehicle) 
    local Speeds = getElementSpeed(vehicle, "mph") 
 local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
        if isObjectInACLGroup ( "user." .. playerName, aclGetGroup ( "Admin" ) ) then 
    setElementRotation(vehicle, rX, rY, rZ + 180) 
    local Boost = 0 -- You Can set this to 0  if You Dont Need it ! 
    setTimer(setElementSpeed,50,1,vehicle,1,-Speeds+Boost 
    outputChatBox("You turned your vehicle with " .. tostring(Speeds) .. " mph", thePlayer) 
end 
  
function bindTheKey() 
    for index, player in pairs(getElementsByType("player")) do 
        bindKey(player, "lctrl", "down", turn) 
        outputChatBox("#00FF00You can press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, bindTheKey) 
  
addEventHandler("onPlayerJoin", root, 
function() 
    bindKey(source, "lctrl", "down", turn) 
end) 

Link to comment

First, don't double post.

Second, your script is wrong, your account name variable is "accName" and you're using "playerName" in isObjectInACLGroup (copied from the wiki).

Third, you're checking in setElementSpeed function? that's really useless as you're also checking in turn function too.

Link to comment

Ok! i changed somethings and now it works!

this is script that i used(you can copy it if you want it):

  
function setElementSpeed(element, unit, speed) -- only work if element is moving! 
    if (unit == nil) then unit = 0 end 
    if (speed == nil) then speed = 0 end 
    speed = tonumber(speed) 
    local acSpeed = getElementSpeed(element, unit) 
    if (acSpeed~=false) then 
        local diff = speed/acSpeed 
        local x,y,z = getElementVelocity(element) 
        setElementVelocity(element,x*diff,y*diff,z*diff) 
        return true 
    end 
  
    return false 
end 
----- 
function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
        local x,y,z = getElementVelocity(element) 
        if (unit=="mph" or unit==1 or unit =='1') then 
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
        else 
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 
        end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 
------ 
function turn(thePlayer) 
  if isObjectInACLGroup( 'user.timiimit', aclGetGroup( 'Admin' ) ) then 
    local vehicle = getPedOccupiedVehicle(thePlayer) 
    if (not vehicle) then return end 
    local rX, rY, rZ = getVehicleRotation(vehicle) 
    local Speeds = getElementSpeed(vehicle, "mph") 
    setElementRotation(vehicle, rX, rY, rZ + 180) 
    local Boost = 10 -- You Can set this to 0  if You Dont Need it ! 
    setTimer(setElementSpeed,50,1,vehicle,1,-Speeds+Boost) 
    outputChatBox("You turned your vehicle with " .. tostring(Speeds) .. " mph", thePlayer) 
  else 
    outputChatBox("#FF0000you are not allowed to use this resource!!", thePlayer)  
  end 
end 
  
function bindTheKey() 
    if isObjectInACLGroup( 'user.timiimit', aclGetGroup( 'Admin' ) ) then 
        for index, player in pairs(getElementsByType("player")) do 
            bindKey(player, "lctrl", "down", turn) 
            outputChatBox("#00FF00You can press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) 
        end 
    else 
    outputChatBox("#FF0000you are not allowed to use this resource!!", thePlayer)  
    end 
end 
addEventHandler("onResourceStart", resourceRoot, bindTheKey) 
  
addEventHandler("onPlayerLogin", root, 
function() 
    if isObjectInACLGroup( 'user.timiimit', aclGetGroup( 'Admin' ) ) then 
       bindKey(source, "lctrl", "down", turn) 
    else 
       outputChatBox("#FF0000you are not allowed to use this resource!!", thePlayer)  
    end 
end) 
  

i know that many things here are unnessesary but i dont mind.

Edited by Guest
Link to comment

this for turning On

      
    function setElementSpeed(element, unit, speed) -- only work if element is moving! 
        if (unit == nil) then unit = 0 end 
        if (speed == nil) then speed = 0 end 
        speed = tonumber(speed) 
        local acSpeed = getElementSpeed(element, unit) 
        if (acSpeed~=false) then -- if true - element is valid, no need to check again 
            local diff = speed/acSpeed 
            local x,y,z = getElementVelocity(element) 
            setElementVelocity(element,x*diff,y*diff,z*diff) 
            return true 
        end 
      
        return false 
    end 
      
    function getElementSpeed(element,unit) 
        if (unit == nil) then unit = 0 end 
        if (isElement(element)) then 
                local x,y,z = getElementVelocity(element) 
                if (unit=="mph" or unit==1 or unit =='1') then 
                    return (x^2 + y^2 + z^2) ^ 0.5 * 100 
                else 
                    return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 
                end 
        else 
            outputDebugString("Not an element. Can't get speed") 
            return false 
        end 
    end 
      
    function turn(thePlayer) 
        if not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(thePlayer)), aclGetGroup ( "Admin" ) ) then return end 
            local vehicle = getPedOccupiedVehicle(thePlayer) 
            if (not vehicle) then return end 
               local rX, rY, rZ = getVehicleRotation(vehicle) 
               local Speeds = getElementSpeed(vehicle, "mph") 
                  setElementRotation(vehicle, rX, rY, rZ + 180) 
               local Boost = 0.001 
        setTimer(setElementSpeed,50,1,vehicle,1,-Speeds+Boost) 
        outputChatBox("#00FF00You turned your vehicle with #FF0000" .. tostring(Speeds) .. " mph", thePlayer) 
    end 
      
    function bindTheKey() 
        for index, player in pairs(getElementsByType("player")) do 
            bindKey(player, "lctrl", "down", turn) 
            outputChatBox("#00FF00You can press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) 
    end 
    end 
      
    function unBindTheKey() 
        for index, player in pairs(getElementsByType("player")) do 
            bindKey(player, "lctrl", "down", turn) 
            outputChatBox("#FF0000Turning disabled!", player, 255, 255, 255, true) 
        end 
    end 
addCommandHandler ( "turningON", turn ) 
  

Link to comment
function setElementSpeed(element, unit, speed) -- only work if element is moving! 
    if (unit == nil) then unit = 0 end 
    if (speed == nil) then speed = 0 end 
    speed = tonumber(speed) 
    local acSpeed = getElementSpeed(element, unit) 
    if (acSpeed~=false) then -- if true - element is valid, no need to check again 
        local diff = speed/acSpeed 
        local x,y,z = getElementVelocity(element) 
        setElementVelocity(element,x*diff,y*diff,z*diff) 
        return true 
    end 
    return false 
end 
  
function getElementSpeed(element,unit) 
    if (unit == nil) then unit = 0 end 
    if (isElement(element)) then 
            local x,y,z = getElementVelocity(element) 
            if (unit=="mph" or unit==1 or unit =='1') then 
                return (x^2 + y^2 + z^2) ^ 0.5 * 100 
            else 
                return (x^2 + y^2 + z^2) ^ 0.5 * 1.61 * 100 
            end 
    else 
        outputDebugString("Not an element. Can't get speed") 
        return false 
    end 
end 
  
function turn(thePlayer) 
        local vehicle = getPedOccupiedVehicle(thePlayer) 
        if (not vehicle) then return end 
           local rX, rY, rZ = getVehicleRotation(vehicle) 
           local Speeds = getElementSpeed(vehicle, "mph") 
              setElementRotation(vehicle, rX, rY, rZ + 180) 
           local Boost = 0.001 
    setTimer(setElementSpeed,50,1,vehicle,1,-Speeds+Boost) 
    outputChatBox("#00FF00You turned your vehicle with #FF0000" .. tostring(Speeds) .. " mph", thePlayer) 
end 
  
function bindTheKey(p) 
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(p)),aclGetGroup("Admin")) then 
    for index, player in pairs(getElementsByType("player")) do 
        bindKey(player, "lctrl", "down", turn) 
        outputChatBox("#00FF00You can press #0000FF'left ctrl' #00FF00in vehicle to turn for 180 degrees!", player, 255, 255, 255, true) 
          end 
     end 
end 
addCommandHandler("turningON",bindTheKey) 
  
function unBindTheKey(p) 
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(p)),aclGetGroup("Admin")) then 
    for index, player in pairs(getElementsByType("player")) do 
        unbindKey(player, "lctrl", "down", turn) 
        outputChatBox("#FF0000Turning disabled!", player, 255, 255, 255, true) 
          end 
     end 
end 
addCommandHandler("turningOFF",unBindTheKey) 

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