Saving weapons - House system
#1

Hi

So I'd like to improve my house system by adding a safe for guns. I firstly thought that doing "Gun1", "Gun2" etc was the only solution but then I found that someone did a better thing which only take 1 line per characters

I'd like to adapt this script for my house system but I find it hard to understand, I usually don't use the strmid & strcat so I may need help

PHP код:
CMD:hdeposit(playerid,params[])
{
    new 
weap[104],query[200];
    new 
strr[128];
    
format(strr,sizeof(strr),"House ID: %d",Character[playerid][hEntered]);
    
SendClientMessage(playerid,-1,strr); // debug 
    
if(Houses[Character[playerid][hEntered]][Owner] == Character[playerid][ID])
    {
        for(new 
113x++)
        {
            new 
weapnaweapamstr[18];
            
GetPlayerWeaponData(playeridxweapnaweapam);
            if(
weapam == 0)
            {
                
Weapon[playerid][x] = 0;
                
WeaponAmmo[playerid][x] = 0;
            }
            
format(strsizeof(str), "%d,%d,"Weapon[playerid][x], WeaponAmmo[playerid][x]);
            
strcat(weapstr);
        }
   }
       else
    {
        
SendClientMessage(playerid,-1,"You're not at your home");
    }
    
mysql_format(SQL_CONNECTIONquerysizeof(query), "UPDATE Houses SET Weapons = '%e' WHERE SQLID = %d LIMIT 1"weapCharacter[playerid][hEntered]);
    
printf("Weapon: %d - ID: %d",weap,Character[playerid][hEntered]);
    
mysql_tquery(SQL_CONNECTIONquery);
    return 
1;

This command seems to work, this is what I've got in the database with a M4 in my hands:


However, tell me if there is a mistake, I'm not sure

Now it's for me the hardest part: loading guns and show them in a Dialog


PHP код:
CMD:hsafe(playerid,params[])
{
    
cache_get_field_content(0"Weapons"Houses[Character[playerid][hEntered]][Weapons], SQL_CONNECTION104);
    new 
pos 0,str2[600];
    
    
strcat(str2"Add a gun\n");
    for (new 
113; ++x)
    {
        new 
temp[4];
        
strmid(tempHouses[Character[playerid][hEntered]][Weapons], posstrfind(Houses[Character[playerid][hEntered]][Weapons], ","truepos));
        
Weapon[playerid][x] = strval(temp);
        
pos += strlen(temp) + 1;
        
strmid(tempHouses[Character[playerid][hEntered]][Weapons], posstrfind(Houses[Character[playerid][hEntered]][Weapons], ","truepos));
        
WeaponAmmo[playerid][x] = strval(temp);
        
pos += strlen(temp) + 1;
        
        
format(str2,sizeof(str2),"Gun: %d \t Ammo: %d\n",Weapon[playerid][x],WeaponAmmo[playerid][x]);
     }
    
Dialog_Show(playeridHOUSEGUNSDIALOG_STYLE_TABLIST,"House - Safe",str2,"Continue","Back");
    return 
1;

And this is what I get:




I don't understand fully the code to light the problem here (like what is doing "WeaponAmmo[playerid][x] = strval(temp);" ?

May someone help me ?

Thanks
Reply
#2

Never store more than one piece of information per field. That is a fundamental rule for proper database design. Check the tutorial about saving weapons in my signature. It can be easily adapted if you change userid to houseid.
Reply
#3

Ok thank you that looks way much easier !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)