kevin433 Posted May 27, 2010 Posted May 27, 2010 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.
50p Posted May 27, 2010 Posted May 27, 2010 Tables are just like arrays in PAWN but more dynamic. tab = { { 1000, 1000, 1000 }, { 1000, 1000, 1000 }, { 1000, 1000, 1000 }, { 1000, 1000, 1000 }, -- etc. }
kevin433 Posted May 27, 2010 Author Posted May 27, 2010 Thank you 50p! My last thing I want to ask is: How should I load them into the Table?
50p Posted May 27, 2010 Posted May 27, 2010 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 ];
kevin433 Posted May 27, 2010 Author Posted May 27, 2010 I've created a Table in the SQL Database, and it's layout is like this: PosX FLOAT PosY FLOAT PosZ FLOAT Liter (amount of fuel in english) INTEGER I then want to store them into a table when I start the server.
eAi Posted May 28, 2010 Posted May 28, 2010 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.
Xierra Posted May 28, 2010 Posted May 28, 2010 Yes it's a good idea, but also the table can be used on many purposes other than x,y,z locations. @eAi: I know, but how should I do that? Any examples?
kevin433 Posted May 28, 2010 Author Posted May 28, 2010 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"?
50p Posted June 1, 2010 Posted June 1, 2010 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.
dzek (varez) Posted June 1, 2010 Posted June 1, 2010 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..
eAi Posted June 1, 2010 Posted June 1, 2010 See Example 2 on: https://wiki.multitheftauto.com/wiki/GetElementsByType#Example
kevin433 Posted June 1, 2010 Author Posted June 1, 2010 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.. See Example 2 on:https://wiki.multitheftauto.com/wiki/GetElementsByType#Example 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: 480Remaining gas in car: 70/70 gas price now: 11$
dzek (varez) Posted June 1, 2010 Posted June 1, 2010 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: 480Remaining 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
50p Posted June 1, 2010 Posted June 1, 2010 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;
dzek (varez) Posted June 2, 2010 Posted June 2, 2010 uhm.. crazy math im not sure.. i just did it in that way
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