Jump to content

Creating Tables?


Recommended Posts

Hi,

I just wondered how I set up tables which have e.g 3 coords and this 5 times. Like this:

x,y,z
x2,y2,z2
x3,y3,z3

I know how to do it in SA:MP, but not in MTA. I've also searched through the forum and google for a tutorial for "how I create tables in LUA", but I didn't found anything like this. I want this because I want to load multiple coordinates for the gas stations, and then later check if the Player is near them.

Link to comment
Thank you 50p! My last thing I want to ask is: How should I load them into the Table?

Load what into them?

If you want to store coords in tables, then just put them in. You can use map files to store coords in them but this is different.

But if you mean, take those coords out of the table then you do it like in PAWN:

x1, y1, z1 = tab[ 1 ][ 1 ], tab[ 1 ][ 2 ], tab[ 1 ][ 3 ];
x2 = tab[ 2 ][ 1 ];
y2 = tab[ 2 ][ 2 ];
z2 = tab[ 2 ][ 3 ];

Link to comment

Map files are the best place to store position-based data, that's what they're designed for. This is fast, and can be edited by the MTA editor - and various other editors.

Link to comment

I just added the coordinates from every Gas Station right to in the Table, and now I just load the remaining gas amount in the Gas Station with a "Gas Station ID".

Here's a little question, because I don't want to create a new Topic just because of a small math thing: How can I get a higher Gas price when the amount of gas is getting "smaller"?

Link to comment
I just added the coordinates from every Gas Station right to in the Table, and now I just load the remaining gas amount in the Gas Station with a "Gas Station ID".

Here's a little question, because I don't want to create a new Topic just because of a small math thing: How can I get a higher Gas price when the amount of gas is getting "smaller"?

I'd like to answer your question but I don't get your idea.

Link to comment

something like that?

gasLeft = 0.75 -- i assume that your gas meter have values from 0 to 1
maxGasValue = 1 -- to make math more readable
gasPrice = 5000 -- "main" gas price
gasExtraPrice = ((gasLeft-maxGasValue)*-1)*1000 -- extra 1000 if your gas is empty, extra 500 if your gas is half empty etc..

Link to comment
I just added the coordinates from every Gas Station right to in the Table, and now I just load the remaining gas amount in the Gas Station with a "Gas Station ID".

Here's a little question, because I don't want to create a new Topic just because of a small math thing: How can I get a higher Gas price when the amount of gas is getting "smaller"?

I'd like to answer your question but I don't get your idea.

something like that?
gasLeft = 0.75 -- i assume that your gas meter have values from 0 to 1
maxGasValue = 1 -- to make math more readable
gasPrice = 5000 -- "main" gas price
gasExtraPrice = ((gasLeft-maxGasValue)*-1)*1000 -- extra 1000 if your gas is empty, extra 500 if your gas is half empty etc..

I meant when the remaining gas in the Gasstation is dropping, the fuel price is getting higher per liter. Like this:

Remaining Gas in station: 500
Remaining gas in Car: 50/70
"standard" gas price: 9$

After I have filled up my car it should be like this:

Remaining gas in station: 480

Remaining gas in car: 70/70

gas price now: 11$

Link to comment

Remaining Gas in station: 500
Remaining gas in Car: 50/70
"standard" gas price: 9$

After I have filled up my car it should be like this:

Remaining gas in station: 480

Remaining gas in car: 70/70

gas price now: 11$

standardPrice = 9
currentPrice = 9
priceWhenThereIsNoGas = 30
maxGas = 500
remainingGas = 500
 
function takeGasAndCountNewPrice(amount)
if (amount<=remainingGas) then
   remainingGas = remainingGas - amount
   currentPrice = ((remainingGas - maxGas) * -1 * priceWhenThereIsNoGas/maxGas) + 9
end
end

not tested of course.. modify it to suits your needs

Link to comment

varez, I don't get it why, you take away smaller value from larger value and convert it to positive value... What's the point? Why not simply swap the order and get the same value w/o multiplying negative value by -1?

a = (30 - 50) * -1
-- is equivalent to:
a = 50 - 30;

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