Scripts / Save/Load script

Author
Message
Moshroom
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location: Finland
Posted: 19th Aug 2015 19:59 Edited at: 12th Nov 2015 21:16
Hi. I created simple save/load system for my project and since there currently aren't any other save/load systems in GameGuru, I'll share it here in case somebody needs one.

Name: Save and Load game script
Developer: Jussi Palomäki a.k.a. Moshroom. (Parts of the script are based on the default scripts of GameGuru.)
License: Edit freely, use in any project (non-commercial or commercial) with GameGuru. Name me as script creator if you find this useful.

The script creates simple save prompt that let's the player save his/her progress to up to 10 slots. The moshroom_savepoint script creates a .dat file that stores player health, player lives and Counter table with 100 variables ("Counters"). These can be loaded with moshroom_loadpoint script.

Counters are used to save entity data. There are currently three scripts that are compatible with Counters: moshroom_ai_keymaster, moshroom_remotedoor and moshroom_health. Keymaster is a character that opens the remote door when player first talks to him/her. Health is based on default health script and the only difference between this and the original is that this adds the Counter table.

The best way to use my script is to create one large map with save- and loadpoints at the center and lots of unlockable features that open new sections of the map.

Setting up the save and load points

1) Create an entity with Static Mode boolean set to NO and ai system (script) set to moshroom_loadpoint.lua.
2) Repeat step 1 with moshroom_savepoint.lua. This script introduces the Counter table so you probably should set the Always active boolean to YES if you have large map (at least I think... not 100 % sure about this).

Setting the save/load system compatible entities

3) Create an entity with Static Mode boolean set to NO and ai system (script) set to moshroom_ai_keymaster, moshroom_remotedoor or moshroom_health
4) Set the name of your keymaster AND remotedoor entities to a number between 1 and 100 (one number per one pair). This links them together and to Counter table, which allows the save/load system to store whether player has talked to keymaster to trigger unlocking of the door
5) Set the name of your health item to a number between 1 and 100 (different than any keymaster/remotedoor pair). This links it to Counter table which allows the save/load system to store whether the item has been picked up or not.
6) Make sure there is only one keymaster/remotedoor pair or health item per each Counter (in other words, make sure that every keymaster/remotedoor pair and health item has different numbers as a name).

There are some limitations that are due to lack of certain LUA command in the current GameGuru version. Please read carefully:
- data can be only saved from entities that use the Counter table
- player position can't be loaded
- weapon data can't be saved nor loaded
- everything happens in single map

A workaround is probably possible for at least the last three of these limitations, but it requires game-specific manual editing of the script. Unless new LUA commands are added to GameGuru, these will probably never work out-of-box. It's left to be seen whether new LUA commands will be available before the official save/load system (which is currenlty at top at the feature vote).

Download:

http://www.univelka.net/games/moshroom_saveload.zip (inclues all 5 lua:s mentioned here and very simple example map)

Videos:

https://www.youtube.com/watch?v=3dZ5FEKMLw0 (savepoint, loadpoint, ai_keymaster and remotedoor)
https://www.youtube.com/watch?v=jgWWIvc7Vm4 (health)

Code:

moshroom_savepoint.lua (version 2.0, 11.11.2015)

moshroom_loadpoint.lua (version 2.0, 11.11.2015)

moshroom_keymaster.lua

moshroom_remotedoor.lua

moshroom_health.lua (version 2.0, saves "Healing Potion" to inventory, if inventory is available, 12.11.2015)

moshroom_magic.lua (version 2.0, saves "Magic Source" to inventory, if inventory is available, 12.11.2015)

Attachments

Login to view attachments
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 19th Aug 2015 21:59
Cool scripts. This will help some people who need this. Thanks for sharing
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
JC LEON
14
Years of Service
User Offline
Joined: 22nd Apr 2010
Location:
Posted: 19th Aug 2015 22:34
cool thanks...
PC Specs:

Q9550@3,8GHZ - 8GB RAM - SVGA R9 280 3GB GDDR5 - HDD WD 1500TB
PM
Pirate Myke
Forum Support
14
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 19th Aug 2015 22:35
Very nice set of scripts. Will come in handy. Thank you for sharing.
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit

Inertia
9
Years of Service
User Offline
Joined: 12th Jul 2015
Location: SoCal, USA
Posted: 20th Aug 2015 14:31
Nicely done, Moshroom!

I put the scripts in a custom directory then adjusted the entities in the map so that the scripts loaded from the custom location, then saved a standalone and tested everything. Perfect!

Couldn't think of anything else to test--it just works.
PM
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 20th Aug 2015 17:31
Wow very nice, thanks for sharing.
Thanks

I may be old, but at least my memory still ....hmmm

DT:Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528, AutoCAD, 3DsMax, Paint.Net, Solidworks.
Moshroom
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location: Finland
Posted: 23rd Aug 2015 20:58 Edited at: 23rd Aug 2015 21:06
Thank you all for your positive feedback. I just created another Counter-compatible script for 3rd person magic collectibles (moshroom_magic.lua). Use just like moshroom_health.lua.

Because "g_Power" variable doesn't exist, I resolved to create a new global variable, g_RPG_SpellPower to store data from collected runes (moshroom_magic.lua) and input it back to the engine with SetPlayerPower(e,v) command. This sparked an inspiration for a new script: RPG Module. It's currently just on "planned" stage, but I already included support to it to 1.2 version of save/loadpoints. Currently the only active part of the RPG Module is g_RPG_SpellPower.

Code:

moshroom_magic.lua

moshroom_savepoint.lua (version 1.2, added compatiblity with moshroom_magic.lua and planned RPG Module)

moshroom_loadpoint.lua (version 1.2, added compatiblity with moshroom_magic.lua and planned RPG Module)

Please note, that save files created with version 1.1 are not compatible with version 1.2 and vice versa because the RPG Module is on top of the Counter table. I wanted to keep the Counter at the bottom of the file so that user could easily change the array size of the table without ruining the save files.
Bored of the Rings
GameGuru Master
19
Years of Service
User Offline
Joined: 25th Feb 2005
Location: Middle Earth
Posted: 23rd Aug 2015 21:03
good work Moshroom, I tried this out, works well.
Professional Programmer: Languages- SAS, C++, SQL, PL-SQL, JavaScript, HTML, Darkbasic Pro, Purebasic, others
Hardware: Dell Precision 490; AMD Radeon HD 7570; LG TFT monitor (widescreen).
guigui
9
Years of Service
User Offline
Joined: 4th Jul 2015
Location:
Posted: 29th Aug 2015 12:59
Hello, I use the following scripts and moshroom_ai_keymaster.lua moshroom_remotedoor.lua. (Https://forum.game-guru.com/thread/213084)
It makes me the following messages:
running error function: scriptbank \ moshroom_ai_keymaster.lua: 49: Attempt to global index 'counter' (a nil value).
Can anyone help me?

thank you

Attachments

Login to view attachments
guigui
9
Years of Service
User Offline
Joined: 4th Jul 2015
Location:
Posted: 29th Aug 2015 13:13
sorry for the message, just a mistake that I have set.
Housetroll
9
Years of Service
User Offline
Joined: 12th Jun 2015
Location:
Posted: 2nd Sep 2015 21:26 Edited at: 3rd Sep 2015 22:27
Very cool, I modified it so that it will store a list of weapons collected (by name) then on load it scans the list and adds them back to player - but you have to place weapons with those names in the zone (I did 'not spawn at start' and it still grabs the entity number and pops them back in - pain to have to make a separate script for each level load with the entity numbers in but it works) Haven't figured out how to do the ammo yet. Thanks Moshroom! Oh and you have to use this modified weapon.lua too.

Attachments

Login to view attachments
PM
Moshroom
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location: Finland
Posted: 4th Sep 2015 21:05
Very nice, Housetroll. Thanks for sharing.
Microck
9
Years of Service
User Offline
Joined: 24th Sep 2015
Playing:
Posted: 28th Sep 2015 21:07
I try you're script Moshroom (with static No, etc... like you say) but i got this:

error running function: scriptbank\moshroom_savepoint.lua:120: attempt to concatenate global 'g_Second' (a table value)

What does it mean ?

---------------------------

And i try the housetroll script but nothing work. How set up the housetroll script ?
PM
Housetroll
9
Years of Service
User Offline
Joined: 12th Jun 2015
Location:
Posted: 28th Sep 2015 23:03 Edited at: 28th Sep 2015 23:39
I made a small error on the script - make sure there is a line above the first function that reads g_Second={} then on the load script you have to replace the nil value with the entity numbers of the weapons you placed. I made the weapons not spawn at start so they don't appear for anyone to pick up but the script looks for the weapon with that entity number and gives it to them. So if they had a dagger in the previous level, put a dagger with the same name anywhere on the new level, change it to not spawn at start, write down the entity number (say, for example 202) of that dagger and change the line in the script for the dagger from nil to 202 or whatever the dagger's entity number is. Do that for each weapon they may have picked up in the previous level.

Try downloading these scripts along with these two test levels. Test play test3 then test play test4 and it should load all 3 weapons you picked up in test3.

Attachments

Login to view attachments
PM
Moshroom
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location: Finland
Posted: 29th Sep 2015 08:49
Hello, Microck. I haven't encountered that before, but I have a guess of what causes it. Make sure that you are not mixing different versions of the script in the same map. There are at least three different versions of the script in this thread: My versions 1.1 (not compatible with 3rd person magic collectables) and 1.2 (compatible with magic) and Housetroll's scripts (use the logic based on the previous scripts to save the weapon list between maps). The scripts are created for different purposes so they should not be mixed. The problem you described might be caused by using Housetroll's load point (define g_Second as table) and my save point (read g_Second as variable) in the same map. LUA can't automaticly transcribe a table into a variable and therefore causes error.
Microck
9
Years of Service
User Offline
Joined: 24th Sep 2015
Playing:
Posted: 30th Sep 2015 18:32
Thanks for reply. Now works fine.
PM
cybernescence
GameGuru Master
11
Years of Service
User Offline
Joined: 28th Jan 2013
Playing: Cogwheel Chronicles
Posted: 2nd Oct 2015 22:16
Hi Moshroom, you may have this in your script now, but in case not you can reset player position on load, if you save player x,y,x and use:



Cheers.
Moshroom
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location: Finland
Posted: 7th Oct 2015 22:25 Edited at: 15th Jan 2016 19:08
Edit 15.1.2016: The script in this post is an alpha version of my RPG AI script, the final version of which is published in the Asset Store (link). Most parts of the code is rewritten in the new version and the version in this post isn't compatible with my RPG Module script pack.

Here's a framework for save/load/RPG module compatible enemy character. It was pretty tricky to create, because there isn't any LUA command to respawn an entity. Therefore I had to create a workaround which overrides the default damage control by HP table.

One advantage in this approach is that I was able to utilize some new RPG variables, not just SpellPower. I replaced Strenght in RPG module with Sight, because I came to a conclusion that Strenght would just do same thing as SpellPower. So now we have 3 RPG variables that do something: SpellPower controls the amount of damage player inflicts to an enemy, Agility controls the rate of damage an enemy can get (if player shoots fireballs faster than Agility level allows, enemy "evades" them) and Sight controls the distance where player can inflict damage on enemies (if player shoots fireballs from more far away than Sight level allows, they "miss"). When the enemy character's HP reaches 0, player is rewarded with 10 points of EXP (the level up system doesn't exist yet).

Another new feature in my script is a Battle Message system which prompts to player how much damage a fireball did to an enemy (or was it evaded/missed). I try to record video tomorrow.

Here's the code:

moshroom_ai_neutral.lua

Use like the previous scripts. Remember to name your entity with a unique number between 1 and 100. Because I replaced Strenght in RPG module with Sight, you need to rename g_RPG_Strenght to g_RPG_Sight in save- and loadpoints if you want to save and load Sight level. This isn't neccessary because I haven't created any level up system yet so Sight is always 100.

Known issues:
- Dying animation doesn't play. This is because currently there isn't any LUA command to show the animation without destroying the entity (which would make it not appear even if the game is loaded)
- BattleMessage 4 is always shown in the start of the level. I don't fully understand why this happens, but this can be avoided if line 134 is replaced with this:
(of course the enemy character must be placed more than 2000 units away from start point)

ps. Note that a character using this script doesn't do anything except looks toward player and takes damage from fireballs. This is not an issue, it's a feature. The only purpose of this code is to work as a framework for upcoming ai scripts. I try to create one in the near future.
pps. I haven't tested this in 1st person mode.
ppps. Cybernescence, thanks. I'll check that out as soon as I've finished the RPG level up system and one active enemy character.
Brny
9
Years of Service
User Offline
Joined: 11th Oct 2015
Playing:
Posted: 15th Oct 2015 17:16 Edited at: 19th Oct 2015 13:50
Hi, here is some info that i'd found, let's see if between all us we can make a decent save/load script for the games... because it is a basic thing that must have...



PM
Big Dog Game Studios
12
Years of Service
User Offline
Joined: 18th Jun 2012
Location: Port Angeles, WA
Posted: 16th Oct 2015 00:02
Hey all, been hanging around the forums and watching every now and then. This is almost the exact type of script I need to get my game published. I have it close to done, but the game includes 25 levels. I need a script that will save when they enter a new area, and a way to load at startup. Without it, my game is useless because no one will sit down and run these huge levels in one sitting. I have hopes that someone finds a way to make this possible. It is very weird that this has not been added to the list of things to include in the engine itself.
cybernescence
GameGuru Master
11
Years of Service
User Offline
Joined: 28th Jan 2013
Playing: Cogwheel Chronicles
Posted: 16th Oct 2015 16:05
Quote: "It is very weird that this has not been added to the list of things to include in the engine itself."


It has been added to the list of things to be done, kind of, if you view the community vote as the list:

https://www.game-guru.com/feature-vote/results

Login to post a reply

Server time is: 2024-11-16 16:53:43
Your offset time is: 2024-11-16 16:53:43