Saving system
#1

I have a problem with saving system I made a command to save business but it's not working I get like "UNKNOWN COMMAND" IG and the command exists here's the code

Код:
CMD:savebiz(playerid, params[])
{
    new DB_Query[2000];
	//Running a query to save the player's data using the stored stuff.
	for(new i; i <= MAX_BUSINESS; i++)
	{
	    if(Business[i][Used])
	    {
			mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `BUSINESS` SET `NAME` = %s, `TYPE` = %d, `PRODUCT` = %d, `FEE` = %d, `SAFE` = %d, `VW` = %d, `INT` = %d, `OWNER` = %d, `PRICE` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f WHERE `ID` = %d LIMIT 1",
			Business[i][Name],Business[i][Type],Business[i][Product],Business[i][Fee],Business[i][Safe],Business[i][Vw],Business[i][Int],Business[i][Owner],Business[i][Price],Business[i][PosX],Business[i][PosY],Business[i][PosZ],i);
			mysql_tquery(Database, DB_Query);
		}
	}
    return SendClientMessage(playerid, COLOR_RED,"DONE DONE DONE DONE");
}
Reply
#2

Give me your enum.
Reply
#3

Quote:
Originally Posted by kovac
Посмотреть сообщение
Give me your enum.
here you go

Код:
enum ENUM_BUSINESS_DATA
{
	Name[125],
	Type,
	Product,
	Fee,
	Safe,
	Vw,
	Int,
	Owner,
	Price,
	Float:PosX,
	Float:PosY,
	Float:PosZ,
	Text3D: BizText[MAX_BUSINESS],
	bool: Used,
}
Reply
#4

Index is going out of range due to loop going further than max businesses
So set the loop to less than (<) only
pawn Код:
CMD:savebiz(playerid, params[])
{
    new DB_Query[2000];
    //Running a query to save the player's data using the stored stuff.
    for(new i; i < MAX_BUSINESS; i++)
    {
        if(Business[i][Used])
        {
            mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `BUSINESS` SET `NAME` = %s, `TYPE` = %d, `PRODUCT` = %d, `FEE` = %d, `SAFE` = %d, `VW` = %d, `INT` = %d, `OWNER` = %d, `PRICE` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f WHERE `ID` = %d LIMIT 1",
            Business[i][Name],Business[i][Type],Business[i][Product],Business[i][Fee],Business[i][Safe],Business[i][Vw],Business[i][Int],Business[i][Owner],Business[i][Price],Business[i][PosX],Business[i][PosY],Business[i][PosZ],i);
            mysql_tquery(Database, DB_Query);
        }
    }
    return SendClientMessage(playerid, COLOR_RED,"DONE DONE DONE DONE");
}
Reply
#5

1. You can't save a string with %d, use %s instead (Talking about "Owner")
* ^ More about formatting here - https://sampwiki.blast.hk/wiki/Format
2. You're looping incorrectly, we're replacing for(new i; i <= MAX_BUSINESS; i++) with for(new i = 0; i < MAX_BUSINESS; i++)
3. Owner name in enum must be specifed as string, so we're putting [MAX_PLAYER_NAME] next to it.
4. Replacing Text3D: BizText[MAX_BUSINESS] with Text3D:BizzText so you can later use it as BizzText from your enum
5. Always use apostrophe " ' " betweed %d, %s or similar while formatting mysql query (only)

The final code should look like this:
PHP код:
CMD:savebiz(playeridparams[])
{
    new 
DB_Query[2000];
    for(new 
0MAX_BUSINESSi++)
    {
        if(
Business[i][Used] == true)
        {
             
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `BUSINESS` SET `NAME`='%s',`TYPE`='%d',`PRODUCT`='%d',`FEE`='%d',`SAFE`='%d',`VW`='%d',`INT`='%d',`OWNER`='%s',`PRICE`='%d',`PosX`='%f',`PosY`='%f',`PosZ`='%f' WHERE `ID`='%d' LIMIT 1"Business[i][Name],Business[i][Type],Business[i][Product],Business[i][Fee],Business[i][Safe],Business[i][Vw],Business[i][Int],Business[i][Owner],Business[i][Price],Business[i][PosX],Business[i][PosY],Business[i][PosZ],i);
            
mysql_tquery(DatabaseDB_Query);
        }
    }
    
SendClientMessage(playeridCOLOR_RED,"DONE DONE DONE DONE");
    return 
1;

PHP код:
enum ENUM_BUSINESS_DATA
{
    
Name[125],
    
Type,
    
Product,
    
Fee,
    
Safe,
    
Vw,
    
Int,
    
Owner[MAX_PLAYER_NAME],
    
Price,
    
Float:PosX,
    
Float:PosY,
    
Float:PosZ,
    
Text3D:BizText,
    
boolUsed,
}
new 
Business[MAX_BUSINESS][ENUM_BUSINESS_DATA]; 
And I don't know why are you saving businesses like this at all
Reply
#6

Aigh thank you the loop stuff worked but now the saving process is not working lol. However, kovac I'm saving it like that cuz I wanna make sure that everything is working alright then I will add more stuffs ! thank you very much <3
Reply
#7

Quote:
Originally Posted by Nru
Посмотреть сообщение
Aigh thank you the loop stuff worked but now the saving process is not working lol. However, kovac I'm saving it like that cuz I wanna make sure that everything is working alright then I will add more stuffs ! thank you very much <3
What is the problem?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)