Quantcast

Jump to content

» «
Photo

[CLEO] How to save data of in-game and load it?

9 replies to this topic
Marty McFlaY
  • Marty McFlaY

    If you cant run, then walk, if you cant walk, then crawl :)

  • Members
  • Joined: 25 Feb 2016
  • England

#1

Posted 4 weeks ago

Yeah, just like DYOM. Like it saves all the place objects, items, checkpoints etc, in a file and load it.

 

How i can do that in SB? For example: I placed some objects in Standard GTA with sanny builder. Now i want to store all objects position in a file like saving a progress. How i can do that and also how to load that?


Marty McFlaY
  • Marty McFlaY

    If you cant run, then walk, if you cant walk, then crawl :)

  • Members
  • Joined: 25 Feb 2016
  • England

#2

Posted 4 weeks ago

Anyone can reply?


ZAZ
  • ZAZ

    Kernlochbohrer

  • Feroci
  • Joined: 10 Jan 2005
  • European-Union
  • Contribution Award [Mods]
    Helpfulness Awards [Mods]

#3

Posted 4 weeks ago

Yeah, there're several methods , needs explain a bit more, what's your knowledge in coding?

Marty McFlaY
  • Marty McFlaY

    If you cant run, then walk, if you cant walk, then crawl :)

  • Members
  • Joined: 25 Feb 2016
  • England

#4

Posted 4 weeks ago

1) Beginning

2) Easy

3) Normal

4) Intermediate

5) Hard

6) Very Hard

 

I'm in Intermediate level. 


ZAZ
  • ZAZ

    Kernlochbohrer

  • Feroci
  • Joined: 10 Jan 2005
  • European-Union
  • Contribution Award [Mods]
    Helpfulness Awards [Mods]

#5

Posted 4 weeks ago Edited by ZAZ, 4 weeks ago.

Ok,
you can store objects placements in an external file, if cleo is installed, means, write model id, x,y,z coords and x,y,z, angle in a file
Then you can save and load it without making a normal savegame

But when you make a normal savegame, there's a disdvantage: objects, radarblips, pickups will be saved for sure in any way

Step by step:

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

In main.scm are used Global Variables and Local Variables
Globals have a global scope, locals only a local scope.
All existing Globals will be stored in the savefile, if you make a savegame

Example:
$OBJECT_M_A51_VENTCOVERB is the global var for the vent cover that you can remove in mission Black Project to get down to the secret area69
It's placed in a mission script that runs at gamestart
 
0107: $OBJECT_M_A51_VENTCOVERB = create_object #A51_VENTCOVERB at 245.968 1862.843 19.49 
0453: set_object $OBJECT_M_A51_VENTCOVERB XY_rotation 0.0 0.0 angle -140.998 
01C7: remove_object_from_mission_cleanup_list $OBJECT_M_A51_VENTCOVERB
and will be stored with your first savegame

This object can be used or removed later in the mission Black Project by calling this global var $OBJECT_M_A51_VENTCOVERB
You can do that from any script inside main.scm



If you use a local var instead,
 
0107: [email protected] = create_object #A51_VENTCOVERB at 245.968 1862.843 19.49
The object placement will also be stored, when you make a savegame,
but then you can't use or remove it anymore, because local vars won't be saved

Objects, radarblips, pickups will be saved by internal id's and codes but if they're placed by local vars, the reference is missing, because local vars won't be saved

The reference is only available for that thread instance that is running where the placement was done

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

In cleo you should not use global vars, because it can cause bugs and crashes
It must not, but it can, like that script below to replace the door objects and the ventcover at area69
Spoiler

My experience is: if a mission is running and a cleoscript with global vars, it cause bugs or if many globals are used, it crashes
So many users got buggy games and savegames because they ran cleo scripts that use global vars or place radarblips and pickups and made a savegame then.

In any way, it's not recommanded to use globals in cleo
For cleo exist another method to give local vars a global scope
It's also not recommanded to place objects, radarblips and pickups by cleo script

If you wanna do it though, then make sure that the user can't get a buggy or corrupted save game

So let's clarify first:
Are you planning to publish a mod that spawns objects or is it for privat use?
If you planning to publish a mod, can it be a main.scm mod, a modpack?
If it should be a cleo script, should it be possible to edit the file, manually, that stores the object info?
  • _Israel_ likes this

Marty McFlaY
  • Marty McFlaY

    If you cant run, then walk, if you cant walk, then crawl :)

  • Members
  • Joined: 25 Feb 2016
  • England

#6

Posted 4 weeks ago Edited by Marty McFlaY, 4 weeks ago.

:Main_Menu_Choice_5_Menu
wait 0
if
  0AAB:   file_exists "CLEO\SAVE\savedata.dat"
jf @ERROR
0A9A: $FILE = openfile "CLEO\SAVE\savedata.dat" mode "a+"  // IF and SET
0A9E: writefile $FILE size 128 from [email protected][[email protected]]
wait 1000
0A9B: closefile $FILE
0ACD: "Successfully saved" 2000
Player.CanMove($PLAYER_CHAR, 1)
jump @Main_Menu_Choice

:ERROR
wait 0
if
   8AAB: not file_exists "CLEO\SAVE\savedata.dat"
jf @Main_Menu_Choice_5_Menu
0ACD: show_text_highpriority "File 'savedata.dat' or Folder not found. Please check again" time 2000
Player.CanMove($PLAYER_CHAR, 1)
jump @Main_Menu

Well, i'm kinda of noob so, will you fix this. [email protected][[email protected]] is a object and $FILE is the variable of file. This ones write the object in "savedata.dat" file.

 

Data successfully stores and it looks like this:

                                                                                                                               H                                                                                                                             

But i can't load the object. Here:

:Main_Menu_Choice_6_Menu
wait 0
if
  0AAB:   file_exists "CLEO\SAVE\savedata.dat"
jf @ERROR2
0A9A: $FILE = openfile "CLEO\SAVE\savedata.dat" mode "r"  // IF and SET
0A9D: readfile $FILE size 128 to $RFILE
0A9B: closefile $FILE
0ACD: show_text_highpriority "File Successfully Loaded" time 2000
Player.CanMove($PLAYER_CHAR, 1)
jump @Main_Menu


:ERROR2
wait 0
if
  8AAB: not  file_exists "CLEO\SAVE\savedata.dat"
jf @Main_Menu_Choice_6_Menu
0ACD: show_text_highpriority "File 'savedata.dat' or Folder not found. Please check again" time 2000
Player.CanMove($PLAYER_CHAR, 1)
jump @Main_Men

Can you fix this?

 

The answer is 2nd one. It's a modpack you can say.


ZAZ
  • ZAZ

    Kernlochbohrer

  • Feroci
  • Joined: 10 Jan 2005
  • European-Union
  • Contribution Award [Mods]
    Helpfulness Awards [Mods]

#7

Posted 4 weeks ago

I give you a template to do it by read/write ini file

Create first an ini file with this content:
[object1]
objectID=1225; barrel4
X=2494.7246
Y=-1671.244
Z=13.3
A=1.1
and save it as Objectspawn.ini inside cleo folder

And here's the cleo script:
{$CLEO .cs}
thread 'coords'

while true
wait 0
    if 
        0AB0:   key_pressed 8// press Backspace
    then
        if 
            0A9A: [email protected] = openfile "CLEO\Objectspawn.ini" mode 114  // binary read
        then
            0AF0: [email protected] = get_int_from_ini_file "CLEO\Objectspawn.INI" section "object1" key "objectID" //IF and SET
            0AF2: [email protected] = get_float_from_ini_file "CLEO\Objectspawn.INI" section "object1" key "x"
            0AF2: [email protected] = get_float_from_ini_file "CLEO\Objectspawn.INI" section "object1" key "y"
            0AF2: [email protected] = get_float_from_ini_file "CLEO\Objectspawn.INI" section "object1" key "z"
            0AF2: 14@ = get_float_from_ini_file "CLEO\Objectspawn.INI" section "object1" key "a"
            0A9B: closefile [email protected]
            
            0247: load_model [email protected]
            038B: load_requested_models
            029B: [email protected] = init_object [email protected] at [email protected] [email protected] [email protected]
            0177: set_object [email protected] z_angle_to  [email protected]
            0249: unload_model [email protected]

        end
        wait 1000        
    end

    if 
        0AB0:   key_pressed 9// press TAB
    then
            [email protected] = 1607// dolphin
            [email protected] = 2478.151
            [email protected] = -1662.19
            [email protected] = 13.34
            [email protected] = 151.612
            0247: load_model [email protected]
            038B: load_requested_models
            029B: [email protected] = init_object [email protected] at [email protected] [email protected] [email protected]
            0177: set_object [email protected] z_angle_to  [email protected]
            0249: unload_model [email protected]
        if 
            0A9A: [email protected] = openfile "CLEO\Objectspawn.ini" mode 114  // binary read
        then
            0AF1: write_int [email protected] to_ini_file "CLEO\Objectspawn.INI" section "object2" key "objectID"
            0AF3: write_float [email protected] to_ini_file "CLEO\Objectspawn.INI" section "object2" key "x"
            0AF3: write_float [email protected] to_ini_file "CLEO\Objectspawn.INI" section "object2" key "y"
            0AF3: write_float [email protected] to_ini_file "CLEO\Objectspawn.INI" section "object2" key "z"
            0AF3: write_float [email protected] to_ini_file "CLEO\Objectspawn.INI" section "object2" key "a"
            0A9B: closefile [email protected]
        end
        wait 1000
    end
end 

Then go ingame into Grovestreet and press Backspace to spawn the object by reading data of the ini file, it's a Barrel4
Then press TAB to spawn another object, it's a dolphin
Then minimize the game and view to the Objectspawn.ini to see the new entries

Marty McFlaY
  • Marty McFlaY

    If you cant run, then walk, if you cant walk, then crawl :)

  • Members
  • Joined: 25 Feb 2016
  • England

#8

Posted 4 weeks ago

I'm using Global Variables in SCM and still its crashing. Don't know why. The file successfully write but it crashes + my object ID is in array form. It's giving wrong ID everytime of object + also wrong X,Y,Z and Angle coords. 

 

Could you have another way like: DYOM? They store every and each things by writing just variables with small calculation. I don't know how to do that. If you have any example like that then please give that to me.


ZAZ
  • ZAZ

    Kernlochbohrer

  • Feroci
  • Joined: 10 Jan 2005
  • European-Union
  • Contribution Award [Mods]
    Helpfulness Awards [Mods]

#9

Posted 4 weeks ago

I'm using Global Variables in SCM and still its crashing. Don't know why. The file successfully write but it crashes + my object ID is in array form. It's giving wrong ID everytime of object + also wrong X,Y,Z and Angle coords. 

Post your main.scm script. if it's too big, then describe the content of your main.scm script and post the script that spawn the objects.

 

Could you have another way like: DYOM? They store every and each things by writing just variables with small calculation. I don't know how to do that. If you have any example like that then please give that to me.

what do you want? save the the objects in a save file when you make a savegame? or do you wanna write the spawn data into a textfile?
  • deltaCJ likes this

deltaCJ
  • deltaCJ

    Davy Jones' Sock

  • Members
  • Joined: 27 Dec 2013
  • Unknown

#10

Posted 3 weeks ago

@MartyMcFlay,

Use ZAZ's script, and see if it works, but don't use SCM then you need to start from NEW game.

 

After using ZAZ's script try to replace the models with your models, and see if they are imported back in.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users