Redox Posted August 19, 2010 Share Posted August 19, 2010 Hi, I have question. Can I do array like 'xxx = { }' and save this when player has left server? I try to do like this: xxx = { } addEventHandler ( "onPlayerLogin", getRootElement(), function () local konto = getPlayerAccount(source) if ( konto ) then xxx[source] = getAccountData ( konto, "xxx" ) end end ) addEventHandler ( "onPlayerQuit", getRootElement(), function () local konto = getPlayerAccount(source) if ( konto ) then setAccountData (konto,"xxx",xxx[source]) end end ) But the above code doesn't work. In data base, 'xxx' has value 'nil'. And it 'xxx[source] doesn't load. Link to comment
dzek (varez) Posted August 19, 2010 Share Posted August 19, 2010 i think you should save it onPlayerLogout too. This could be big bug in your script. (ie when you saving money) Try some Debugging. Don't be lazy. You have to learn to debug if you want to make more complicated than few lines scripts. Link to comment
Redox Posted August 19, 2010 Author Share Posted August 19, 2010 But I don't know what I have to do. I haven't any errors/warnings. Link to comment
dzek (varez) Posted August 19, 2010 Share Posted August 19, 2010 i think better way than using arrays with some values will be to setElementData after login, and getElementData on quit/logout Link to comment
Redox Posted August 19, 2010 Author Share Posted August 19, 2010 Ahh, thanks. I forgot about this function. Link to comment
dzek (varez) Posted August 19, 2010 Share Posted August 19, 2010 btw: Debugging is not only watching for warnings/errors in debugscript/console window. It will help you in many cases. https://wiki.multitheftauto.com/wiki/Debugging Link to comment
Redox Posted August 19, 2010 Author Share Posted August 19, 2010 Ok ;> I have another question. I have in script code like this: Load data setElementData ( source, "skin", getAccountData ( konto, "skin" )) Save data: setAccountData (konto,"skin",getElementData(source,"skin")) And this doesn't work. I don't have idea what can I do. Link to comment
dzek (varez) Posted August 19, 2010 Share Posted August 19, 2010 should work.. Maybe your event handlers are wrong? Again: Debug. Put outputDebugString with useful informations every important line in your script, after each if, function, inside loops and after any function use. I´ve already given a lot of examples of this to other people.. Search. And please.. Read that wiki page about debugging.. Link to comment
50p Posted August 19, 2010 Share Posted August 19, 2010 If you want to get data from an account you better make sure the data has been stored before, that is, make sure getAccountData returns the data that you expect it to return.. If it'll return false then your setElementData will set player's "skin" data to false... After that you use setAccountData to set player's account data "skin" to false. You have to think in advance. What will happen if player joins your server for the first time and you try to get his account data and set it as element data? If you save player's skin, then why don't you use getElementModel instead? It saves memory because you don't have to store his skin ID in as element data. 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