Absence2 Posted March 25, 2012 Share Posted March 25, 2012 Alright so I just entered this part, it's very new to me, including sqlite. So I'm trying to save every stat a player has, money, skin, location, weapon, and so on.. So far, I've managed the money & skin. Though, the location is causing me problems. I'm convinced I'm doing something wrong after 30 minutes of trying to figure it out Alright, so this is what I got, function onPlayerQuit() local playerAccount = getPlayerAccount(source) if (playerAccount) and not isGuestAccount(playerAccount) then local playerMoney = getPlayerMoney(source) local playerSkin = getElementModel(source) local playerPos = getElementPosition ( source ) setAccountData(playerAccount, "money", playerMoney) setAccountData(playerAccount, "skin", playerSkin) setAccountData(playerAccount, "position", playerPos) end end addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) function onPlayerLogin() local playerAccount = getPlayerAccount(source) if (playerAccount) then local playerMoney = tonumber(getAccountData(playerAccount, "money")) local playerSkin = tonumber(getAccountData(playerAccount, "skin")) local playerPos = tonumber(getAccountData(playerAccount, "position")) if (playerMoney and playerSkin and playerPos) then setPlayerMoney(source, playerMoney) setElementModel(source, playerSkin) setElementPosition ( source, playerPos ) end end end addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) as I said, I'm new to sqlite, so I took it as I had to create a table, so I went to wiki and ended up with this executeSQLCreateTable ( "position", "x, y, z" ) I'm not really sure where the problem lays at >.< so, what to do? I suppose it's at the table, though I don't understand how to do it completely. Note: this is my third topic about this within a minute, lol. Forums seems to be really slow or it's my internet, causing me to first create two topics by misstake, then delete those two by misstake Link to comment
Castillo Posted March 25, 2012 Share Posted March 25, 2012 getElementPosition returns 3 arguments, not one: x, y, z. Btw, account data doesn't require to create tables, that's for SQLite. Link to comment
Absence2 Posted March 25, 2012 Author Share Posted March 25, 2012 oh yes, but I cannot add commas to line 20: if (playerMoney and playerSkin and x,y,z) then So I'm not really sure what to do with that one. Link to comment
Castillo Posted March 25, 2012 Share Posted March 25, 2012 Of course you can't, but you can do this: if ( playerMoney and playerSkin and x and y and z ) then Link to comment
Absence2 Posted March 25, 2012 Author Share Posted March 25, 2012 Oh yes, I did try that but didn't work. Syntax however is gone, but there's no "effect". function onPlayerQuit() local playerAccount = getPlayerAccount(source) if (playerAccount) and not isGuestAccount(playerAccount) then local playerMoney = getPlayerMoney(source) local playerSkin = getElementModel(source) local x,y,z = getElementPosition ( source ) setAccountData(playerAccount, "money", playerMoney) setAccountData(playerAccount, "skin", playerSkin) setAccountData(playerAccount, "position", x,y,z) end end addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) function onPlayerLogin() local playerAccount = getPlayerAccount(source) if (playerAccount) then local playerMoney = tonumber(getAccountData(playerAccount, "money")) local playerSkin = tonumber(getAccountData(playerAccount, "skin")) local x,y,z = tonumber(getAccountData(playerAccount, "position")) if (playerMoney and playerSkin and x and y and z) then setPlayerMoney(source, playerMoney) setElementModel(source, playerSkin) setElementPosition ( source, x,y,z ) end end end addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) function createSQLOnStart () executeSQLCreateTable ( "position", "x, y, z" ) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()),createSQLOnStart ) and that's how I trigger the table.. or whatever^ Link to comment
Castillo Posted March 25, 2012 Share Posted March 25, 2012 function onPlayerQuit ( ) local playerAccount = getPlayerAccount ( source ) if ( playerAccount ) and not isGuestAccount ( playerAccount ) then local playerMoney = getPlayerMoney ( source ) local playerSkin = getElementModel ( source ) local x, y, z = getElementPosition ( source ) setAccountData ( playerAccount, "money", playerMoney ) setAccountData ( playerAccount, "skin", playerSkin ) setAccountData ( playerAccount, "posX", x ) setAccountData ( playerAccount, "posY", y ) setAccountData ( playerAccount, "posZ", z ) end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) function onPlayerLogin ( _, playerAccount ) if ( not isGuestAccount ( playerAccount ) ) then local playerMoney = tonumber ( getAccountData ( playerAccount, "money" ) ) or 0 local playerSkin = tonumber ( getAccountData ( playerAccount, "skin" ) ) or 0 local x = tonumber ( getAccountData ( playerAccount, "posX" ) ) or 0 local y = tonumber ( getAccountData ( playerAccount, "posY" ) ) or 0 local z = tonumber ( getAccountData ( playerAccount, "posZ" ) ) or 0 if ( playerMoney and playerSkin and x and y and z ) then setPlayerMoney(source, playerMoney) setElementModel(source, playerSkin) setElementPosition ( source, x, y, z ) end end end addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) Link to comment
Absence2 Posted March 25, 2012 Author Share Posted March 25, 2012 It does seem to work, sort of. For some reason, it keeps spawning me out in Red County no matter where I am. Link to comment
Castillo Posted March 25, 2012 Share Posted March 25, 2012 As you can see, I set it if no position data, it'll be 0 instead. Link to comment
Absence2 Posted March 25, 2012 Author Share Posted March 25, 2012 I don't really get it, so I have to create a table, for an example: function createSQLOnStart () executeSQLCreateTable ( "posX", "x" ) executeSQLCreateTable ( "posY", "y" ) executeSQLCreateTable ( "posZ", "z" ) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()),createSQLOnStart ) So, this would do the trick? I tested few other ways, but didn't work. I suppose it's this what you mean by with no data. Currently, it keeps spawning me at location '0'. Link to comment
Cadu12 Posted March 25, 2012 Share Posted March 25, 2012 Just use code of Solidsnake14. Did you used login? Did you leave server? ( You can back server ) Link to comment
Castillo Posted March 25, 2012 Share Posted March 25, 2012 You didn't read what I first replied? Btw, account data doesn't require to create tables, that's for SQLite. Link to comment
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