MontiVante

help with FadeCamera

Recommended Posts

hello, I come to ask for help is on the fadecamera of the login, I put a spawny and spawn makes the fadecamera not work, I would like to help me to make the fadecamera link with the spawn.

 

FadeCamera:

function setCameraOnPlayerJoin()
local mat = math.random(1,4)
fadeCamera(source, true, 5)    if mat == 1 then
    setCameraMatrix(source, -2816.0283203125, 2125.6923828125, 156.8657989502, -2720.1396484375, 1835.1181640625, 133.21673583984) 
    end
    if mat == 2 then
    setCameraMatrix(source, -1145.0048828125, 879.6533203125, 9.1189212799072, -1357.7978515625, 719.6279296875, 14.321132659912) 
    end
    if mat == 3 then
    setCameraMatrix(source, 1135.3759765625, -1977.408203125, 78.517211914063, 1413.7529296875, -1617.5576171875, 63.588264465332)
    end
    if mat == 4 then
    setCameraMatrix(source, 2160.0869140625, -102.408203125, 5.6070313453674, 1894.4580078125, -146.1396484375, 21.12876701355)
    end
end 
addEventHandler("onPlayerJoin", getRootElement(), setCameraOnPlayerJoin)

 

Spawn:

local randomSpawnTable =
{
    { 270.92654418945, -1986.3665771484, 797.52966308594 },
    { 270.92654418945, -1986.3665771484, 797.52966308594 },
    { 270.92654418945, -1986.3665771484, 797.52966308594 }
}
 
function randomSpawn( thePlayer, randomSpawnTable )
    local random = math.random( 1, #randomSpawnTable )
    spawnPlayer(
    thePlayer,
        randomSpawnTable[random][1],
        randomSpawnTable[random][2],
        randomSpawnTable[random][3]
    )

    setElementModel ( thePlayer, 312 )
    giveWeapon ( thePlayer, 46 )
    giveWeapon ( thePlayer, 9 )
    giveWeapon ( thePlayer, 25, 5000 ,true )
    giveWeapon ( thePlayer, 28, 5000 ,true )
    giveWeapon ( thePlayer, 31, 5000 ,true )
    giveWeapon ( thePlayer, 22, 5000 ,true )

end

function onPlayerJoin()
    setTimer(function(source)
        fadeCamera(source, true)
        setElementFrozen(source, true)
        setCameraTarget(source, source)
        randomSpawn(source, randomSpawnTable)
    end, 1000, 1, source)
end
addEventHandler("onPlayerJoin", root, onPlayerJoin)

function onPlayerLogin()
    setElementFrozen(source, false)
end
addEventHandler("onPlayerLogin", root, onPlayerLogin)

help I need the FadeCamera to work and that the spawn NO!! Buguee the FadeCamera.

Share this post


Link to post
  1. This should be client-side.

  2. addEventHandler("onClientPlayerJoin", localPlayer, 
    function()
        local camPositions = {
            {-2816.0283203125, 2125.6923828125, 156.8657989502, -2720.1396484375, 1835.1181640625, 133.21673583984},
            {-1145.0048828125, 879.6533203125, 9.1189212799072, -1357.7978515625, 719.6279296875, 14.321132659912},
            {1135.3759765625, -1977.408203125, 78.517211914063, 1413.7529296875, -1617.5576171875, 63.588264465332},
            {2160.0869140625, -102.408203125, 5.6070313453674, 1894.4580078125, -146.1396484375, 21.12876701355}
        }   
        fadeCamera(source, true, 5)
        setCameraMatrix(source, camPositions[math.random(1, #camPositions)]) 
    end)

    And this should be server-side.

  3. local randomSpawnTable = {
        { 270.92654418945, -1986.3665771484, 797.52966308594 },
        { 270.92654418945, -1986.3665771484, 797.52966308594 },
        { 270.92654418945, -1986.3665771484, 797.52966308594 }
    }
     
    local function randomSpawn(thePlayer)
        spawnPlayer(thePlayer, unpack(randomSpawnTable[math.random(1, #randomSpawnTable)]))
    
        setElementModel(thePlayer, 312)
        giveWeapon(thePlayer, 46)
        giveWeapon(thePlayer, 9)
        giveWeapon(thePlayer, 25, 5000, true)
        giveWeapon(thePlayer, 28, 5000, true)
        giveWeapon(thePlayer, 31, 5000, true)
        giveWeapon(thePlayer, 22, 5000, true)
    end
    
    local function restorePlayer(player)
        fadeCamera(player, true)
        setElementFrozen(source, true)
        setCameraTarget(player, source)
        randomSpawn(player)
    end
    
    addEventHandler("onPlayerJoin", root,  
    function()
        fadeCamera(player, false, 1000, 0, 0, 0)--> Set the color you want, and the time you want(but i think you wanted it to be 1000ms)
        setElementFrozen(source, false)
        setTimer(restorePlayer, 950, 1, source)--> You should't create a new function every time the event is called, and the timer is set.set it to slightly less than the timer, since it may not be that accuret.
    end)

     

  • Like 1

Share this post


Link to post
11 hours ago, santinet12 said:

It doesn't work bro

Whats the problem with it?

 

Edit:

fount it.Try this:

addEventHandler("onClientPlayerJoin", localPlayer, 
function()
    local camPositions = {
        {-2816.0283203125, 2125.6923828125, 156.8657989502, -2720.1396484375, 1835.1181640625, 133.21673583984},
        {-1145.0048828125, 879.6533203125, 9.1189212799072, -1357.7978515625, 719.6279296875, 14.321132659912},
        {1135.3759765625, -1977.408203125, 78.517211914063, 1413.7529296875, -1617.5576171875, 63.588264465332},
        {2160.0869140625, -102.408203125, 5.6070313453674, 1894.4580078125, -146.1396484375, 21.12876701355}
    }   
    fadeCamera(source, true, 5)
    setCameraMatrix(source, unpack(camPositions[math.random(1, #camPositions)])) 
end)

Only replace this on client-side.And it should work.

Edited by Pirulax

Share this post


Link to post
local camPositions = {
  {-2816.0283203125, 2125.6923828125, 156.8657989502, -2720.1396484375, 1835.1181640625, 133.21673583984},
  {-1145.0048828125, 879.6533203125, 9.1189212799072, -1357.7978515625, 719.6279296875, 14.321132659912},
  {1135.3759765625, -1977.408203125, 78.517211914063, 1413.7529296875, -1617.5576171875, 63.588264465332},
  {2160.0869140625, -102.408203125, 5.6070313453674, 1894.4580078125, -146.1396484375, 21.12876701355}
}   

addEventHandler("onClientResourceStart",resourceRoot, 
function()
	fadeCamera(true, 5)
	setCameraMatrix(unpack(camPositions[math.random(#camPositions)]))
end)

This code must work. onClientResourceStart event will be triggered after they join and have downloaded client script.
Notes:

1.onClientPlayerJoin is triggered for all players except the local player, as the local player joins the server before their client-side resources are started
2.fadeCamera and setCameraMatrix  doesn't have player parameter in client side

Share this post


Link to post
3 hours ago, IRBIS said:

local camPositions = {
  {-2816.0283203125, 2125.6923828125, 156.8657989502, -2720.1396484375, 1835.1181640625, 133.21673583984},
  {-1145.0048828125, 879.6533203125, 9.1189212799072, -1357.7978515625, 719.6279296875, 14.321132659912},
  {1135.3759765625, -1977.408203125, 78.517211914063, 1413.7529296875, -1617.5576171875, 63.588264465332},
  {2160.0869140625, -102.408203125, 5.6070313453674, 1894.4580078125, -146.1396484375, 21.12876701355}
}   

addEventHandler("onClientResourceStart",resourceRoot, 
function()
	fadeCamera(true, 5)
	setCameraMatrix(unpack(camPositions[math.random(#camPositions)]))
end)

This code must work. onClientResourceStart event will be triggered after they join and have downloaded client script.
Notes:

1.onClientPlayerJoin is triggered for all players except the local player, as the local player joins the server before their client-side resources are started
2.fadeCamera and setCameraMatrix  doesn't have player parameter in client side

Yeah, i was tired.

Share this post


Link to post

brother does not work.........

 

the functions that you have passed me does not work, the spawn works but the fadecamera does not, here is a picture of what the spawn does to the fadecamera.

*Note: image of what spawn affects the fadecamera.*

https://prnt.sc/iyz4y3

 

 

What I want is that the spawn does not affect the fadecamera, and I want the fadecamera to work normally but it does not buguee with the spawn.

*Note: Here is an image of how I want the spawn to be linked to the fadecamera.*

https://prnt.sc/iyzcue

*Copy Link and paste it into a tab*

 

Edited by santinet12

Share this post


Link to post

FadeCamera:

local camPositions = {
  {-2816.0283203125, 2125.6923828125, 156.8657989502, -2720.1396484375, 1835.1181640625, 133.21673583984},
  {-1145.0048828125, 879.6533203125, 9.1189212799072, -1357.7978515625, 719.6279296875, 14.321132659912},
  {1135.3759765625, -1977.408203125, 78.517211914063, 1413.7529296875, -1617.5576171875, 63.588264465332},
  {2160.0869140625, -102.408203125, 5.6070313453674, 1894.4580078125, -146.1396484375, 21.12876701355}
}   

addEventHandler("onPlayerJoin",getRootElement(),
function()
	fadeCamera(source,true,5)
	setCameraMatrix(source,unpack(camPositions[math.random(#camPositions)]))
end)

Spawn:

local randomSpawnTable = {
    { 270.92654418945, -1986.3665771484, 797.52966308594 },
    { 270.92654418945, -1986.3665771484, 797.52966308594 },
    { 270.92654418945, -1986.3665771484, 797.52966308594 }
}

addEventHandler("onPlayerLogin",getRootElement(),
function()
	spawnPlayer(source,unpack(randomSpawnTable[math.random(#randomSpawnTable)]))
	setCameraTarget(source,source)
	setElementModel(source, 312)
	giveWeapon(source,46)
	giveWeapon(source,9)
    giveWeapon(source,25,5000,true)
    giveWeapon(source,28,5000,true)
    giveWeapon(source,31,5000,true)
    giveWeapon(source,22,5000,true)
end)

 

  • Thanks 1

Share this post


Link to post

THANK YOU BRO, sorry for bothering you xd, but there is a problem, the fadecamera works well: D that I am proud, but the problem is when I log in not spawneo in the place that was going to disconnect, aparesco in the coordinates of spawn, I would like you to help me when one logue appears in the position that was when you disconnect not in the position of the spawn, help me with that bro xd.

Share this post


Link to post
43 minutes ago, santinet12 said:

THANK YOU BRO, sorry for bothering you xd, but there is a problem, the fadecamera works well: D that I am proud, but the problem is when I log in not spawneo in the place that was going to disconnect, aparesco in the coordinates of spawn, I would like you to help me when one logue appears in the position that was when you disconnect not in the position of the spawn, help me with that bro xd.

Use account data to store player element position and then spawn the player element at that saved position upon login.

setAccountData
getAccountData

Such as...

local randomSpawnTable = {
	{ x = 270.92654418945, y = -1986.3665771484, z = 797.52966308594, rotation = 0, model = 312, interior = 0, dimension = 0 },
	{ x = 270.92654418945, y = -1986.3665771484, z = 797.52966308594 },
	{ x = 270.92654418945, y = -1986.3665771484, z = 797.52966308594 }
}

-- Once the player logs in, let's spawn them to their saved position or a random spawnpoint
addEventHandler("onPlayerLogin", root, function(_, account)
	-- Get the saved x, y, z position from the account data
	local x, y, z = getAccountData(account, "posX"), getAccountData(account, "posY"), getAccountData(account, "posZ")
	
	-- Get the saved rotation from the account data and default to 0
	local rotation = getAccountData(account, "rotation") or 0

	-- Get the saved model (skin) from the account data and default to 312
	local model = getAccountData(account, "model") or 312

	-- Get the saved interior from the account data and default to 0
	local interior = getAccountData(account, "interior") or 0

	-- Get the saved dimension from the account data and default to 0
	local dimension = getAccountData(account, "dimension") or 0

	-- If account data was missing any of the coordinates
	if (not x) or (not y) or (not z) then
		-- Get a random spawnpoint from the spawnpoint table
		local randomSpawnPoint = randomSpawnTable[math.random(#randomSpawnTable)]

		-- Overwrite coordinates and other details with spawnpoint details or fall back to the data above
		x, y, z = randomSpawnPoint.x or 0, randomSpawnPoint.y or 0, randomSpawnPoint.z or 3
		rotation = randomSpawnPoint.rotation or rotation
		model = randomSpawnPoint.model or model
		interior = randomSpawnPoint.interior or interior
		dimension = randomSpawnPoint.dimension or dimension
	end

	-- Spawn the player to the location
	spawnPlayer(source, x, y, z, rotation, model, interior, dimension)

	-- Reset their camera target
	setCameraTarget(source)

	-- Give weapons
	giveWeapon(source, 46)
	giveWeapon(source, 9)
	giveWeapon(source, 25, 5000)
	giveWeapon(source, 28, 5000)
	giveWeapon(source, 31, 5000)
	giveWeapon(source, 22, 5000, true)
end)

-- Let's create a new savePlayer function for general use
function savePlayer(player, account)
	-- Make sure we have passed in an element
	if (isElement(player)) then
		-- Get the player's account
		account = account or getPlayerAccount(player)

		-- If the player has an account
		if (account) then
			-- Get the player element position
			local x, y, z = getElementPosition(player)

			-- Get the player element rotation
			local _, _, rotation = getElementRotation(player)

			-- Set the account data
			setAccountData(account, "posX", x)
			setAccountData(account, "posY", y)
			setAccountData(account, "posZ", z)
			setAccountData(account, "rotation", rotation)
			setAccountData(account, "model", getElementModel(player))
			setAccountData(account, "interior", getElementInterior(player))
			setAccountData(account, "dimension", getElementDimension(player))

			return true
		end
	end

	return false
end

-- Once the player logs out, let's save the player to their old account
addEventHandler("onPlayerLogout", root, function(account)
	savePlayer(source, account)
end)

-- Once the player disconnects, let's log them out (which triggers savePlayer)
addEventHandler("onPlayerQuit", root, function()
	logOut(source)
end)

 

Edited by myonlake

Share this post


Link to post

hello bro, I did not speak of a spawn point, said that I just wanted a spawn for the new players example: I am a new player and he registered and I log in and spawneo, when he leaves and enters another day appears in the position that was cuabdo He had left. That's what I meant.

Share this post


Link to post
1 hour ago, santinet12 said:

hello bro, I did not speak of a spawn point, said that I just wanted a spawn for the new players example: I am a new player and he registered and I log in and spawneo, when he leaves and enters another day appears in the position that was cuabdo He had left. That's what I meant.

Yes? Well, you need to spawn the player somewhere if they don't have any old position on their account? That script works fine for spawning the player to a random spawnpoint and then saves their position and spawns them to their old location when they come back another day and log in to the server.

Share this post


Link to post
1 hour ago, myonlake said:

hello bro, I did not speak of a spawn point, said that I just wanted a spawn for the new players example: I am a new player and he registered and I log in and spawneo, when he leaves and enters another day appears in the position that was cuabdo He had left. That's what I meant.

Well the function that you passed me, does not save the position of the player to disconnect because when I leave the server I stay in another position but when I enter and log in I appear in the position of spawn and I need that does not happen, I want the position I had to disconnect me, there is logging in.

Share this post


Link to post
1 hour ago, santinet12 said:

Well the function that you passed me, does not save the position of the player to disconnect because when I leave the server I stay in another position but when I enter and log in I appear in the position of spawn and I need that does not happen, I want the position I had to disconnect me, there is logging in.

Seems it does save the position but the camera is not faded in. Add the following line of code after setCameraTarget.

fadeCamera(source, true)

Full script would now look like this:

local randomSpawnTable = {
	{ x = 270.92654418945, y = -1986.3665771484, z = 797.52966308594, rotation = 0, model = 312, interior = 0, dimension = 0 },
	{ x = 270.92654418945, y = -1986.3665771484, z = 797.52966308594 },
	{ x = 270.92654418945, y = -1986.3665771484, z = 797.52966308594 }
}

-- Once the player logs in, let's spawn them to their saved position or a random spawnpoint
addEventHandler("onPlayerLogin", root, function(_, account)
	-- Get the saved x, y, z position from the account data
	local x, y, z = getAccountData(account, "posX"), getAccountData(account, "posY"), getAccountData(account, "posZ")
	
	-- Get the saved rotation from the account data and default to 0
	local rotation = getAccountData(account, "rotation") or 0

	-- Get the saved model (skin) from the account data and default to 312
	local model = getAccountData(account, "model") or 312

	-- Get the saved interior from the account data and default to 0
	local interior = getAccountData(account, "interior") or 0

	-- Get the saved dimension from the account data and default to 0
	local dimension = getAccountData(account, "dimension") or 0

	-- If account data was missing any of the coordinates
	if (not x) or (not y) or (not z) then
		-- Get a random spawnpoint from the spawnpoint table
		local randomSpawnPoint = randomSpawnTable[math.random(#randomSpawnTable)]

		-- Overwrite coordinates and other details with spawnpoint details or fall back to the data above
		x, y, z = randomSpawnPoint.x or 0, randomSpawnPoint.y or 0, randomSpawnPoint.z or 3
		rotation = randomSpawnPoint.rotation or rotation
		model = randomSpawnPoint.model or model
		interior = randomSpawnPoint.interior or interior
		dimension = randomSpawnPoint.dimension or dimension
	end

	-- Spawn the player to the location
	spawnPlayer(source, x, y, z, rotation, model, interior, dimension)

	-- Give weapons
	giveWeapon(source, 46)
	giveWeapon(source, 9)
	giveWeapon(source, 25, 5000)
	giveWeapon(source, 28, 5000)
	giveWeapon(source, 31, 5000)
	giveWeapon(source, 22, 5000, true)

	-- Reset their camera target and fade the camera in
	setCameraTarget(source)
	fadeCamera(source, true)
end)

-- Let's create a new savePlayer function for general use
function savePlayer(player, account)
	-- Make sure we have passed in an element
	if (isElement(player)) then
		-- Get the player's account
		account = account or getPlayerAccount(player)

		-- If the player has an account
		if (account) then
			-- Get the player element position
			local x, y, z = getElementPosition(player)

			-- Get the player element rotation
			local _, _, rotation = getElementRotation(player)

			-- Set the account data
			setAccountData(account, "posX", x)
			setAccountData(account, "posY", y)
			setAccountData(account, "posZ", z)
			setAccountData(account, "rotation", rotation)
			setAccountData(account, "model", getElementModel(player))
			setAccountData(account, "interior", getElementInterior(player))
			setAccountData(account, "dimension", getElementDimension(player))

			return true
		end
	end

	return false
end

-- Once the player logs out, let's save the player to their old account
addEventHandler("onPlayerLogout", root, function(account)
	savePlayer(source, account)
end)

-- Once the player disconnects, let's log them out (which triggers savePlayer)
addEventHandler("onPlayerQuit", root, function()
	logOut(source)
end)

 

Edited by myonlake
  • Thanks 1

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.