SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 25/05/2019, 06:59 PM   #1
DerickClark
High-roller
 
Join Date: Jul 2012
Posts: 1,752
Reputation: 14
Default Repair System database

Repair system loading created another one in the database.

OnGameModeInit:

Code:
    for(new i = 0; i != sizeof(ARepairPickups); i++)
	ARepairPickups[i][PickupID] = -1;
	mysql_tquery(MySQL, "SELECT * FROM `repair_system`", "OnLoadRepairPickups");
Code:
forward OnLoadRepairPickups(playerid);
public OnLoadRepairPickups()
{
    new count;
	cache_get_row_count(count); // Get total rows
    for(new i; i < count; i++)
	{
        cache_get_value_name_int(i, "PickupID", ARepairPickups[i][PickupID]);
        cache_get_value_float(i, "pux",ARepairPickups[i][pux]);
        cache_get_value_float(i, "puy",ARepairPickups[i][puy]);
        cache_get_value_float(i, "puz",ARepairPickups[i][puz]);
        ARepairPickups[i][PickupID] = AddARepairPickups(ARepairPickups[i][pux],ARepairPickups[i][puy],ARepairPickups[i][puz]);
        print("repair_system loaded");
	}
	return 1;
}
Attached Images
File Type: png Wrong.PNG (5.7 KB, 5 views)
__________________
Working on a Trucking Server from scratch.
There are cool features, like /workmenu /convoy /pay(When Police Officer asked you for a fine) and more etc.
DerickClark is offline   Reply With Quote
Old 25/05/2019, 07:48 PM   #2
Macronix
Huge Clucker
 
Macronix's Avatar
 
Join Date: Jul 2010
Location: Germany
Posts: 476
Reputation: 100
Default Re: Repair System database

Can you post the function AddARepairPickups ?
Macronix is offline   Reply With Quote
Old 25/05/2019, 07:50 PM   #3
DerickClark
High-roller
 
Join Date: Jul 2012
Posts: 1,752
Reputation: 14
Default Re: Repair System database

Quote:
Originally Posted by Macronix View Post
Can you post the function AddARepairPickups ?
Code:
AddARepairPickups(Float:x, Float:y, Float:z)
{
	for (new i; i < sizeof(ARepairPickups); i++)
	{
		if (ARepairPickups[i][PickupID] == -1)
		{
            new query[128];
            new string[100];
			ARepairPickups[i][PickupID] = CreatePickup(3096, 1, x, y, z, 0);
			ARepairPickups[i][pux] = x;
			ARepairPickups[i][puy] = y;
			ARepairPickups[i][puz] = z;
			Create3DTextLabel("{FFFF00}Type {00FF00}/repair {FFFF00}to repair your vehicle!", -1, x, y, z +0.5, 50.0, 0);
			CreateDynamicMapIcon(x, y, z, 27, 0, 0, 0, -1, 300.0);
			printf("PickupID: %d, PosX: %.4f, PosY: %.4f, PosZ: %.4f",ARepairPickups[i][PickupID],x,y,z);
            mysql_format(MySQL, query, 128, "INSERT INTO `repair_system` (`PickupID`, `pux`,`puy`,`puz`) VALUES (%d, %f, %f, %f)",ARepairPickups[i][PickupID], x, y, z); // Use %f specifier here, because we insert float for pux puy puz
            mysql_tquery(MySQL, query, "AddARepairPickups", "dfff", ARepairPickups[i][PickupID], x, y, z); // AddARepairPickups must be a public function
       	    format(string, sizeof(string), "Repair_system created ID: %d", ARepairPickups[i][PickupID]);
	        SendClientMessageToAll(0xFFFFFFFF, string);
			break;
		}
	}
}
__________________
Working on a Trucking Server from scratch.
There are cool features, like /workmenu /convoy /pay(When Police Officer asked you for a fine) and more etc.
DerickClark is offline   Reply With Quote
Old 25/05/2019, 07:53 PM   #4
Macronix
Huge Clucker
 
Macronix's Avatar
 
Join Date: Jul 2010
Location: Germany
Posts: 476
Reputation: 100
Default Re: Repair System database

Everytime this function is called, you insert a new pickup to the database. Even on loading.
Macronix is offline   Reply With Quote
Old 26/05/2019, 03:08 AM   #5
DerickClark
High-roller
 
Join Date: Jul 2012
Posts: 1,752
Reputation: 14
Default Re: Repair System database

i need to create another function
to load it?
__________________
Working on a Trucking Server from scratch.
There are cool features, like /workmenu /convoy /pay(When Police Officer asked you for a fine) and more etc.
DerickClark is offline   Reply With Quote
Old 26/05/2019, 01:07 PM   #6
Macronix
Huge Clucker
 
Macronix's Avatar
 
Join Date: Jul 2010
Location: Germany
Posts: 476
Reputation: 100
Default Re: Repair System database

No, you don't have to. You just copy some of the content of your AddARepairPickups function to the loading function:

pawn Code:
public OnLoadRepairPickups()
{
    new count;
    cache_get_row_count(count); // Get total rows
    for(new i; i < count; i++)
    {
        cache_get_value_name_int(i, "PickupID", ARepairPickups[i][PickupID]);
        cache_get_value_float(i, "pux",ARepairPickups[i][pux]);
        cache_get_value_float(i, "puy",ARepairPickups[i][puy]);
        cache_get_value_float(i, "puz",ARepairPickups[i][puz]);

        ARepairPickups[i][PickupID] = CreatePickup(3096, 1, ARepairPickups[i][pux], ARepairPickups[i][puy], ARepairPickups[i][puz], 0);
        Create3DTextLabel("{FFFF00}Type {00FF00}/repair {FFFF00}to repair your vehicle!", -1, ARepairPickups[i][pux], ARepairPickups[i][puy], ARepairPickups[i][puz] +0.5, 50.0, 0);
        CreateDynamicMapIcon(ARepairPickups[i][pux], ARepairPickups[i][puy], ARepairPickups[i][puz], 27, 0, 0, 0, -1, 300.0);
        printf("PickupID: %d, PosX: %.4f, PosY: %.4f, PosZ: %.4f",ARepairPickups[i][PickupID], ARepairPickups[i][pux], ARepairPickups[i][puy], ARepairPickups[i][puz]);

        print("repair_system loaded");
    }
    return 1;
}
Macronix 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
Repair System, Not Loading. DerickClark Scripting Help 14 25/02/2017 01:39 PM
Save Repair System DerickClark Scripting Help 2 13/02/2017 12:48 AM
(All) how do I repair the database failed gogo45 Server Support 4 31/12/2015 11:02 AM
[HELP] Nitro and Repair system arjanforgames Scripting Help 9 24/01/2012 07:43 PM


All times are GMT. The time now is 09:44 PM.


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