Jump to content

Help with Script


maky55

Recommended Posts

I have made a script to respawn Vehicles and I wanted to output a message to the chatbox that states the players name, is this possible? Here is the script (server side):

function respawn() 
local accountname = getAccountName (getPlayerAccount(source)) 
if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "Admin" ) ) then 
outputChatBox("") 
setTimer(function () 
local vehicles = getElementsByType ( "vehicle" )  
for k, vehicle in ipairs ( vehicles ) do 
if checkEmpty( vehicle ) then 
local seats = getVehicleMaxPassengers(vehicle) 
resetVehicleIdleTime ( vehicle )  
respawnVehicle ( vehicle ) 
end 
end 
end, 10000, 1) 
end  
end 
addEvent( "respawn", true ) 
addEventHandler( "respawn", getRootElement(), respawn ) 
  
function checkEmpty( vehicle ) 
local passengers = getVehicleMaxPassengers( vehicle ) 
if type( passengers ) == 'number' then 
for seat = 0, passengers do 
if getVehicleOccupant( vehicle, seat ) then 
return false 
end 
end 
end 
return true 
end 

Thanks

Link to comment
function respawn ( ) 
    local accountname = getAccountName ( getPlayerAccount ( client ) ) 
    if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "Admin" ) ) then 
        outputChatBox ( "" ) 
        setTimer ( 
            function ( ) 
                for _, vehicle in ipairs ( getElementsByType ( "vehicle" ) ) do 
                    if checkEmpty ( vehicle ) then 
                        local seats = getVehicleMaxPassengers ( vehicle ) 
                        resetVehicleIdleTime ( vehicle ) 
                        respawnVehicle ( vehicle ) 
                    end 
                end 
            end 
            , 10000, 1 
        ) 
        outputChatBox ( getPlayerName ( client ) .." has respawned all empty vehicles.", root, 255, 50, 0 ) 
    end 
end 
addEvent ( "respawn", true ) 
addEventHandler ( "respawn", getRootElement(), respawn ) 
  
function checkEmpty ( vehicle ) 
    local passengers = getVehicleMaxPassengers ( vehicle ) 
    if ( type ( passengers ) == 'number' ) then 
        for seat = 0, passengers do 
            if getVehicleOccupant ( vehicle, seat ) then 
                return false 
            end 
        end 
    end 
  
    return true 
end 

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