Scripts / Farming/Harvest Scripts

Author
Message
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 13th Mar 2014 15:11 Edited at: 13th Mar 2014 15:19
Hello. Here is a video explaining how I made my farming video a few days ago. I'll link it in case you haven't seen it already. The videos should explain what this is about, but basically these scripts will allow you to have plants you can harvest, store and sell in your games. Including XP and level ups.



Here is the original video.



Here are the scripts I made.







You will need to add these variables to your global.lua file.



Hopefully that should cover everything!

I began these scripts from AUShadows Level and Xp scripts. First automating the level gain and adding an editable maxlevel. So thanks to him for giving me the idea to begin with!

Scene Commander
Support Manager
15
Years of Service
User Offline
Joined: 3rd May 2008
Location:
Posted: 13th Mar 2014 20:04
Thanks Dvader, very generous of you to share.



I think it's great the way the community is already willing to share so much.



SC

i7-4770s 3.10ghz - Geforce GTX 650ti
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 13th Mar 2014 22:36 Edited at: 13th Mar 2014 22:40
Yeah, it's cool everyone wants to share their work. We just need some more control over the engine with lua I really need a function to spawn object from lua script... with that, I could already make some simple games that are not just run and shoot.



I would just propose not to use so many global variables, but place all of them into one global lua table (array, list, however you want) and make that variable name unique. Or keep those variables but prefix them with some unique word.



Also, I wouldn't put all vars in global.lua. Place them in myfile.lua and then in global.lua just add:







That way you won't lose your variables when FPSCR's global.lua file is updated (with new version).

HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 14th Mar 2014 00:18
Many thanks Dvader.



I love it!!



Harry

Harry
PM
AuShadow
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 14th Mar 2014 10:33
@Dvader

I'm trying to fine tune my cash script which may interest you for this demo you have put together its to display the currebtcash variable as gold silver and copper, only thing is I need to convert the currentcash variable into a numeric I can us
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 14th Mar 2014 13:55
this looks awesome dvader m8, as always great vids

amd radeon hd 6450, quad core win 8, 4gb ram
PM
AuShadow
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 15th Mar 2014 09:42
I've worked it out and hopefully have a gold silver copper script up tomorrow night sometime

PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz

Feel free to visit and edit the public FPSCR resource wiki page: http://fpscrresource.wikispaces.com/home
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 15th Mar 2014 10:01
Sorry first time I have checked this thread, never normally get many posts on non main page threads lol! Haven't tried that sort of thing yet AuShadow, so unsure, it would be easy in DB or AGK though. I would imagine it is fairly similar to what I have done here with the extra text options really. Seems you have solved it so no need for me to go looking lol!



Avram, yeah I was conscious of all those variables starting to look a little messy. I have looked into tables a little as I wanted to make this code way more automated. However, I can't see how I can do that yet as there is no way of using the table in an effective way as yet to my knowledge. Still I am new as new can be to Lua and only understand it at all because I have used AGK etc in the past.



Obviously if I made this in say AGK, I would know the id's of each object and could store any relevant data into a array. Then it would be simply a matter of retrieving it when you interact with that object ID. But here I have no clue apart from when you are interacting with each object. Of course this was only meant for demo purposes, so knowing me I will move on to different stuff soon enough I started converting it into an array before I released the vid, but figured I'd leave it, as I didn't see the point of just making it tidier at present Or confusing people more than I need to



To make it mostly automatic, I need to have a property set on each plant type for exactly which it is. If I could do that, it would be easy to convert all this info into an array and make it way better! Unfortunately, I can't see any way to do this yet.





I didn't know you could add a separate file to the global list, will have to look into that next time I'm scripting!

AuShadow
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 15th Mar 2014 10:32
Yeah all I'm doing is multiplying the current cash by say 0.001 and then using math.floor to round to the lower full number so for example 4750 becomes 4.750 and with math.floor that just becomes 4 instead of rounding up. Sorry for all these posts I'm kinda using the forum here to store my ideas while I'm not at home ;P

PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz

Feel free to visit and edit the public FPSCR resource wiki page: http://fpscrresource.wikispaces.com/home
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 15th Mar 2014 20:08 Edited at: 15th Mar 2014 21:34
DVader wrote: "Avram, yeah I was conscious of all those variables starting to look a little messy. I have looked into tables a little as I wanted to make this code way more automated. However, I can't see how I can do that yet as there is no way of using the table in an effective way as yet to my knowledge. Still I am new as new can be to Lua and only understand it at all because I have used AGK etc in the past."




I'm not sure how you can't see the benefit of tables. You can do pretty much everything with tables: make arrays, hash tables (key->value storage) or classes for OOP development. For example, you could replace all your variables in global.lua with one (global) table, and then add whatever variable (and it's value) you want into that one table. If you have seen my aTimer class, you can see there how you can avoid messy code by using tables as classes.



DVader wrote: "Obviously if I made this in say AGK, I would know the id's of each object and could store any relevant data into a array. Then it would be simply a matter of retrieving it when you interact with that object ID. But here I have no clue apart from when you are interacting with each object."




All (dynamic) entities are stored in g_Entity table (as an array), but I don't know if their indexes change with each game run. I'm currently working on a entity class that will allow easier manipulation of entities within LUA. For example, this is how you can create entity object and get it's distance from the player.







DVader wrote: "To make it mostly automatic, I need to have a property set on each plant type for exactly which it is. If I could do that, it would be easy to convert all this info into an array and make it way better! Unfortunately, I can't see any way to do this yet."




My Entity class will support fetching entities by their name:







Unfortunately, at this time, g_Entity is not populated with entity names from FPSC editor, so all entities (that are going to be fetched by name) need to have this line in their main script:







This will create object for that particular entity and give it a name (if it doesn't have one yet). You can then retreive it's name with this:attr('name') or you can read whatever is in g_Entity array with this:attr('attr_name') or set new attribute to an entity with this:attr('attr_name', 'attr_value')



I don't know if this is worth releasing yet, as you can't do anything useful except getting the distance between entities. We need more control over game in LUA!



p.s. Sorry for poisoning the thread. This may be split into separate thread.

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 16th Mar 2014 02:02
Avram, I immediately saw tables or arrays as I call them, would be better. I hardly use variables in other coding, apart from basic flags normally, the rest would all be called from an array. But as I said, I could not think of a way to utilize them effectively in Lua, being fairly new to it.



I'll take a look at your snippets tomorrow, and see if they help me understand how to get one implemented. From glancing at your snippets, it still looks like I would have to have a unique script for each plant type, which was one of the things I was trying to avoid by using arrays in the first place. You also mention the object would need to be dynamic? I'm pretty certain all my objects were static in my demo.



I've only scratched the surface with Lua so far, so expect to get better as time goes on. One day I may even switch up from using notepad to an actual Lua editor Testing in Reloaded can take ages: Load up Reloaded, load the map, test, crash, read awkward error message, wait for reloaded to reload up, close it (editing a script while Reloaded is open does not seem to register), edit lua file, rinse and repeat :p You can imagine it can be a bit ponderous and can put one off messing too much!

Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 16th Mar 2014 08:25 Edited at: 16th Mar 2014 09:10
How do you mean your entities were static? In old FPSC you couldn't have static object with a script, static objects were "baked" into the world while building level, so in the built game they were not entities (separate objects) anymore, but part of the level. Maybe something has changed in the meantime, but I just switched all entities with a script to be dynamic.



Yes, unfortunately as I said FPSC won't pass entity name from editor to g_Entity global table, so I have to use separate script to set entity names in order to be able to fetch them via their name later. I hope TGC will pass all entity properties to LUA in later versions.



Regarding script testing, I have found much easier to build game once and then edit scripts from built game folder, so you can close FPSC and play around. Just remember to copy your modified scripts back to FPSC folder/files/scriptbank once you are finished with testing but that way you can't edit pretty much anything except scripts.



p.s. I have also never seen LUA before FPSC:R

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 16th Mar 2014 12:52 Edited at: 16th Mar 2014 13:06
Although I own it, I never really did too much with the original FPSC, as I found it too limiting. You couldn't even switch the mouse control for those awkward few who prefer plane sim style controls to normal ones!

I just double checked my original scene and yes, they are static. The scripts work fine though. Reloaded must work differently than the original FPSC.

It would certainly be a lot easier if you could get more info from the objects fpe file. Still not actually looked into those snippets you posted, been busy modelling, and have managed to find a missing polygon in Reloaded that looks fine in Blender, so been looking into that. Doesn't look good at the minute, and it was mostly done bar touch ups and animation



Sounds like were all new to Lua in the main then! I'll post if I have any luck getting an ID to use as a pointer for an array based system. Even if it's something different



Edit - I set them as static, because I figured that would help keep the performance up (it seems to help). I tend to set anything that will never move as static.



Edit - Good idea about the build though, probably faster to test than the editor

Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 16th Mar 2014 13:28 Edited at: 16th Mar 2014 13:31
That's great if you can now set scripts to static objects too. I also noticed that animated palm tree that comes with FPSC:R is static by default, yet it animates even if static. Guess I'm going to use dynamic only on entities that move.



Those code snippets in my post above are just examples how entity class will be used to encapsulate entity properties in a single entity object (per entity), along with entity functions (such as playsound0, playsound1, destroy, ...) and some generic helper functions to fetch entity by name (shown in an example above), or set of entities with a same (or similar) name, or closest entities (also by name), etc... it is not finished though, but can be used... we just need couple of more functions and all entity properties in LUA and we will be able to make anything that can be imagined

almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 18th Mar 2014 13:38
hey dvader m8 hows it going?, I found something in your script m8 that needs changing? well not so much in the script itself exactly but anyways no idea if you noticed or not m8.



-- LUA Script - precede every function and global member with lowercase name of script + '_main'

-- Player Collected esperiance



should be experience, hope that's helpful m8

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
Racing Brain Games
10
Years of Service
User Offline
Joined: 12th Jan 2014
Location:
Posted: 23rd Mar 2014 15:33
Very nice, I will have a play with this combined with Au Shadows cash levelling script. The ultimate tweaks to this script would be:



-Make the farming skill seperate to overall player level.



-Vegetable Quality could improve per level so you could the sell potatoes for more gold per level, it would give a pretty good reason for a seperate Farming Skill. (I'm thinking of trying to create sneak, weapon, armor, stamina skills etc similar to skyrim/oblivion, fps creator needs more melee weapons though. And player hands!)



-Plants grow back showing different stages of growth on a timer (in the background not on screen) and the player can only pick the vegetables/plats once its fully grown. (I have a feeling this is easier said than done but will likely become easier once a proper stable version of reloaded is released and is no longer in the beta stages.)



Just some food for thought for any would be coders, I will be trying my best to learn LUA once I finish my current project.



Good stuff and keep it up!

Racing Brain Entertainment.

All or Nothing.
Super Clark
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 4th Apr 2011
Location: UK
Posted: 25th Mar 2014 05:22 Edited at: 25th Mar 2014 05:33
Hi, I'm new to scripting so not 100% sure what to do to get this working correctly, I have addded the 3 files to the script bank with names

redrootxp.lua / redrootstore.lua / redrootsell.lua and added this



--

-- LUA Globals Common Header

--



-- Globals (built-in)

g_Entity = {}



-- Globals (passed-in)

g_PlayerPosX = 0

g_PlayerPosY = 0

g_PlayerPosZ = 0

g_KeyPressE = 0





currentcash = 0

charexp = 0

charlvl = 1

chardiscount = 1



levelmax=10

levelxp = 4000

upgradeskill=8500

potatoes=0

potatoestore=0

potatoesold=0

greetings=0

beetroots=0

beetrootstore=0

beetrootsold=0

redroots=0

redrootstore=0

redrootsold=0



to global scrip.



I have added tw0 imges 1 of the fpe file and the big pictre of what i get in

reloaded. It asks me to press E to collect but that is all I get says Not High Enough Level?. can someone let me know where I am going wrong please.



Thanks.
PM
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 25th Mar 2014 20:53 Edited at: 25th Mar 2014 20:55
The scripts I have posted are for the highest level plant in this case. Just decrease the level requirement in the redrootxp lua file.



Change this line



if charlvl>5 then



to



if charlvl>=0 then



That should get it working. The first line is to ensure you are level 6 before you are allowed to pick the plant. Each plant can have a different level set. Of course it was working properly, you just weren't high enough level to pick it up!

Super Clark
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 4th Apr 2011
Location: UK
Posted: 25th Mar 2014 22:14 Edited at: 25th Mar 2014 22:15
Thanks DVader that did the trick, is it possable to set it so

you do not have to press E all the time to pick up each 1 as at the moment

every root i have to press E to collect?
PM
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 26th Mar 2014 00:37
Well, you can just hold down the e key. But if you don't want it just comment out, or remove the code that checks for a key press.



if g_KeyPressE == 1 then



and the subsequent end further down also.

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 5th Apr 2014 16:23
@ Avram. Tried adding some globals from a separate file and worked a treat. Nice tip! Lua feels more like AGK in it's options by the day

[URL=http://talosgames.com/][IMG]http://imageshack.us/a/img62/6592/monsnakerbanner.png[/I
Avram
GameGuru TGC Backer
17
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 5th Apr 2014 20:01
Great! I told you it'll work. And when you re-install FPSC and global.lua gets updated, your variables should be safe in separate file.

Meows
12
Years of Service
User Offline
Joined: 12th Oct 2011
Location: Totally over the Rainbow
Posted: 7th May 2014 15:44
I did what Super Clark did adding the lines to the global file

-- Globals (built-in)

g_Entity = {}



-- Globals (passed-in)

g_PlayerPosX = 0

g_PlayerPosY = 0

g_PlayerPosZ = 0

g_KeyPressE = 0





currentcash = 0

charexp = 0

charlvl = 1

chardiscount = 1



levelmax=10

levelxp = 4000

upgradeskill=8500

potatoes=0

potatoestore=0

potatoesold=0

greetings=0

beetroots=0

beetrootstore=0

beetrootsold=0

redroots=0

redrootstore=0

redrootsold=0



but I do not own any Beetroots so I used default box and finally got the everything working the Press E to store Beetroots. shows but you never pick it up! no matter how many times you press E

smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 7th May 2014 19:29
i'm sorry,
Quote: "but you never pick it up"
.... meaning?

you can't pick the boxes up from the floor?

or you can't store them?

or you can't collect the money?



but it looks like the scripts here are only for the last of the vegetables (redroot) and not for potatoes or beetroot so you would need to edit them a bit to allow them to work for the other 2 as well (basically just changing the redroot varible to beetroot/potatoes and the level requirement)



so for beetroot you would need





and







that should work (obviously need to name the files appropriately too)

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 24th May 2014 16:40
Sorry missed this. Looks like smallg has answered you though. The scripts have been modified a little to use a global file rather than adding them to your global script now. They are available on the wiki.



http://fpscrresource.wikispaces.com/home



SPECS: Q6600 CPU. Nvidia 260GTX. 8 Gig Memory. Win 7.

Login to post a reply

Server time is: 2024-04-19 12:31:48
Your offset time is: 2024-04-19 12:31:48