Saving weapons - House system -
Sus-Pets - 10.08.2016
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 x = 1; x < 13; x++)
{
new weapna, weapam, str[18];
GetPlayerWeaponData(playerid, x, weapna, weapam);
if(weapam == 0)
{
Weapon[playerid][x] = 0;
WeaponAmmo[playerid][x] = 0;
}
format(str, sizeof(str), "%d,%d,", Weapon[playerid][x], WeaponAmmo[playerid][x]);
strcat(weap, str);
}
}
else
{
SendClientMessage(playerid,-1,"You're not at your home");
}
mysql_format(SQL_CONNECTION, query, sizeof(query), "UPDATE Houses SET Weapons = '%e' WHERE SQLID = %d LIMIT 1", weap, Character[playerid][hEntered]);
printf("Weapon: %d - ID: %d",weap,Character[playerid][hEntered]);
mysql_tquery(SQL_CONNECTION, query);
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_CONNECTION, 104);
new pos = 0,str2[600];
strcat(str2, "Add a gun\n");
for (new x = 1; x < 13; ++x)
{
new temp[4];
strmid(temp, Houses[Character[playerid][hEntered]][Weapons], pos, strfind(Houses[Character[playerid][hEntered]][Weapons], ",", true, pos));
Weapon[playerid][x] = strval(temp);
pos += strlen(temp) + 1;
strmid(temp, Houses[Character[playerid][hEntered]][Weapons], pos, strfind(Houses[Character[playerid][hEntered]][Weapons], ",", true, pos));
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(playerid, HOUSEGUNS, DIALOG_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
Re: Saving weapons - House system -
Vince - 10.08.2016
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.
Re: Saving weapons - House system -
Sus-Pets - 10.08.2016
Ok thank you that looks way much easier !