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(playerid, params[], help)
{
    if(
help) return SCM(playerid, COLOR_GREY, "Not supported");
    if(
IsPlayerConnected(playerid))
    {
            new 
string[256], ammo, house = PlayerInfo[playerid][pPhousekey];
            new 
gunname[24];
            if(
IsPlayerInRangeOfPoint(playerid, 15, HouseInfo[house][hExitx],HouseInfo[house][hExity],HouseInfo[house][hExitz]))
            {
                if(
sscanf(params, "d", ammo))
                {
                    
SCM(playerid, COLOR_GRAD1, "USAGE: /storeweapon [ammo]");
                    return 
1;
                }
                if(
ammo > GetPlayerAmmo(playerid))
                {
                    
SCM(playerid, COLOR_GREY, "   You don't have so many Ammo.");
                    return 
1;
                }
                new 
weapon = GetPlayerWeapon(playerid);
                
GetWeaponName(weapon,gunname, sizeof(gunname));
                if(
weapon != 0)
                {
                    if(
HouseInfo[house][hWeapon][0] == 0)
                    {
                        if(
HouseInfo[house][hAmmo][0] >= 25000) return SCM(playerid, COLOR_GREY,"* You cannot exceed the 25000 Limit.");
                        
SafeGivePlayerWeapon(playerid, weapon, -ammo);
                        
HouseInfo[house][hWeapon][0] = weapon;
                        
HouseInfo[house][hAmmo][0] = ammo;
                        if(
PlayerInfo[playerid][pSex] == 1) { format(string, sizeof(string), "* %s takes out his %s and places it at his safe.", GetPlayerNameEx(playerid),gunname); }
                        else { 
format(string, sizeof(string), "* %s takes out her %s and places it at her safe.", GetPlayerNameEx(playerid),gunname); }
                        
ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    }
                    else if(
HouseInfo[house][hWeapon][0] == weapon)
                    {
                        if(
HouseInfo[house][hAmmo][0] >= 25000) return SCM(playerid, COLOR_GREY,"* You cannot exceed the 25000 Limit.");
                        
SafeGivePlayerWeapon(playerid, weapon, -ammo);
                        
HouseInfo[house][hAmmo][0] += ammo;
                        if(
PlayerInfo[playerid][pSex] == 1) { format(string, sizeof(string), "* %s takes out his %s and places it at his safe.", GetPlayerNameEx(playerid),gunname); }
                        else { 
format(string, sizeof(string), "* %s takes out her %s and places it at her safe.", GetPlayerNameEx(playerid),gunname); }
                        
ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    }
                    else if(
HouseInfo[house][hWeapon][0] != 0 && HouseInfo[house][hWeapon][1] == 0)
                    {
                        if(
HouseInfo[house][hAmmo][1] >= 25000) return SCM(playerid, COLOR_GREY,"* You cannot exceed the 25000 Limit.");
                        
SafeGivePlayerWeapon(playerid, weapon, -ammo);
                        
HouseInfo[house][hWeapon][1] = weapon;
                        
HouseInfo[house][hAmmo][1] = ammo;
                        if(
PlayerInfo[playerid][pSex] == 1) { format(string, sizeof(string), "* %s takes out his %s and places it at his safe.", GetPlayerNameEx(playerid),gunname); }
                        else { 
format(string, sizeof(string), "* %s takes out her %s and places it at her safe.", GetPlayerNameEx(playerid),gunname); }
                        
ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    }
                    else if(
HouseInfo[house][hWeapon][1] == weapon)
                    {
                        if(
HouseInfo[house][hAmmo][1] >= 25000) return SCM(playerid, COLOR_GREY,"* You cannot exceed the 25000 Limit.");
                        
SafeGivePlayerWeapon(playerid, weapon, -ammo);
                        
HouseInfo[house][hAmmo][1] += ammo;
                        if(
PlayerInfo[playerid][pSex] == 1) { format(string, sizeof(string), "* %s takes out his %s and places it at his safe.", GetPlayerNameEx(playerid),gunname); }
                        else { 
format(string, sizeof(string), "* %s takes out her %s and places it at her safe.", GetPlayerNameEx(playerid),gunname); }
                        
ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    }
                    else
                    {
                        
SCM(playerid, COLOR_GREY,"* This slot is taken by another weapon!");
                        return 
1;
                    }
                    
OnPropUpdate(1, house);
                }
                else
                {
                    
SCM(playerid, COLOR_GREY,"* This slot is taken by another weapon!");
                    
SCM(playerid, COLOR_GREY,"* Either deposit more ammo of the same weapon or load it up!");
                    return 
1;
                }
            }
            else
            {
                
SCM(playerid, COLOR_GREY,"* You're not on your House!");
                return 
1;
            }
    }
    return 
1;
} 
PHP код:
YCMD:checksafe(playerid, params[], help)
{
    if(
help) return SCM(playerid, COLOR_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],gunname, sizeof(gunname));
        
GetWeaponName(HouseInfo[house][hWeapon][1],gunname1, sizeof(gunname1));
        
GetWeaponName(HouseInfo[house][hWeapon][2],gunname2, sizeof(gunname2));
        
GetWeaponName(HouseInfo[house][hWeapon][3],gunname3, sizeof(gunname3));
        
GetWeaponName(HouseInfo[house][hWeapon][4],gunname4, sizeof(gunname4));
        
GetWeaponName(HouseInfo[house][hWeapon][5],gunname5, sizeof(gunname5));
        if(
IsPlayerInRangeOfPoint(playerid, 15, HouseInfo[house][hExitx],HouseInfo[house][hExity],HouseInfo[house][hExitz]))
        {
            
format(string, sizeof(string),"-HOUSE STORAGE- You have %d Drugs and %d Materials.",HouseInfo[house][hDrugs],HouseInfo[house][hMaterials]);
            
SCM(playerid, COLOR_GREY,string);
            
format(string, sizeof(string),"-HOUSE STORAGE- Weapon 0 - %s Ammo: %d.",gunname,HouseInfo[house][hAmmo][0]);
            
SCM(playerid, COLOR_GREY,string);
            
format(string, sizeof(string),"-HOUSE STORAGE- Weapon 1 - %s Ammo: %d.",gunname1,HouseInfo[house][hAmmo][1]);
            
SCM(playerid, COLOR_GREY,string);
            
format(string, sizeof(string),"-HOUSE STORAGE- Weapon 2 - %s Ammo: %d.",gunname2,HouseInfo[house][hAmmo][2]);
            
SCM(playerid, COLOR_GREY,string);
            
format(string, sizeof(string),"-HOUSE STORAGE- Weapon 3 - %s Ammo: %d.",gunname3,HouseInfo[house][hAmmo][3]);
            
SCM(playerid, COLOR_GREY,string);
            
format(string, sizeof(string),"-HOUSE STORAGE- Weapon 5 - %s Ammo: %d.",gunname4,HouseInfo[house][hAmmo][4]);
            
SCM(playerid, COLOR_GREY,string);
            
format(string, sizeof(string),"-HOUSE STORAGE- Weapon 5 - %s Ammo: %d.",gunname5,HouseInfo[house][hAmmo][5]);
            
SCM(playerid, COLOR_GREY,string);
        }
        else
        {
            
SCM(playerid, COLOR_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(rows, cols, dbhandle);
        if(!
rows) return printf("[SCRIPT]: The SQL Houses loading query returned 0 results");
        for(
currentRow = 0; currentRow != rows; ++currentRow, fx = 0, loadedWeapons = 0) {
            
tmp = cache_get_row_int(currentRow, fx++, 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(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hEntrancey]  = cache_get_row_float(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hEntrancez]  = cache_get_row_float(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hExitx]         = cache_get_row_float(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hExity]         = cache_get_row_float(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hExitz]         = cache_get_row_float(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hHealthx]    = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hHealthy]     = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hHealthz]     = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hArmourx]     = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hArmoury]     = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hArmourz]     = cache_get_row_int(currentRow, fx++, dbhandle);
            
cache_get_row(currentRow, fx++, HouseInfo[idx][hOwner], dbhandle, 255);
            
cache_get_row(currentRow, fx++, HouseInfo[idx][hDiscription], dbhandle, 255);
            
HouseInfo[idx][hValue]         = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hHel]         = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hArm]         = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hInt]         = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hLock]         = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hOwned]         = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hRooms]         = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hRentabil]     = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hRent]         = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hTakings]     = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hLevel]         = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hWorld]         = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hSetted]     = 1;
            
HouseInfo[idx][hDrugs]         = cache_get_row_int(currentRow, fx++, dbhandle);
            
HouseInfo[idx][hMaterials]  = cache_get_row_int(currentRow, fx++, dbhandle);
            
cache_get_row(currentRow, fx++, HouseInfo[idx][hMessage], dbhandle, 255);
            
OnHousePickupUpdate(idx);
            
OnPropTextdrawUpdate(1, idx);
            
Iter_Add(HouseInfo, idx);
            ++
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(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hEntrancey]  = cache_get_row_float(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hEntrancez]  = cache_get_row_float(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hExitx]         = cache_get_row_float(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hExity]         = cache_get_row_float(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hExitz]         = cache_get_row_float(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hHealthx]    = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hHealthy]     = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hHealthz]     = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hArmourx]     = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hArmoury]     = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hArmourz]     = cache_get_row_int(currentRow, fx++, dbhandle); 
            
cache_get_row(currentRow, fx++, HouseInfo[idx][hOwner], dbhandle, 255); 
            
cache_get_row(currentRow, fx++, HouseInfo[idx][hDiscription], dbhandle, 255); 
            
HouseInfo[idx][hValue]         = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hHel]         = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hArm]         = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hInt]         = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hLock]         = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hOwned]         = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hRooms]         = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hRentabil]     = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hRent]         = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hTakings]     = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hLevel]         = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hWorld]         = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hSetted]     = 1; 
            
HouseInfo[idx][hDrugs]         = cache_get_row_int(currentRow, fx++, dbhandle); 
            
HouseInfo[idx][hMaterials]  = cache_get_row_int(currentRow, fx++, dbhandle); 
            
cache_get_row(currentRow, fx++, HouseInfo[idx][hMessage], dbhandle, 255); 
But if you put the
PHP код:
Query 
PHP код:
 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 
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: 1 Guest(s)