MYSQL Load Weapon Problem
#1

Hello Guys, after seeking around big time i couldnt solve that problem , it's not error it's not bug but it's something like MYSQL doesn't doing his JOB
After The Player Store's his weapons In House , it Stores the First Slot and if he want to store an other weapon he can in too and it saves in mysql DB.. BUt ! BUT ! when im re-booting the server , The Save(data) still in the DB , and if player goes to his house and doing
PHP код:
/checksafe 
he will find ONLY FIrst Slot with the first gun he store's it , second one gone!! , but he is still in DB .. i can see the Id weapon and ammo in DB , in server i cannot , it doesnt load all the stored Guns from the Database .


i hope from you guys helping me with this ..
PHP код:
YCMD:storeweapon(playeridparams[], help)
{
    if(
help) return SCM(playeridCOLOR_GREY"Not supported");
    if(
IsPlayerConnected(playerid))
    {
            new 
string[256], ammohouse PlayerInfo[playerid][pPhousekey];
            new 
gunname[24];
            if(
IsPlayerInRangeOfPoint(playerid15HouseInfo[house][hExitx],HouseInfo[house][hExity],HouseInfo[house][hExitz]))
            {
                if(
sscanf(params"d"ammo))
                {
                    
SCM(playeridCOLOR_GRAD1"USAGE: /storeweapon [ammo]");
                    return 
1;
                }
                if(
ammo GetPlayerAmmo(playerid))
                {
                    
SCM(playeridCOLOR_GREY"   You don't have so many Ammo.");
                    return 
1;
                }
                new 
weapon GetPlayerWeapon(playerid);
                
GetWeaponName(weapon,gunnamesizeof(gunname));
                if(
weapon != 0)
                {
                    if(
HouseInfo[house][hWeapon][0] == 0)
                    {
                        if(
HouseInfo[house][hAmmo][0] >= 25000) return SCM(playeridCOLOR_GREY,"* You cannot exceed the 25000 Limit.");
                        
SafeGivePlayerWeapon(playeridweapon, -ammo);
                        
HouseInfo[house][hWeapon][0] = weapon;
                        
HouseInfo[house][hAmmo][0] = ammo;
                        if(
PlayerInfo[playerid][pSex] == 1) { format(stringsizeof(string), "* %s takes out his %s and places it at his safe."GetPlayerNameEx(playerid),gunname); }
                        else { 
format(stringsizeof(string), "* %s takes out her %s and places it at her safe."GetPlayerNameEx(playerid),gunname); }
                        
ProxDetector(30.0playeridstringCOLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    }
                    else if(
HouseInfo[house][hWeapon][0] == weapon)
                    {
                        if(
HouseInfo[house][hAmmo][0] >= 25000) return SCM(playeridCOLOR_GREY,"* You cannot exceed the 25000 Limit.");
                        
SafeGivePlayerWeapon(playeridweapon, -ammo);
                        
HouseInfo[house][hAmmo][0] += ammo;
                        if(
PlayerInfo[playerid][pSex] == 1) { format(stringsizeof(string), "* %s takes out his %s and places it at his safe."GetPlayerNameEx(playerid),gunname); }
                        else { 
format(stringsizeof(string), "* %s takes out her %s and places it at her safe."GetPlayerNameEx(playerid),gunname); }
                        
ProxDetector(30.0playeridstringCOLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    }
                    else if(
HouseInfo[house][hWeapon][0] != && HouseInfo[house][hWeapon][1] == 0)
                    {
                        if(
HouseInfo[house][hAmmo][1] >= 25000) return SCM(playeridCOLOR_GREY,"* You cannot exceed the 25000 Limit.");
                        
SafeGivePlayerWeapon(playeridweapon, -ammo);
                        
HouseInfo[house][hWeapon][1] = weapon;
                        
HouseInfo[house][hAmmo][1] = ammo;
                        if(
PlayerInfo[playerid][pSex] == 1) { format(stringsizeof(string), "* %s takes out his %s and places it at his safe."GetPlayerNameEx(playerid),gunname); }
                        else { 
format(stringsizeof(string), "* %s takes out her %s and places it at her safe."GetPlayerNameEx(playerid),gunname); }
                        
ProxDetector(30.0playeridstringCOLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    }
                    else if(
HouseInfo[house][hWeapon][1] == weapon)
                    {
                        if(
HouseInfo[house][hAmmo][1] >= 25000) return SCM(playeridCOLOR_GREY,"* You cannot exceed the 25000 Limit.");
                        
SafeGivePlayerWeapon(playeridweapon, -ammo);
                        
HouseInfo[house][hAmmo][1] += ammo;
                        if(
PlayerInfo[playerid][pSex] == 1) { format(stringsizeof(string), "* %s takes out his %s and places it at his safe."GetPlayerNameEx(playerid),gunname); }
                        else { 
format(stringsizeof(string), "* %s takes out her %s and places it at her safe."GetPlayerNameEx(playerid),gunname); }
                        
ProxDetector(30.0playeridstringCOLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    }
                    else
                    {
                        
SCM(playeridCOLOR_GREY,"* This slot is taken by another weapon!");
                        return 
1;
                    }
                    
OnPropUpdate(1house);
                }
                else
                {
                    
SCM(playeridCOLOR_GREY,"* This slot is taken by another weapon!");
                    
SCM(playeridCOLOR_GREY,"* Either deposit more ammo of the same weapon or load it up!");
                    return 
1;
                }
            }
            else
            {
                
SCM(playeridCOLOR_GREY,"* You're not on your House!");
                return 
1;
            }
    }
    return 
1;

PHP код:
YCMD:checksafe(playeridparams[], help)
{
    if(
help) return SCM(playeridCOLOR_GREY"Not supported");
    if(
IsPlayerConnected(playerid))
    {
        new 
house PlayerInfo[playerid][pPhousekey];
        new 
gunname[24];
        new 
gunname1[24];
        new 
gunname2[24];
        new 
gunname3[24];
        new 
gunname4[24];
        new 
gunname5[24];
        new 
string[256];
        
GetWeaponName(HouseInfo[house][hWeapon][0],gunnamesizeof(gunname));
        
GetWeaponName(HouseInfo[house][hWeapon][1],gunname1sizeof(gunname1));
        
GetWeaponName(HouseInfo[house][hWeapon][2],gunname2sizeof(gunname2));
        
GetWeaponName(HouseInfo[house][hWeapon][3],gunname3sizeof(gunname3));
        
GetWeaponName(HouseInfo[house][hWeapon][4],gunname4sizeof(gunname4));
        
GetWeaponName(HouseInfo[house][hWeapon][5],gunname5sizeof(gunname5));
        if(
IsPlayerInRangeOfPoint(playerid15HouseInfo[house][hExitx],HouseInfo[house][hExity],HouseInfo[house][hExitz]))
        {
            
format(stringsizeof(string),"-HOUSE STORAGE- You have %d Drugs and %d Materials.",HouseInfo[house][hDrugs],HouseInfo[house][hMaterials]);
            
SCM(playeridCOLOR_GREY,string);
            
format(stringsizeof(string),"-HOUSE STORAGE- Weapon 0 - %s Ammo: %d.",gunname,HouseInfo[house][hAmmo][0]);
            
SCM(playeridCOLOR_GREY,string);
            
format(stringsizeof(string),"-HOUSE STORAGE- Weapon 1 - %s Ammo: %d.",gunname1,HouseInfo[house][hAmmo][1]);
            
SCM(playeridCOLOR_GREY,string);
            
format(stringsizeof(string),"-HOUSE STORAGE- Weapon 2 - %s Ammo: %d.",gunname2,HouseInfo[house][hAmmo][2]);
            
SCM(playeridCOLOR_GREY,string);
            
format(stringsizeof(string),"-HOUSE STORAGE- Weapon 3 - %s Ammo: %d.",gunname3,HouseInfo[house][hAmmo][3]);
            
SCM(playeridCOLOR_GREY,string);
            
format(stringsizeof(string),"-HOUSE STORAGE- Weapon 5 - %s Ammo: %d.",gunname4,HouseInfo[house][hAmmo][4]);
            
SCM(playeridCOLOR_GREY,string);
            
format(stringsizeof(string),"-HOUSE STORAGE- Weapon 5 - %s Ammo: %d.",gunname5,HouseInfo[house][hAmmo][5]);
            
SCM(playeridCOLOR_GREY,string);
        }
        else
        {
            
SCM(playeridCOLOR_GRAD1"   You are not Logged in!");
            return 
1;
        }
    }
    return 
1;

PHP код:

stock LoadProperty
()
{
    print(
"[SCRIPT]: Loading MySQL Properties");
    
inline SQLLoadProperty() {
        new
            
rows,
            
cols,
            
currentRow,
            
idx,
            
previousId,
            
tmp,
            
fx 0,
            
loadedWeapons 0;
        
cache_get_data(rowscolsdbhandle);
        if(!
rows) return printf("[SCRIPT]: The SQL Houses loading query returned 0 results");
        for(
currentRow 0currentRow != rows; ++currentRowfx 0loadedWeapons 0) {
            
tmp cache_get_row_int(currentRowfx++, dbhandle);
            
//Property weapons in joined query
            
if(previousId == tmp) {
                if(
MAX_PROPERTY_WEAPONS != loadedWeapons) {
                    
HouseInfo[idx][hWeapon][loadedWeapons] = cache_get_field_content_int(currentRow"pw_weapon"dbhandle);
                    
HouseInfo[idx][hAmmo][loadedWeapons] = cache_get_field_content_int(currentRow"pw_ammo"dbhandle);
                    ++
loadedWeapons;
                }
                continue;
            } else 
previousId tmp;
            
HouseInfo[idx][hdbID]         = tmp;
            
HouseInfo[idx][hEntrancex]  = cache_get_row_float(currentRowfx++, dbhandle);
            
HouseInfo[idx][hEntrancey]  = cache_get_row_float(currentRowfx++, dbhandle);
            
HouseInfo[idx][hEntrancez]  = cache_get_row_float(currentRowfx++, dbhandle);
            
HouseInfo[idx][hExitx]         = cache_get_row_float(currentRowfx++, dbhandle);
            
HouseInfo[idx][hExity]         = cache_get_row_float(currentRowfx++, dbhandle);
            
HouseInfo[idx][hExitz]         = cache_get_row_float(currentRowfx++, dbhandle);
            
HouseInfo[idx][hHealthx]    = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hHealthy]     = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hHealthz]     = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hArmourx]     = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hArmoury]     = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hArmourz]     = cache_get_row_int(currentRowfx++, dbhandle);
            
cache_get_row(currentRowfx++, HouseInfo[idx][hOwner], dbhandle255);
            
cache_get_row(currentRowfx++, HouseInfo[idx][hDiscription], dbhandle255);
            
HouseInfo[idx][hValue]         = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hHel]         = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hArm]         = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hInt]         = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hLock]         = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hOwned]         = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hRooms]         = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hRentabil]     = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hRent]         = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hTakings]     = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hLevel]         = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hWorld]         = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hSetted]     = 1;
            
HouseInfo[idx][hDrugs]         = cache_get_row_int(currentRowfx++, dbhandle);
            
HouseInfo[idx][hMaterials]  = cache_get_row_int(currentRowfx++, dbhandle);
            
cache_get_row(currentRowfx++, HouseInfo[idx][hMessage], dbhandle255);
            
OnHousePickupUpdate(idx);
            
OnPropTextdrawUpdate(1idx);
            
Iter_Add(HouseInfoidx);
            ++
idx;
            if(
idx == MAX_LOADED_PROPERTIES) {
                
printf("[SCRIPT]: Notice - there's more properties in database than script can handle. Tweak your MAX_LOADED_PROPERTIES settings");
                break;
            }
        }
        
printf("[SCRIPT]: Loaded MySQL Houses (%d)"idx);
        return 
1;
    }
    
mysql_tquery_inline(dbhandle"SELECT p.*,    pw.weapon AS pw_weapon, pw.ammo AS pw_ammo FROM properties p LEFT JOIN property_weapons pw ON pw.pid = p.id ORDER BY p.id ASC, pw.id ASC"using inline SQLLoadProperty"");
    return 
1;

Reply
#2

What is your code for loading the database after a reboot? That's most likely where the issue is located.
Reply
#3

The
PHP код:
stock loadproperty 
the one who is loading the house weapons dude ..
Reply
#4

Quote:
Originally Posted by MCZOFT
Посмотреть сообщение
The
PHP код:
stock loadproperty 
the one who is loading the house weapons dude ..
Bare with me since I'll admit I'm a bit out of it at the moment (stoned), but looking at it my guess would be:

Код:
if(previousId == tmp) {
                if(MAX_PROPERTY_WEAPONS != loadedWeapons) {
                    HouseInfo[idx][hWeapon][loadedWeapons] = cache_get_field_content_int(currentRow, "pw_weapon", dbhandle);
                    HouseInfo[idx][hAmmo][loadedWeapons] = cache_get_field_content_int(currentRow, "pw_ammo", dbhandle);
                    ++loadedWeapons;
                }
                continue;
            } else previousId = tmp;
That you aren't looping this anywhere in any way, therefore it just loads one which is for example: HouseInfo[idx][hWeapon][0] since it never loops around to reach HouseInfo[idx][hWeapon][1] or 2. hence atm
Код:
++loadedWeapons;
doesn't really do anything.
Reply
#5

i really didnt got your point .. How then we can fix it ?
Reply
#6

Got a question before I can really help further, since I'm a bit confused.
How do you store the weapons in the db? Are they in the same column or seperate columns for each weapon?

But I mean looking at your code the problem is like I said, you're not loading weapons properly in your loading function, since you don't seem to be looping through LoadedWeapons stuff so it never reaches higher than 0 hence it only loads one weapon/ammo.
Reply
#7

there is two Tables , The First i called hem Propreties , he contains this

PHP код:

            HouseInfo
[idx][hdbID]         = tmp
            
HouseInfo[idx][hEntrancex]  = cache_get_row_float(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hEntrancey]  = cache_get_row_float(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hEntrancez]  = cache_get_row_float(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hExitx]         = cache_get_row_float(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hExity]         = cache_get_row_float(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hExitz]         = cache_get_row_float(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hHealthx]    = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hHealthy]     = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hHealthz]     = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hArmourx]     = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hArmoury]     = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hArmourz]     = cache_get_row_int(currentRowfx++, dbhandle); 
            
cache_get_row(currentRowfx++, HouseInfo[idx][hOwner], dbhandle255); 
            
cache_get_row(currentRowfx++, HouseInfo[idx][hDiscription], dbhandle255); 
            
HouseInfo[idx][hValue]         = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hHel]         = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hArm]         = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hInt]         = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hLock]         = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hOwned]         = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hRooms]         = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hRentabil]     = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hRent]         = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hTakings]     = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hLevel]         = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hWorld]         = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hSetted]     = 1
            
HouseInfo[idx][hDrugs]         = cache_get_row_int(currentRowfx++, dbhandle); 
            
HouseInfo[idx][hMaterials]  = cache_get_row_int(currentRowfx++, dbhandle); 
            
cache_get_row(currentRowfx++, HouseInfo[idx][hMessage], dbhandle255); 
But if you put the
PHP код:
Query 
PHP код:
 SELECT p.*,    pw.weapon AS pw_weaponpw.ammo AS pw_ammo FROM properties p LEFT JOIN property_weapons pw ON pw.pid p.id ORDER BY p.id ASCpw.id ASC 
in SQL search he will give you the The first code (above ) + column of pw_weapon and pw_ammo besides Messages column

and there is another Table , wich i called hem Proprety_weapons , his work to save each proprety(house) with 6 slots of weapons , and he acualty doing it , he saves the weapon ID and the AMMO ,

PHP код:
    mysql_tquery_inline(dbhandle"SELECT p.*,    pw.weapon AS pw_weapon, pw.ammo AS pw_ammo FROM properties p LEFT JOIN property_weapons pw ON pw.pid = p.id ORDER BY p.id ASC, pw.id ASC"using inline SQLLoadProperty""); 
hope you understand me ,
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)