Scripts / mining script help

Author
Message
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 14th Oct 2019 19:08
hi all, I'm wondering how is the best way to e.g I have various mining scripts which say mine g_ores or g_minerals etc what I would like to do is have g_ores = g_ironscollected, g_gemscollected, g_zincscollected what would be the best way to write this?
Thanks

Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 14th Oct 2019 19:46
I can not understand very well what you want, you can post the script you use, using tags please.

I suspect that you will have to use an array called mining, and put the other elements inside, for example:


Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 14th Oct 2019 19:52 Edited at: 14th Oct 2019 20:16
well yes m8 there are a few scripts I use which mine for ores ( I'm trying this with small's miner script ATM) attached I edited this in my old project so as you could craft a schematic to buy and use the rig for mining (but only 1 item) so I was trying to convert "g_ores" to multiple types of ore in 1 script to save having multiple miners.
so maybe this? or that what I mean anyway

e.g g_ironscollected + math.random(1 , 2),g_gemscollected + math.random(1 , 2),g_zincscollected + math.random(1 , 2)

so I presume it would write out like?




so basically every time 1 g_ores is collected random irons, gems and zincs are added to the inventory

or would this be better to add to the inventory script? attached
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on

Attachments

Login to view attachments
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 14th Oct 2019 20:33 Edited at: 14th Oct 2019 20:42
I didn't look at the script, but
Make them separate variables I would think- no?

If g_ores > 0 then --- this means the miner has collected ores.
ironscollected = math.random(1 , 2)
gemscollected = math.random(1 , 2)
zincscollected = math.random(1 , 2)
..... and so forth...
end

Is that the idea?
Also, math.random(2) produces the same results as math.random(1 , 2)
and for more variety you could do;
(math.random(3)) - 1

which would give you the return that sometimes no ore ( 0 ) is found
for each specific treasure when you dig.

In other words the random variables would be either 0, 1, or 2.
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 14th Oct 2019 20:39 Edited at: 14th Oct 2019 20:41
missed 3coms answer
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 14th Oct 2019 20:45
Tried most of these thanks guys think I need to verify as nothing seems to be working
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 14th Oct 2019 20:46
Or

Or
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 14th Oct 2019 21:12
Yeah, tables/ arrays are a bit confusing to me still-- I wouldn't know
how to call out the individual variables from the table,
maybe I'll study it out and see more about them when possible.

In my scripts I keep things as 'visual' and 'open' to study as I can.
All I learn in lua is almost just here on the forums (and programming in general),
from my experience in DOS basic 30 years ago! IOW limited!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 14th Oct 2019 21:38
Okay, I think [allegorically] an 'array' is like a string of beads.
Each bead represents an assigned variable (or nil)
call the 'bead' by calling it's order in the string of beads.
lua.org calls them 'keys'.
a[20] = "great" -- new entry, with key=20 and value="great"
k = 20
print(a[k]) --> "great"
so, that's how we use local vs global variables.

PM
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 14th Oct 2019 21:50 Edited at: 14th Oct 2019 21:57
I'm not a very good scripter m8 I can do menus, save and load etc but sometimes smallg's and Am's scripts go above me lol. with this one tbh I'm unsure whether I should be adding the code to one of the scripts I'm using or whether I need to write a separate one.

I do now have the ores adding to the inventory but not converting them to the ores (the idea of this is you hit a vein of unknown ore which then will produce a random one in the inventory) other items are drops from kills or scavenging space wrecks.

Its been a while since I worked with the miner script in the older project I had 1 miner per ore, heres it working so far (need to clean up the miner textures but its getting there)

P.s also the script isn't recording the ores on screen.

Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 14th Oct 2019 21:59 Edited at: 14th Oct 2019 22:02
local a = {} -- an empty list

a.hello = 'world' -- adding a value 'world' with the key 'hello'
a.goodbye = 'all' -- adding a value 'all' with the key 'goodbye'

local b = 'hello'

Prompt( b .. " " .. a.hello ) -- will print out "hello world"
Prompt( b .. " " .. a[ b ] ) -- will also print out "hello world"
Prompt( 'goodbye' .. " " a[ 'goodbye' ] ) -- will printout "goodbye all"

To use as an array:

local c = {}

for i = 1, 9 do
c[ #c + 1 ] = I -- #c gives the current length of the list
end

This will give you an array { 1, 2, 3, 4, 5, 6, 7, 8, 9 }

Prompt( c[ 3 ] ) -- will print out '3'

Hope that helps.
Been there, done that, got all the T-Shirts!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 14th Oct 2019 22:05 Edited at: 14th Oct 2019 22:06
Here is an example list from Slaur3n's cowboy game inventory:

Been there, done that, got all the T-Shirts!
PM
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 15th Oct 2019 10:52 Edited at: 15th Oct 2019 11:27
Ok {} is an array or table and all the items I need go inbetween the {} e.g local ores = { zinc = 1, copper = 1} I get that part

What I'm trying to do is every time the miner obtains a g_ore the script takes a random amount of ores from that array an adds it to the inventory script

So in my case I'm using g_ores (the ore vein) to tally how many ore veins have been hit but also need to have a random amount of zinc and copper added to the inventory for that hit.

So firstly I presume I would need to convert g_ores into ores for the local ores to work yes? and then pull the result from the array.

ok changed line 53 to local ores = g_ores which stops the error and adds the g_ores value but not the other ores from the table

ok now this is my head thinking so its probably wrong lol



which returned the pictured error



I am now running this as a separate script so I can understand what I'm doing wrong along the way
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on

Attachments

Login to view attachments
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 15th Oct 2019 11:26
You have to see an array like a backpack with many elements inside.
An array is similar to a folder that contains files, to open a file you would do: myfolder / myfile; in the same / similar way an array element would be accessed: myarray.myitem.
In other words you must understand the array as a parent and the elements it contains as children.

When you declare an array, it must be treated as such, since it is no longer an individual element, ie:

wrong way
myArray = 22

right way
myArray.iron = 22

here iron is one item holded into myArray and you are passing 22 to it, as integer value.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 15th Oct 2019 11:53
so in my case myfolder = ores yes? and to call say g_zincscollected from the folder I would use
ores.g_zincscollected = 22
or for a random result
ores.g_zincscollected+ math.random(1 , 10) ?

so the syntax would be
if g_ores > 0 then ores.zincscollected+ math.random(1 , 10) for a random amount of zinc?

thanks for putting up with me 3com these type of scripts really confuse me
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 15th Oct 2019 13:54 Edited at: 15th Oct 2019 17:59
Oh well I resorted to the old way of doing it which works. I'm a little wiser on arrays but still haven't got a clue how to make them do what I want lol here's my new working script.



If it works.......................




can anyone see why this is not switching scripts?

Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 15th Oct 2019 18:26
Good job! Do it however you understand now to get you started out.
Then over time, you can study and learn, and switch over if it seems
advantageous to do so. Personally I see no advantage to it, for a simple
request like you are asking. (More lines than I had assumed though! )
It's still not a Fort Knox inventory script but the perfect way to go yet.

As for switching scripts-- not sure, but there's no end directly after init(e)
also, usually the assignments of the variables fall inside the init-- but this
again is something [[that works for me]] but I'm not sure if it's necessary.
I'd try that and see what happens.
Also-- check the name of script saved to init(e) and main(e), I can't see it?
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 15th Oct 2019 18:31 Edited at: 15th Oct 2019 18:33
It also looks like you would need a ;

if g_KeyPressE == 0 then pressed = 0 end

Also, have you considered making it just one script combined?
I'm not making your game, so I'm not for sure, but perhaps that
is a possible solution if all else fails?
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 15th Oct 2019 18:40
Other than the beginning of assigning collected variable -----

where is your assignment of collected back to zero -
collected = 0 ?? Maybe it should be *checked* somewhere where
the player gets near the miner machine?
PM
Honkeyboy
3D Media Maker
9
Years of Service
User Offline
Joined: 16th Sep 2015
Location: Doesnt know half the time ;)
Posted: 15th Oct 2019 19:01
yep ty missed an end off thanks m8
Intel i5 4950 Quad core 3.3ghz AMD FX 6300 x6 cores 3.5ghz(unclocked)
8gb Ram 8gb Ram
AMD Radeon 7570 1gb AMD Radeon HD 6670 2gb
and a well fed mouse on a wheel

I only smile because i have absolutely no idea whats going on
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 15th Oct 2019 20:11
Here you have defined two global variables and set them to 0
g_zincscollected=0
g_coppercollected=0

Here you have created an array with two entries pointing to the global variables
local ores = { g_zincscollected , g_coppercollected }

What you probably want to do is have them combined in one list like this:
g_ores_collected = { zinc = 0, copper = 0 }

Then in your script somewhere you would say
g_ores_collected.zinc = math.random( 1, 4 )
g_ores_collected.copper = math.random( 2, 3 )

If you wanted to find out how many ores of all kinds you have you can then do this:
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-12-22 08:49:51
Your offset time is: 2024-12-22 08:49:51