toptional Posted May 14, 2013 Posted May 14, 2013 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!
iPrestege Posted May 14, 2013 Posted May 14, 2013 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 .
toptional Posted May 14, 2013 Author Posted May 14, 2013 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" )
iPrestege Posted May 14, 2013 Posted May 14, 2013 -- # 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)
toptional Posted May 14, 2013 Author Posted May 14, 2013 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)
Moderators IIYAMA Posted May 14, 2013 Moderators Posted May 14, 2013 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) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
toptional Posted May 14, 2013 Author Posted May 14, 2013 Ok it works but the skin doesn't keep the same D: It has skin ID 0 all the time
iPrestege Posted May 14, 2013 Posted May 14, 2013 (edited) -- # 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 May 14, 2013 by Guest
PaiN^ Posted May 14, 2013 Posted May 14, 2013 addEventHandler("onPlayerLogout",root, function ( account ) " Keep Thinking Different . " - Steve Jops -------------------- Don't send me PMs asking for help, I Won't reply !
iPrestege Posted May 14, 2013 Posted May 14, 2013 addEventHandler("onPlayerLogout",root, function ( account ) Oh yes forget this line edited
toptional Posted May 14, 2013 Author Posted May 14, 2013 Here's the whole script 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)
PaiN^ Posted May 14, 2013 Posted May 14, 2013 Use #Mr.Pres[T]ege's edited code . " Keep Thinking Different . " - Steve Jops -------------------- Don't send me PMs asking for help, I Won't reply !
iPrestege Posted May 14, 2013 Posted May 14, 2013 -- # 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.!
iPrestege Posted May 14, 2013 Posted May 14, 2013 (edited) Thanks sorted it Great. Edited May 14, 2013 by Guest
toptional Posted May 14, 2013 Author Posted May 14, 2013 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:
toptional Posted May 14, 2013 Author Posted May 14, 2013 Eariler in the script here: local Unemployed = createTeam ( "Unemployed",236,92,178)
iPrestege Posted May 14, 2013 Posted May 14, 2013 -- # 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)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now