Jump to content

Accountdata issue


Recommended Posts

Why won't this work D: no debug errors :/

function saveStats() 
    account = getPlayerAccount(source) 
    setAccountData ( account, "CMG2.Xpos", x ) 
    setAccountData ( account, "CMG2.Ypos", y ) 
    setAccountData ( account, "CMG2.Zpos", z ) 
end 
addEventHandler("onPlayerLogout",getRootElement(),saveStats) 
addEventHandler("onPlayerQuit",getRootElement(),saveStats) 
  
function loadStats() 
    account = getPlayerAccount(source) 
    x = getAccountData ( account, "CMG2.Xpos" ) 
    y = getAccountData ( account, "CMG2.Ypos" ) 
    z = getAccountData ( account, "CMG2.Zpos" ) 
    if x and y and z then 
        spawnPlayer(source,x,y,z + 0.5,0,skin) 
        setCameraTarget(source) 
        fadeCamera(source,true,2.5) 
    else 
        spawnPlayer(source,0,0,999999) 
  
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),loadStats) 

(I chopped this off my larger script script becuase everything else worked like the health and ammo!

Link to comment
Why won't this work D: no debug errors :/
function saveStats() 
    account = getPlayerAccount(source) 
    setAccountData ( account, "CMG2.Xpos", x ) 
    setAccountData ( account, "CMG2.Ypos", y ) 
    setAccountData ( account, "CMG2.Zpos", z ) 
end 
addEventHandler("onPlayerLogout",getRootElement(),saveStats) 
addEventHandler("onPlayerQuit",getRootElement(),saveStats) 
  
function loadStats() 
    account = getPlayerAccount(source) 
    x = getAccountData ( account, "CMG2.Xpos" ) 
    y = getAccountData ( account, "CMG2.Ypos" ) 
    z = getAccountData ( account, "CMG2.Zpos" ) 
    if x and y and z then 
        spawnPlayer(source,x,y,z + 0.5,0,skin) 
        setCameraTarget(source) 
        fadeCamera(source,true,2.5) 
    else 
        spawnPlayer(source,0,0,999999) 
  
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),loadStats) 

(I chopped this off my larger script script becuase everything else worked like the health and ammo!

The 'skin' argument it not defined use :

getElementModel 

Also the x and y and z on the setAccountData function is not defined use :

getElementPosition 

With the account data function's .

Link to comment

skin is defined earlier in the script would this be fine for the x y z?

  
   x,y,z = getElementPosition 
    x = getAccountData ( account, "CMG2.Xpos" ) 
    y = getAccountData ( account, "CMG2.Ypos" ) 
    z = getAccountData ( account, "CMG2.Zpos" ) 
  

Link to comment
-- # Server Side Not Tested But I Hope It Work : 
function saveStats() 
    local x,y,z = getElementPosition ( source ) 
    local skin = getElementModel ( source ) 
    local account = getPlayerAccount( source ) 
    if not isGuestAccount ( account ) then 
    setAccountData ( account, "CMG2.Xpos", x ) 
    setAccountData ( account, "CMG2.Ypos", y ) 
    setAccountData ( account, "CMG2.Zpos", z ) 
    setAccountData ( account, "CMG2.skin", skin ) 
    end 
end 
addEventHandler("onPlayerLogout",getRootElement(),saveStats) 
addEventHandler("onPlayerQuit",getRootElement(),saveStats) 
  
function loadStats(_,account) 
    local x = getAccountData ( account, "CMG2.Xpos" ) 
    local y = getAccountData ( account, "CMG2.Ypos" ) 
    local z = getAccountData ( account, "CMG2.Zpos" ) 
    local skin = getAccountData ( account, "CMG2.skin" ) 
    if x and y and z and skin then 
        spawnPlayer(source,x,y,z + 0.5,0,skin) 
        setCameraTarget(source) 
        fadeCamera(source,true,2.5) 
    else 
        spawnPlayer(source,0,0,999999,0,0) 
         setCameraTarget(source) 
        fadeCamera(source,true,2.5) 
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),loadStats) 

Link to comment

Got another issue with spawning the player and with his skin! It won't work :/

  
function saveStats() 
    account = getPlayerAccount(source) 
    Skin = getElementModel(source) 
    setAccountData (account,"CMG2.skin",tostring(Skin) )  
    local x,y,z = getElementPosition(source) 
    setAccountData ( account, "CMG2.Xpos", x ) 
    setAccountData ( account, "CMG2.Ypos", y ) 
    setAccountData ( account, "CMG2.Zpos", z ) 
end 
addEventHandler("onPlayerLogout",getRootElement(),saveStats) 
addEventHandler("onPlayerQuit",getRootElement(),saveStats) 
  
function loadStats() 
    account = getPlayerAccount(source) 
     
    skin = getAccountData (account,"CMG2.skin" ) 
    if skin then 
        setTimer (setElementModel,source, skin) 
    end 
  
    x = getAccountData ( account, "CMG2.Xpos" ) 
    y = getAccountData ( account, "CMG2.Ypos" ) 
    z = getAccountData ( account, "CMG2.Zpos" ) 
    if x and y and z then 
        spawnPlayer(source,x,y,z + 0.5,tonumber(skin),0) 
        setCameraTarget(source) 
        fadeCamera(source,true,2.5) 
    else 
        --spawnPlayer(source,0,0,999999) 
        --setCameraTarget(source) 
        --fadeCamera(source,true,2.5) 
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),loadStats) 
  
  

Link to comment
  • Moderators

You forgot the rotation.

spawnPlayer(source,x,y,z+.5,0,tonumber(skin),0) 

spawnPlayer (thePlayer, x,  y, z,  rotation, skinID,interior ) 

Try this:

  
function saveStats() 
    local account = getPlayerAccount(source) 
    if not isGuestAccount (account ) then 
        local Skin = getElementModel(source) 
        setAccountData (account,"CMG2.skin",tostring(Skin) ) 
        local x,y,z = getElementPosition(source) 
        setAccountData ( account, "CMG2.Xpos", x ) 
        setAccountData ( account, "CMG2.Ypos", y ) 
        setAccountData ( account, "CMG2.Zpos", z ) 
    end 
end 
addEventHandler("onPlayerLogout",root,saveStats) 
addEventHandler("onPlayerQuit",root,saveStats) 
  
  
addEventHandler("onPlayerLogin",root,  
function ()--loadStats 
    local account = getPlayerAccount(source) 
    local skin = getAccountData (account,"CMG2.skin" ) 
    local x,y,z = getAccountData ( account, "CMG2.Xpos" ),getAccountData ( account, "CMG2.Ypos" ),getAccountData ( account, "CMG2.Zpos" ) 
    if x and y and z then 
        spawnPlayer(source,x,y,z + 0.5,0,tonumber(skin) or 0,0) 
        setCameraTarget(source) 
        fadeCamera(source,true,2.5) 
    else 
        --spawnPlayer(source,0,0,999999) 
        --setCameraTarget(source) 
        --fadeCamera(source,true,2.5) 
    end 
end) 
  
   
  

Link to comment

-- # Server Side 
  
addEventHandler("onPlayerQuit",root, 
 function ( ) 
    local account = getPlayerAccount(source) 
    if not isGuestAccount (account ) then 
        local Skin = getElementModel(source) 
        setAccountData (account,"CMG2.skin",Skin ) 
        local x,y,z = getElementPosition(source) 
        setAccountData ( account, "CMG2.Xpos", x ) 
        setAccountData ( account, "CMG2.Ypos", y ) 
        setAccountData ( account, "CMG2.Zpos", z ) 
    end 
end 
) 
  
addEventHandler("onPlayerLogout",root, 
    function ( account ) 
if not isGuestAccount (account ) then 
        local Skin = getElementModel(source) 
        setAccountData (account,"CMG2.skin",Skin ) 
        local x,y,z = getElementPosition(source) 
        setAccountData ( account, "CMG2.Xpos", x ) 
        setAccountData ( account, "CMG2.Ypos", y ) 
        setAccountData ( account, "CMG2.Zpos", z ) 
    end 
end 
) 
  
addEventHandler("onPlayerLogin",root,  
function ( _,account ) 
    local skin = getAccountData (account,"CMG2.skin" ) 
    local x,y,z = getAccountData ( account, "CMG2.Xpos" ),getAccountData ( account, "CMG2.Ypos" ),getAccountData ( account, "CMG2.Zpos" ) 
    if x and y and z then 
        spawnPlayer(source,x,y,z + 0.5,0,tonumber(skin),0) 
        setCameraTarget(source) 
        fadeCamera(source,true,2.5) 
    else 
       -- spawnPlayer(source,0,0,999999) 
        --setCameraTarget(source) 
  --fadeCamera(source,true,2.5) 
    end 
end) 
  
Edited by Guest
Link to comment

Here's the whole script xD It makes more sense lol

  
function saveStats() 
    account = getPlayerAccount(source) 
    if not isGuestAccount (account ) then 
        local Skin = getElementModel(source) 
        setAccountData (account,"CMGRP.skin",tostring(Skin) ) 
        local Health = getElementHealth ( source ) 
        setAccountData ( account, "CMGRP.health", tostring(Health) ) 
        local Money = getPlayerMoney ( source ) 
        setAccountData ( account, "CMGRP.money", Money ) 
        local Armour = getPedArmor ( source ) 
    setAccountData ( account, "CMGRP.armour", tostring(Armour) ) 
    local x,y,z = getElementPosition(source) 
    setAccountData ( account, "CMGRP.Xpos", x ) 
    setAccountData ( account, "CMGRP.Ypos", y ) 
    setAccountData ( account, "CMGRP.Zpos", z ) 
    end 
end 
addEventHandler("onPlayerLogout",getRootElement(),saveStats) 
addEventHandler("onPlayerQuit",getRootElement(),saveStats) 
  
function loadStats() 
    account = getPlayerAccount(source) 
  
    local skin = getAccountData (account,"CMGRP.skin" ) 
    if skin then 
        setTimer (setElementModel,source, skin) 
    end 
    local health = getAccountData ( account, "CMGRP.health" ) 
    if health then 
        setTimer (setElementHealth, 500, 1, source, health) 
    end 
    local money = getAccountData ( account, "CMGRP.money" ) 
    if money then 
        setPlayerMoney ( source, money ) 
    end 
    local armour = getAccountData ( account, "CMGRP.armour" ) 
    if armour then 
        setTimer (setPedArmor, 500, 1, source, armour) 
    end 
     
    x = getAccountData ( account, "CMGRP.Xpos" ) 
    y = getAccountData ( account, "CMGRP.Ypos" ) 
    z = getAccountData ( account, "CMGRP.Zpos" ) 
    if x and y and z then 
        spawnPlayer(source,x,y,z + 0.5,tonumber(skin),0) 
        setCameraTarget(source) 
        fadeCamera(source,true,2.5) 
    else 
        --spawnPlayer(source,0,0,999999) 
        --setCameraTarget(source) 
        --fadeCamera(source,true,2.5) 
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),loadStats) 
  
  

Link to comment

-- # Server Side 
addEventHandler("onPlayerQuit",getRootElement(),  
function ( )  
    account = getPlayerAccount(source) 
    if not isGuestAccount (account ) then 
        local Skin = getElementModel(source) 
        setAccountData (account,"CMGRP.skin",Skin ) 
        local Health = getElementHealth ( source ) 
        setAccountData ( account, "CMGRP.health",Health ) 
        local Money = getPlayerMoney ( source ) 
        setAccountData ( account, "CMGRP.money", Money ) 
        local Armour = getPedArmor ( source ) 
    setAccountData ( account, "CMGRP.armour", Armour ) 
    local x,y,z = getElementPosition(source) 
    setAccountData ( account, "CMGRP.Xpos", x ) 
    setAccountData ( account, "CMGRP.Ypos", y ) 
    setAccountData ( account, "CMGRP.Zpos", z ) 
    end 
end 
) 
  
addEventHandler("onPlayerLogout",getRootElement(),  
function ( account ) 
    if not isGuestAccount (account ) then 
        local Skin = getElementModel(source) 
        setAccountData (account,"CMGRP.skin",Skin ) 
        local Health = getElementHealth ( source ) 
        setAccountData ( account, "CMGRP.health", Health ) 
        local Money = getPlayerMoney ( source ) 
        setAccountData ( account, "CMGRP.money", Money ) 
        local Armour = getPedArmor ( source ) 
    setAccountData ( account, "CMGRP.armour", Armour ) 
    local x,y,z = getElementPosition(source) 
    setAccountData ( account, "CMGRP.Xpos", x ) 
    setAccountData ( account, "CMGRP.Ypos", y ) 
    setAccountData ( account, "CMGRP.Zpos", z ) 
    end 
end 
) 
  
function loadStats( _,account ) 
    local skin = getAccountData (account,"CMGRP.skin" ) 
    setTimer(setElementModel,500,1,source, skin) 
    local health = getAccountData ( account, "CMGRP.health" ) 
    if health then 
    setTimer (setElementHealth, 500, 1, source, health) 
    end 
    local money = getAccountData ( account, "CMGRP.money" ) 
        setPlayerMoney ( source, money ) 
    local armour = getAccountData ( account, "CMGRP.armour" ) 
    setTimer (setPedArmor, 500, 1, source, armour) 
    x = getAccountData ( account, "CMGRP.Xpos" ) 
    y = getAccountData ( account, "CMGRP.Ypos" ) 
    z = getAccountData ( account, "CMGRP.Zpos" ) 
    if x and y and z then 
        spawnPlayer(source,x,y,z + 0.5,tonumber(skin),0) 
        setCameraTarget(source) 
        fadeCamera(source,true,2.5) 
    else 
        --spawnPlayer(source,0,0,999999) 
        --setCameraTarget(source) 
        --fadeCamera(source,true,2.5) 
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),loadStats) 
  

Use this one because you add more things armor , health , etc.!

Link to comment

I have another issue D: I don't know why but the teams arn't saving

Server part - This is triggered when you first join the server and have to choose a skin, once that is done it saves your team as unemployed

  
addEvent("lookSkin",true) 
addEventHandler("lookSkin",root,function(skin) 
    setAccountData ( getPlayerAccount(source), "CMGRP.team", "Unemployed" )  
    givePlayerMoney(source,10000) 
    giveWeapon ( source, 22, 90, true ) 
    giveWeapon ( source, 4, 1, false ) 
    setElementModel(source,skin) 
    --setPlayerTeam ( source,Unemployed) 
end) 
  

In the save script here is the server side part

addEventHandler("onPlayerQuit",getRootElement(), 
function ( ) 
    account = getPlayerAccount(source) 
    if not isGuestAccount (account ) then 
        local Team = getPlayerTeam ( source ) 
        setAccountData (account, "CMGRP.team",Team) 
    end 
end 
) 
  
addEventHandler("onPlayerLogout",getRootElement(), 
function ( account ) 
    if not isGuestAccount (account ) then 
        local Team = getPlayerTeam ( source ) 
        setAccountData (account, "CMGRP.team",Team) 
    end 
end 
) 
  
function loadStats( _,account ) 
    local team = getAccountData ( source, "CMGRP.team") 
        setPlayerTeam (source,team) 
    if x and y and z then 
        spawnPlayer(source,x,y,z + 0.5,tonumber(skin),0) 
        setCameraTarget(source) 
        fadeCamera(source,true,2.5) 
    else 
        --spawnPlayer(source,0,0,999999) 
        --setCameraTarget(source) 
        --fadeCamera(source,true,2.5) 
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),loadStats) 

I've took out the unimportant stuff don't worry everything is defined, maybe not at the team part thats where the issue is D:

Link to comment

-- # Server Side 
addEventHandler("onPlayerQuit",getRootElement(), 
function ( ) 
    account = getPlayerAccount(source) 
    if not isGuestAccount (account ) then 
         local Team = getPlayerTeam ( source ) 
        if Team then 
        local teamName = getTeamName ( Team ) 
        setAccountData (account, "CMGRP.team",teamName) 
        end 
    end 
end 
) 
  
addEventHandler("onPlayerLogout",getRootElement(), 
function ( account ) 
    if not isGuestAccount (account ) then 
        local Team = getPlayerTeam ( source ) 
        if Team then 
        local teamName = getTeamName ( Team ) 
        setAccountData (account, "CMGRP.team",teamName) 
        end 
    end 
end 
) 
  
function loadStats( _,account ) 
    local team = getAccountData ( account, "CMGRP.team" ) 
        setPlayerTeam (source,getTeamFromName(tostring(team))) 
    if x and y and z then 
        spawnPlayer(source,x,y,z + 0.5,tonumber(skin),0) 
        setCameraTarget(source) 
        fadeCamera(source,true,2.5) 
    else 
        --spawnPlayer(source,0,0,999999) 
        --setCameraTarget(source) 
        --fadeCamera(source,true,2.5) 
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),loadStats) 
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...