Jump to content

AFK script


Noki

Recommended Posts

Hello,

I made this AFK script (client sided) and I cannot get it to work. It just returns bad arguments at 'isPedInVehicle' and 'isPedOnGround'.

local theVehicle = getPedOccupiedVehicle(localPlayer) 
function afkCommand(localPlayer) 
    if isPedInVehicle(localPlayer) then 
        outputChatBox("You must be on foot to use this command.", localPlayer, 255, 255, 255) 
    elseif isPedOnGround(localPlayer) then 
        if (getElementPosition(localPlayer) ~= 0) then 
            outputChatBox("You will be AFK in 5 seconds", localPlayer, 255, 255, 255) 
                setTimer(function () 
                    setElementDimension(localPlayer, math.random(10 - 1000)) 
                    setElementFrozen(localPlayer, true)  
                end, 5000, 1) 
        elseif (getElementDimension(localPlayer) >= 10) then 
            outputChatBox("You will be returned to the main dimension in 5 seconds", localPlayer, 255, 255, 255) 
                setTimer(function () 
                    setElementDimension(localPlayer, 0) 
                    setElementFrozen(localPlayer, false)  
                end, 5000, 1) 
        end 
    end 
end 
addCommandHandler("afk", afkCommand) 

If someone could help me, or guide me in the right direction, I'd much appreciate it.

Thank you, MTA community.

Edited by Guest
Link to comment

Try that

local theVehicle = getPedOccupiedVehicle(localPlayer) 
  
function afkCommand(localPlayer) 
    if (isPedInVehicle(localPlayer)) then 
        outputChatBox("You must be on foot to use this command.", localPlayer, 255, 255, 255) 
    elseif (isPedOnGround(localPlayer)) then 
        if (getElementPosition(localPlayer) ~= 0) then 
            outputChatBox("You will be AFK in 5 seconds", localPlayer, 255, 255, 255) 
                setTimer(function () 
                    setElementPosition(localPlayer, math.random(10 - 1000)) 
                    setElementFrozen(localPlayer, true) 
                end, 5000, 1) 
        elseif (getElementPosition(localPlayer) >= 10) then 
            outputChatBox("You will be returned to the main dimension in 5 seconds", localPlayer, 255, 255, 255) 
                setTimer(function () 
                    setElementPosition(localPlayer, 0) 
                    setElementFrozen(localPlayer, false) 
                end, 5000, 1) 
        end 
    end 
end 
addCommandHandler("afk", afkCommand) 

Link to comment

try this. but make it server side is better

function afkCommand( ) 
    if (isPedOnGround(localPlayer)) then 
        if (getElementDimension(localPlayer) < 10) then 
            outputChatBox("You will be AFK in 5 seconds", 255, 255, 255) 
            setTimer(function () 
                setElementDimension(localPlayer, math.random(10 - 1000)) 
                setElementFrozen(localPlayer, true) 
            end, 5000, 1) 
        elseif (getElementDimension(localPlayer) >= 10) then 
            outputChatBox("You will be returned to the main dimension in 5 seconds", 255, 255, 255) 
            setTimer(function () 
                setElementDimension(localPlayer, 0) 
                setElementFrozen(localPlayer, false) 
            end, 5000, 1) 
        end 
    else 
        outputChatBox("You must be on foot to use this command.", 255, 255, 255) 
    end 
end 
addCommandHandler("afk", afkCommand) 

Link to comment
function afkCommand( ) 
    if (isPedOnGround(client)) then 
        if (getElementDimension(client) < 10) then 
            outputChatBox("You will be AFK in 5 seconds", client, 255, 255, 255) 
            setTimer(function () 
                setElementDimension(client, math.random(10 - 1000)) 
                setElementFrozen(client, true) 
            end, 5000, 1) 
        elseif (getElementDimension(client) >= 10) then 
            outputChatBox("You will be returned to the main dimension in 5 seconds", client, 255, 255, 255) 
            setTimer(function () 
                setElementDimension(client, 0) 
                setElementFrozen(client, false) 
            end, 5000, 1) 
        end 
    else 
        outputChatBox("You must be on foot to use this command.", client, 255, 255, 255) 
    end 
end 
addCommandHandler("afk", afkCommand) 

Link to comment

Server side:

  
function afkCommand(thePlayer, cmd) 
    if isPedInVehicle(thePlayer) then 
        outputChatBox("You must be on foot to use this command.", thePlayer, 255, 255, 255) 
    else 
        if isPedOnGround(thePlayer) then 
            if getElementDimension(thePlayer) < 10 then 
                outputChatBox("You will be AFK in 5 seconds", thePlayer, 255, 255, 255) 
                setTimer( 
                    function() 
                        setElementDimension(thePlayer, math.random(10, 1000)) 
                        setElementFrozen(thePlayer, true) 
                    end, 5000, 1 
                ) 
            elseif getElementDimension(thePlayer) >= 10 and getElementDimension(thePlayer) <= 1000 then 
                outputChatBox("You will be returned to the main dimension in 5 seconds", thePlayer, 255, 255, 255) 
                setTimer( 
                    function() 
                        setElementDimension(thePlayer, 0) 
                        setElementFrozen(thePlayer, false) 
                    end, 5000, 1 
                ) 
            end 
        else 
            outputChatBox("You must be on the ground to use this command.", thePlayer, 255, 255, 255) 
        end 
    end 
end 
addCommandHandler("afk", afkCommand) 
  

Note: To make this script to work, don't make it client side. If you make it client side it will not work due to the arguments given in certain functions.

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