Jump to content

Element data arrays


DiSaMe

Recommended Posts

I have just decided that using element data functions would be better than array of players data. And some of data is in array format too. So I have to do something like this with element data. This is what I tried with runcode resource:

setElementData(player,"array",{4,5,6}) 

Then checked it:

getElementData(player,"array")[2] 

It returned 5. It's OK. Now here's the problem. I try to change one field in array:

getElementData(player,"array")[3] = 7 

But when I use

getElementData(player,"array")[3] 

it still returns 6. Is there any way to use element data as array?

Link to comment

While storing arrays will obviously work, I suspect the reason for this problem is that, when getElementData'ing it, you get an actual array instead of a pointer to it. (Which makes sense since element data is supposed to be synchronized between server and clients and pointers of any kind would be a bad idea.)

After setting the value, you will need to setElementData the resulting array back into the element data.

Link to comment

Yes, I know that, but some of the data has to be synced with clients. Right now my gamemode uses triggerClientEvent for that. But if using element data is so inefficient, maybe I'll stay with tables. I think I don't need to sync player inventory with all clients just because he bought one more item when he already has 50 items and he must see them all in his inventory window :)

Link to comment

Because I don't want to create thousands of topics, I'll tell you about my another problem here.

a = 5*1e-005
outputChatBox(tostring(a))

When executed server-side, it outputs 5e-005. In client-side it shows 4.9999998736894e-005. How could I make it be shown correctly?

Edited by Guest
Link to comment
Because I don't want to create thousands of topics, I'll tell you about my another problem here.
a = 5*1e-005 
outputChatBox(tostring(a)) 

When executed server-side, it outputs 5e-005. In client-side it shows 4.9999998736894e-005. How could I make it be shown correctly? I don't like it when I have 256mg of amphetamine but in kilograms it shows 0.00025599999935366...

This is an issue with sending large numbers to client. I had the same problem with my bank resource which doesn't always show correct amount of money you have on your account because sending huge numbers to client fails.

This is from changelog of the bank resource:

* fixed: The difference between 99999999 and (the total of pocket money + money to withdraw) could be lost. That would make you lose money if you wanted to withdraw more, this is caused by GTA itself because you can only have 99,999,999 at a time. Although, sometimes your account balance (in GUI window) may not be shown correctly because the amount to be displayed isn't sent correctly to the client.
Link to comment

My problem isn't about sending data to client. The code I just wrote returns incorrect result and is completely client-side. In my gamemode I have 256mg amphetamine in the inventory. This number is sent from server and displayed correctly with GUI. But where it shows the mass in kilograms, it multiplies those 256mg by 0.000001 (which is stored in client-side) and displays 0.00025599999935366.

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