SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/07/2020, 12:56 AM   #1
LowIQ
Little Clucker
 
Join Date: May 2019
Posts: 41
Reputation: 5
Default Saving&Loading 100 Variables

Hello, what is the best way to save and load something like this?

Code:
new ZoneChecker[100];

CMD:test(playerid, params[])
{
     new X = random(100);

     if(Something)
     {
     ZoneChecker[X] = 0;
     return 1;
     }
     if(SomethingElse)
     {
     ZoneChecker[X] = 1;
     return 1;
     }
     return 0;
     
}
What is the best way to save all of this: ZoneChecker[100], to one file?
like:

Code:
ZoneChecker[0] = 0;
ZoneChecker[1] = 1;
ZoneChecker[2] = 0;
ZoneChecker[3] = 0;
...
ZoneChecker[99] = 0;
And then i need to read it so i will load that:

Code:
ZoneChecker[0] = 0;
ZoneChecker[1] = 1;
ZoneChecker[2] = 0;
ZoneChecker[3] = 0;
...
ZoneChecker[99] = 0;
into the gamemode again..
LowIQ is offline   Reply With Quote
Old 12/07/2020, 08:26 AM   #2
Lexless
Little Clucker
 
Join Date: May 2020
Posts: 38
Reputation: 14
Default Re: Saving&Loading 100 Variables

Use INI or MYSQL.
Lexless is offline   Reply With Quote
Old 13/07/2020, 12:00 AM   #3
LowIQ
Little Clucker
 
Join Date: May 2019
Posts: 41
Reputation: 5
Default Re: Saving&Loading 100 Variables

I would like to do it with INI or TxT but i have no idea what to do...
Can u tell me some example?
Do i need to make enum for all 100 variables and save it one by one and how can i load the exact one?
LowIQ is offline   Reply With Quote
Old 14/07/2020, 10:22 AM   #4
LowIQ
Little Clucker
 
Join Date: May 2019
Posts: 41
Reputation: 5
Default Re: Saving&Loading 100 Variables

Anyone?
LowIQ is offline   Reply With Quote
Old 14/07/2020, 10:53 AM   #5
iRob
Little Clucker
 
Join Date: Apr 2019
Posts: 4
Reputation: 0
Default Re: Saving&Loading 100 Variables

As Lexless has me mentioned above, INI or MySQL
regarding INI file, I suggest you to read this tutorial https://forum.sa-mp.com/showthread.php?t=430722
This post gonna help you to read/write to any file in your server's computer.

about MySQL,
First of all you will need a table to store these values, for example, here's a table creation query that could help you

Code:
CREATE TABLE IF NOT EXISTS `ZoneChecker` (
  `ZoneNumber` int(11) NOT NULL,
  `Check` int(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`ZoneNumber`)
)
You can store in this table ZoneNumber which is the number you've listed above as an index on your array.
On Check field, you can store values that are integers with 1 digit. such as, 0 & 1

To insert into this table;
Code:
INSERT INTO `ZoneChecker` (`ZoneNumber`,`Check`) VALUES (1,0);
1 is the ZoneNumber field value,
0 is the Check field value

if the number exists you may use update query
To Update this table:
Code:
UPDATE `ZoneChecker`
SET `Check` = 1
WHERE `ZoneNumber` = 5
This query updates ZoneNumber 5 to 1. you may change the numbers.

you can get all the table field's values using this query
Code:
SELECT *
SET `ZoneChecker`
or you can get an exact ZoneNumber field's value:
Code:
SELECT `Check`
SET `ZoneChecker`
WHERE `ZoneNumber` = 5
These are some queries that could help you to save all these values somewhere else than your actual pawn files

to implement these into your actual code using pawno, SA-MP Wiki is a helpful documentation.
Here are some useful links to connect MySQL to your server.
https://github.com/pBlueG/SA-MP-MySQL/releases
https://wiki.sa-mp.com/wiki/MySQL

Good Luck
iRob is offline   Reply With Quote
Old 14/07/2020, 04:40 PM   #6
LowIQ
Little Clucker
 
Join Date: May 2019
Posts: 41
Reputation: 5
Default Re: Saving&Loading 100 Variables

Quote:
Originally Posted by iRob View Post
As Lexless has me mentioned above, INI or MySQL
regarding INI file, I suggest you to read this tutorial https://forum.sa-mp.com/showthread.php?t=430722
This post gonna help you to read/write to any file in your server's computer.

about MySQL..
I dont understand how this tutorial can help me to save anything to .ini file...

about MySQL.. I am not going to use MySQL.


I just need to save ZoneChecker[0-100] = 0 or 1;
and load ZoneChecker[0-100] = 0 or 1; into the gamemode.
LowIQ is offline   Reply With Quote
Old 14/07/2020, 05:29 PM   #7
iRob
Little Clucker
 
Join Date: Apr 2019
Posts: 4
Reputation: 0
Default Re: Saving&Loading 100 Variables

The link above is about reading or writing to any file not only .ini files.
I'll state some of that, You can use the basic functions of reading/writing:

Code:
fopen(FILE_PATH, io_write);
this function is used to open a file on writing mode. you can also use "io_write", "io_readwrite", "io_append.
you can read about it with the link I gave above.

however, I'll give you another tutorial which more specific to ini files: https://forum.sa-mp.com/showthread.php?t=548322
iRob is offline   Reply With Quote
Old 14/07/2020, 06:33 PM   #8
LowIQ
Little Clucker
 
Join Date: May 2019
Posts: 41
Reputation: 5
Default Re: Saving&Loading 100 Variables

Quote:
Originally Posted by iRob View Post
Code:
fopen(FILE_PATH, io_write);
I did this this way for the first time and i saved to txt this:

Code:
...
ZoneChecker[78] = 0;
ZoneChecker[69] = 1;
...
ect.
So anytime the zone got updated, "ZoneChecker[x] = x;" was written to the .txt file.
There was a problem with loading but the thing is that WRITES "ZoneChecker[x] = x;"
again and again and it makes endless .txt file.

So anytime "ZoneChecker[90] = x;" updates, then the .txt looks like

ZoneChecker[90] = 0;
ZoneChecker[90] = 1;
ZoneChecker[90] = 1;
ZoneChecker[90] = 0;

I need some system that rewrite the value of the specific zone so it does not make .txt file bigger and bigger.

Is there any example how to save all of SomeArray[100] = ?;
I have searched many topics and did not found any..
LowIQ is offline   Reply With Quote
Old 14/07/2020, 07:23 PM   #9
algorhitmically
Little Clucker
 
Join Date: Feb 2020
Posts: 35
Reputation: 22
Default Re: Saving&Loading 100 Variables

Well, you can load and save with this method:
pawn Code:
forward LoadZone(id, name[], value[]);
public LoadZone(id, name[], value[])
{
new Zone[8];
format(Zone, sizeof Zone, "Z_%d", id);
INI_Bool(Zone, ZoneVariable[id]);
return 1;
}

stock SaveZone(id)
{
new INI:File = INI_Open("Zones.ini");
INI_SetTag(File, "Zones");

new Zone[8];
format(Zone, sizeof Zone, "Z_%d", id);

INI_WriteBool(File, Zone, ZoneVariable[id]);
INI_Close(File);
return 1;
}
and then use loop to save/load zones you want.

You can also make seperate files for every zone so you can load it that way too.

There is classic file loading too(you can find it on samp wiki).

Maybe you should give sqlite a try if you don't want to use mysql.
algorhitmically is offline   Reply With Quote
Old 16/07/2020, 12:04 PM   #10
LowIQ
Little Clucker
 
Join Date: May 2019
Posts: 41
Reputation: 5
Default Re: Saving&Loading 100 Variables

Ok i tried this but i do something wrong

Code:
CMD:savezones(playerid, params[])
{

        for(new i = 0; i < sizeof(DAZoneCheck); i++)
	SaveZones(i);
	return 1;
}
CMD:loadzones(playerid, params[])
{
 
        for(new i = 0; i < sizeof(DAZoneCheck); i++)
	LoadZones(i);
	return 1;

}

Code:
forward LoadZones(id);
public LoadZones(id)
{
new Zone[16];
format(Zone, sizeof Zone, "ID%d_ST_%d", id,DAZoneCheck[id]);
INI_Int(Zone, id);
return 1;
}

stock SaveZones(id)
{
new INI:File = INI_Open("Zones.ini");
INI_SetTag(File, "Zones");

new Zone[16];
format(Zone, sizeof Zone, "ID%d_ST_%d",id,DAZoneCheck[id]);

INI_WriteInt(File, Zone);
INI_Close(File);
return 1;
}
does not work at all iam lost..
LowIQ is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving variables is saving under wrong car id's GunZ75 Scripting Help 0 07/08/2017 06:19 PM
Saving/Loading Variables hossam22 Scripting Help 0 10/07/2014 06:57 PM
Saving/Loading Variables hossam22 Server Support 1 10/07/2014 10:25 AM
Not loading all variables BlackRaven Scripting Help 3 13/02/2013 02:10 PM
Loading variables Antonio [G-RP] Help Archive 9 13/08/2011 09:00 AM


All times are GMT. The time now is 02:21 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.