Jump to content

MTA VARIABLES


DexoTronic

Recommended Posts

Posted

Hello.

I have saved the PlayerMoney in a Variable in the Accounts.xml.

So i can load it:

account = getPlayerAccount ( source )

PlayerMoney = getAccountData ( account, "Money" )

It works.

But 1 Problem:

for example, i have 650$ in my account saved, after i login the varibale PlayerMoney is 650$. But if somebody else loggs in, who has 800$ saved the variable has 800$ :(

Is there a way to aviod that?

Like:

PlayerMoney[source] ? (i tried that, doesnt work)

sry 4 my english

i hope you help me.

Posted

You need to define a new table for PlayerMoney[source]

Playermoney = {}

And yes there is a easy way to aviod this...

Set the Variable to nil or 0 when the Player disconnects from the server.

function quitPlayer ( quitType )
    Playermoney = nil
end
addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer )

Stats_Signature.php?name=Jason_Gregory
Contact me if you need a Website / Signature ↑ / Mapuploadsystem

(HTML5, JS, PHP, ASP.NET, MySQL / Sybase)

Posted
Hello.

I have saved the PlayerMoney in a Variable in the Accounts.xml.

So i can load it:

account = getPlayerAccount ( source )

PlayerMoney = getAccountData ( account, "Money" )

It works.

But 1 Problem:

for example, i have 650$ in my account saved, after i login the varibale PlayerMoney is 650$. But if somebody else loggs in, who has 800$ saved the variable has 800$ :(

Is there a way to aviod that?

Like:

PlayerMoney[source] ? (i tried that, doesnt work)

sry 4 my english

i hope you help me.

It does work. You just need to declare PlayerMoney as table (array). Like, Jason_Gregory showed

PlayerMoney = { }

But his example code will not work since his example deletes the whole table when someone leaves the server. You'll have to delete just one cell in that table/array. Do something like this:

addEventHandler ( "onPlayerQuit", getRootElement(), 
function ( )
       PlayerMoney[ source ] = nil 
end
)

Posted

function onLogin ( player, user, pass )
local account = getAccount ( user, pass )
if ( account ~= false ) then
	if (logIn ( player, account, pass ) == true) then
		account = getAccount ( user, pass )
		PlayerMoney[source] = getAccountData ( account[source], "Money" )
	   	PlayerSkillPoints[source] = getAccountData ( account[source], "SkillPoints" )
	   	PlayerLevel[source] = getAccountData ( account[source], "Level" )
		PlayerFraction[source] = getAccountData ( account[source], "Fraction" )
		PlayerJob[source] = getAccountData ( account[source], "Job" )
		PlayerBankMoney[source] = getAccountData ( account[source], "BankMoney" )
		PlayerHausnummer[source] = getAccountData ( account[source], "Hausnummer" )
		PlayerAdminlevel[source] = getAccountData ( account[source], "Adminlevel" )
		PlayerSkin[source] = getAccountData ( account[source], "Skin" )
		PlayerCarID[source] = getAccountData ( account[source], "CarID" )
		PlayerCarx[source] = getAccountData ( account[source], "Carx" )
		PlayerCary[source] = getAccountData ( account[source], "Cary" )
		PlayerCarz[source] = getAccountData ( account[source], "Carz" )
		PlayerCarrx[source] = getAccountData ( account[source], "Carrx" )
		PlayerCarry[source] = getAccountData ( account[source], "Carry" )
		PlayerCarrz[source] = getAccountData ( account[source], "Carrz" )
	else
		outputChatBox ( "Loginfehler!", player, 255, 255, 0 )
	end
else
	outputChatBox ( "Du besitzt noch keinen Account. Registriere dich bitte zuerst.", player, 255, 255, 0 )
end
end
addEvent( "onLogin", true )
addEventHandler( "onLogin", getRootElement(), onLogin )

so thats my code (+ the onquit) now :)

i love you guys :P

Posted
But his example code will not work since his example deletes the whole table when someone leaves the server. You'll have to delete just one cell in that table/array. Do something like this:

It was a Example for his method not mine :o

Dextronic, 50p says youre using the Variable "account" as table and

as a single Variable.

Use something like this

local account[source] = getAccount ( user, pass )
if ( account[source] ~= false ) then
if (logIn ( player, account[source], pass ) == true) then
        account[source] = getAccount ( user, pass )

Stats_Signature.php?name=Jason_Gregory
Contact me if you need a Website / Signature ↑ / Mapuploadsystem

(HTML5, JS, PHP, ASP.NET, MySQL / Sybase)

Posted
....
local account[source] = getAccount ( user, pass )
if ( account[source] ~= false ) then
if (logIn ( player, account[source], pass ) == true) then
        account[source] = getAccount ( user, pass )

Neither this will work. 1st line is invalid Lua syntax. I let you fix it.

Posted
....
local account[source] = getAccount ( user, pass )
if ( account[source] ~= false ) then
if (logIn ( player, account[source], pass ) == true) then
        account[source] = getAccount ( user, pass )

Neither this will work. 1st line is invalid Lua syntax. I let you fix it.

C´mon, icon_neutral.gif

now he should know how to define a table.

Thats not a Bug its a feature

account[source] = getAccount ( user, pass )

Stats_Signature.php?name=Jason_Gregory
Contact me if you need a Website / Signature ↑ / Mapuploadsystem

(HTML5, JS, PHP, ASP.NET, MySQL / Sybase)

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