Jump to content

help


X-Flow

Recommended Posts

pls help me i am new to scripting and i made this script.

its loaded and running but it doesnt react when i type /test.

function Chopper ( command ) 
     local player = getLocalPlayer 
     local Account = getAccountName ( getPlayerAccount ( player ) ) 
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then 
          local Px, Py, Pz = getElementPosition ( player ) 
          local Rx, Ry, Rz = getElementRotation ( player ) 
          local vehicle = getPedOccupiedVehicle ( player ) 
          destroyElement ( vehicle ) 
          local vehicle2 = createVehicle ( 497, Px, Py, Pz, Rx, Ry, Rz ) 
          warpPedIntoVehicle ( player, vehicle2 ) 
     else outputChatBox ( "You can not execute this command!", player ) 
end 
  
addCommandHandler ( "test", Chopper ) 

Link to comment

Server side.

local uTimers = { } 
  
function Chopper ( player ) 
    local Account = getAccountName ( getPlayerAccount ( player ) ) 
    if isObjectInACLGroup ("user."..Account, aclGetGroup ( "Admin" ) ) then 
        local Px, Py, Pz = getElementPosition ( player ) 
        local Rx, Ry, Rz = getElementRotation ( player ) 
        if isPedInVehicle( player ) then 
            local vehicle = getPedOccupiedVehicle ( player ) 
            destroyElement ( vehicle ) 
        end  
        local vehicle2 = createVehicle ( 497, Px, Py, Pz, Rx, Ry, Rz ) 
        if isTimer( uTimers[ player ] ) then killTimer( uTimers[ player ] ) end 
        uTimers[ player ] = setTimer( 
            function( player,vehicle ) 
                warpPedIntoVehicle ( player, vehicle ) 
            end, 
        100, 
        1,player,vehicle2 )  
    else  
        outputChatBox ( "You can not execute this command!", player ) 
    end  
end 
addCommandHandler ( "test", Chopper ) 
  
addEventHandler( 'onPlayerQuit',root, 
    function( ) 
        uTimers[ source ] = nil 
    end 
)    

Updated again.

You can't use function getLocalPlayer in server side.

Edited by Guest
Link to comment

Ah yes,my bad :/

local uTimers = { } 
  
function Chopper ( player ) 
    local Account = getAccountName ( getPlayerAccount ( player ) ) 
    if isObjectInACLGroup ("user."..Account, aclGetGroup ( "Admin" ) ) then 
        local Px, Py, Pz = getElementPosition ( player ) 
        local Rx, Ry, Rz = getElementRotation ( player ) 
        if isPedInVehicle( player ) then 
            local vehicle = getPedOccupiedVehicle ( player ) 
            destroyElement ( vehicle ) 
        end  
        local vehicle2 = createVehicle ( 497, Px, Py, Pz, Rx, Ry, Rz ) 
        if isTimer( uTimers[ player ] ) then killTimer( uTimers[ player ] ) end 
        uTimers[ player ] = setTimer( 
            function( player,vehicle ) 
                warpPedIntoVehicle ( player, vehicle ) 
            end, 
        100, 
        1,player,vehicle2 )  
    else  
        outputChatBox ( "You can not execute this command!", player ) 
    end  
end 
addCommandHandler ( "test", Chopper ) 
  
addEventHandler( 'onPlayerQuit',root, 
    function( ) 
        uTimers[ source ] = nil 
    end 
)    

thank you so much, but what is uTimers?

uTimers is table stored timers.

As an index, we use the userdata Player.

If player quit remove index from table.

It is very convenient we can remove the timer current ( which we need ) player and not a all players.

Link to comment

I tested it now and it working only if rename cmd. :?

local uTimers = { } 
  
function Chopper ( player ) 
    local Account = getAccountName ( getPlayerAccount ( player ) ) 
    if isObjectInACLGroup ("user."..Account, aclGetGroup ( "Admin" ) ) then 
        local Px, Py, Pz = getElementPosition ( player ) 
        local Rx, Ry, Rz = getElementRotation ( player ) 
        if isPedInVehicle( player ) then 
            local vehicle = getPedOccupiedVehicle ( player ) 
            destroyElement ( vehicle ) 
        end  
        local vehicle2 = createVehicle ( 497, Px, Py, Pz, Rx, Ry, Rz ) 
        if isTimer( uTimers[ player ] ) then killTimer( uTimers[ player ] ) end 
        uTimers[ player ] = setTimer( 
            function( player,vehicle ) 
                warpPedIntoVehicle ( player, vehicle ) 
            end, 
        100, 
        1,player,vehicle2 )  
    else  
        outputChatBox ( "You can not execute this command!", player ) 
    end  
end 
addCommandHandler ( "_test", Chopper ) 
  
addEventHandler( 'onPlayerQuit',root, 
    function( ) 
        uTimers[ source ] = nil 
    end 
)    

cmd:/_test

Edited by Guest
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...