Jump to content

[SOLVED] Tiny problem


justn

Recommended Posts

So, I would like it, so if the player has joined the server and logged in for the first time, then he will be spawned at the position below

function assigntheteam () 
setPlayerTeam ( source, Unemployed ) 
spawnPlayer(source, 1643.40002, -2249.10009, 13.300, 178.0004, 0, 0, 0, Unemployed) 
fadeCamera(source, true) 
setCameraTarget(source, source) 
end 
addEvent ( "IfNewPlayerJoin", true ) 
addEventHandler ( "IfNewPlayerJoin", getRootElement(), assigntheteam ) 

otherwise, if he has joined the server before. then, his 'Skin,Team,Money,Position' will save.

Edited by Guest
Link to comment

You can use onPlayerLogin and accounts data for that. On login set an account data to identify whether he logged in before or not.

function onLogin(old, acc) 
 local firstTime = getAccountData(acc, 'firstTime') 
 if (not firstTime) then 
  --new player, spawn him 
  setAccountData(acc, 'firstTime', 'true') 
 end 
end 

Link to comment
You can use onPlayerLogin and accounts data for that. On login set an account data to identify whether he logged in before or not.
function onLogin(old, acc) 
 local firstTime = getAccountData(acc, 'firstTime') 
 if (not firstTime) then 
  --new player, spawn him 
  setAccountData(acc, 'firstTime', 'true') 
 end 
end 

Full code please?

Link to comment
  • Moderators
You can use onPlayerLogin and accounts data for that. On login set an account data to identify whether he logged in before or not.
function onLogin(old, acc) 
 local firstTime = getAccountData(acc, 'firstTime') 
 if (not firstTime) then 
  --new player, spawn him 
  setAccountData(acc, 'firstTime', 'true') 
 end 
end 

Full code please?

Just try, you are supposed to work for your server.

Link to comment

Okay , so if the player is new, he will spawn at the XYZ position below. that works but the problem is, so what im trying to do below is when the player quits, i want it to get the player's last position, and when the player logs in again, he will spawn at the last position he was before he had quit the server.

function onPlayerQuit ( ) 
      local playeraccount = getPlayerAccount ( source, 'playerAcc' ) 
       if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
        local playerXYZ = getElementPosition ( source ) 
            setAccountData ( playeraccount, "playerPosition", playerXYZ ) 
      end 
end 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
  
function onLogin (old, acc) 
local firstTime = getAccountData(acc, 'firstTime') 
 if (not firstTime) then 
    setPlayerTeam ( source, Unemployed ) 
    spawnPlayer(source, 1643.40002, -2249.10009, 13.300, 178.0004, 0, 0, 0, Unemployed) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    setAccountData(acc, 'firstTime', 'true') 
 else 
    if (playeraccount) then 
        if (firstTime) then 
        local playerXYZ = getAccountData ( playeraccount, "playerPosition" ) 
            if ( playerXYZ ) then 
            setElementPosition ( source, playerXYZ ) 
            end 
        end 
    end 
 end 
 end 
addEvent ( "IfNewPlayerJoin", true ) 
addEventHandler ( "IfNewPlayerJoin", getRootElement(), onLogin ) 
addEventHandler ( "onPlayerLogin", getRootElement ( ), onLogin ) 

Link to comment

1# When you use else statement then you can't use if statement again unless you add an "end" statement.

2# its not playerXYZ but in fact its

local x,y,z = getElementPosition ( source ) 

3# How do you trigger "IfNewPlayerJoin" event? You must use triggerEvent if the player is new

4# This code is a mess, too many errors. I'm on mobile can't help you but I hope someone helps you to fix it.

Link to comment
1# When you use else statement then you can't use if statement again unless you add an "end" statement.

2# its not playerXYZ but in fact its

local x,y,z = getElementPosition ( source ) 

3# How do you trigger "IfNewPlayerJoin" event? You must use triggerEvent if the player is new

4# This code is a mess, too many errors. I'm on mobile can't help you but I hope someone helps you to fix it.

Actually, this was just an example to show you guys what I wanted. but nvm, i fixed it, thanks though

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