Jump to content

SetTimer Problem


OrbTanT

Recommended Posts

Good I am using a system of respawn player, and I'm trying to set the time to respawn after dying,more the setTimer is not working.

local spawnLocations = { 
{2171.90625, 1392.59765625, 10.8203125}, 
{2265.3674316406, 2398.3068847656, 10.8203125}, 
{2361.689453125, 2070.2077636719, 10.671875} 
} 
  
local spawnPlayer = function() 
    local chosenSpawnLocation = math.random(1,#spawnLocations) 
    spawnPlayer(source,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
end 
addEventHandler("onPlayerJoin",root,spawnPlayer) 
  
local spawnLocations = { 
{2171.90625, 1392.59765625, 10.8203125}, 
{2265.3674316406, 2398.3068847656, 10.8203125}, 
{2361.689453125, 2070.2077636719, 10.671875} 
} 
  
local respawnPlayer = function() 
    local chosenSpawnLocation = math.random(1,#spawnLocations) 
    spawnPlayer(source,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    setTimer ( source, 5000 ) 
end 
addEventHandler("onPlayerWasted",root,respawnPlayer) 

Link to comment
local spawnLocations = { 
{2171.90625, 1392.59765625, 10.8203125}, 
{2265.3674316406, 2398.3068847656, 10.8203125}, 
{2361.689453125, 2070.2077636719, 10.671875} 
} 
  
local spawnPlayer = function() 
    local chosenSpawnLocation = math.random(1,#spawnLocations) 
    spawnPlayer(source,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
end 
addEventHandler("onPlayerJoin",root,spawnPlayer) 
  
local spawnLocations = { 
{2171.90625, 1392.59765625, 10.8203125}, 
{2265.3674316406, 2398.3068847656, 10.8203125}, 
{2361.689453125, 2070.2077636719, 10.671875} 
} 
  
local respawnPlayer = function() 
    local chosenSpawnLocation = math.random(1,#spawnLocations) 
    spawnPlayer(source,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
  setTimer ( respawnPlayer, 5000, 5000, source) 
end 
addEventHandler("onPlayerWasted",root,respawnPlayer) 

Link to comment

How about this?

addEventHandler("onPlayerWasted",root, 
setTimer(function() 
    local chosenSpawnLocation = math.random(1,#spawnLocations) 
    spawnPlayer(source,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
end, 5000, 1) 
end) 

Link to comment
addEventHandler("onPlayerWasted",root, 
setTimer(function(tPlayer) 
    local chosenSpawnLocation = math.random(1,#spawnLocations) 
    spawnPlayer(tPlayer,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
    fadeCamera(tPlayer, true) 
    setCameraTarget(tPlayer, tPlayer) 
end, 5000, 1, source) 
end) 

You forgot to send the 'source' withing the setTimer, because setTimer has no source you have to send it with it.

Link to comment

Now appeared bad argument in: SpawnPlayer, FadeCamera, SetCameraTarget.

setTimer(function() 
    local chosenSpawnLocation = math.random(1,#spawnLocations) 
    spawnPlayer(source,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
end, 5000, 1) 
addEventHandler("onPlayerWasted", root, setTimer) 

Link to comment

setTimer is a code and you can't use it like that. Also, like I said, send 'source' with the timer.

Like this:

function spawnThePlayer() 
    setTimer(function(tPlayer) 
        local chosenSpawnLocation = math.random(1,#spawnLocations) 
        spawnPlayer(tPlayer,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
        fadeCamera(tPlayer, true) 
        setCameraTarget(tPlayer, tPlayer) 
    end, 5000, 1, source) 
end 
  
addEventHandler("onPlayerWasted", getRootElement(), spawnThePlayer) 

(Tested)

EDIT: Forgot to add it, it's working now x3

Link to comment

This is the complete script that I am using.

local spawnLocations = { 
{2171.90625, 1392.59765625, 10.8203125}, 
{2265.3674316406, 2398.3068847656, 10.8203125}, 
{2361.689453125, 2070.2077636719, 10.671875} 
} 
  
local spawnPlayer = function() 
    local chosenSpawnLocation = math.random(1,#spawnLocations) 
    spawnPlayer(source,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
end 
addEventHandler("onPlayerJoin",root,spawnPlayer) 
  
local spawnLocations = { 
{2171.90625, 1392.59765625, 10.8203125}, 
{2265.3674316406, 2398.3068847656, 10.8203125}, 
{2361.689453125, 2070.2077636719, 10.671875} 
} 
  
function spawnThePlayer() 
    setTimer(function(tPlayer) 
        local chosenSpawnLocation = math.random(1,#spawnLocations) 
        spawnPlayer(tPlayer,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
        fadeCamera(tPlayer, true) 
        setCameraTarget(tPlayer, tPlayer) 
    end, 5000, 1, source) 
end 
  
addEventHandler("onPlayerWasted", getRootElement(), spawnThePlayer) 

Link to comment
local spawnLocations = { 
{2171.90625, 1392.59765625, 10.8203125}, 
{2265.3674316406, 2398.3068847656, 10.8203125}, 
{2361.689453125, 2070.2077636719, 10.671875} 
} 
  
function spawnThePlayerDirectly() 
    local chosenSpawnLocation = math.random(1,#spawnLocations) 
    spawnPlayer(source,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
end 
addEventHandler("onPlayerJoin",root,spawnThePlayerDirectly) 
  
local spawnLocations = { 
{2171.90625, 1392.59765625, 10.8203125}, 
{2265.3674316406, 2398.3068847656, 10.8203125}, 
{2361.689453125, 2070.2077636719, 10.671875} 
} 
  
function spawnThePlayer() 
    setTimer(function(tPlayer) 
        local chosenSpawnLocation = math.random(1,#spawnLocations) 
        spawnPlayer(tPlayer,spawnLocations[chosenSpawnLocation][1],spawnLocations[chosenSpawnLocation][2],spawnLocations[chosenSpawnLocation][3]) 
        fadeCamera(tPlayer, true) 
        setCameraTarget(tPlayer, tPlayer) 
    end, 5000, 1, source) 
end 
  
addEventHandler("onPlayerWasted", getRootElement(), spawnThePlayer) 

Not sure or you can throw a function into a variable.

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