Saving weapons via mysql using TEXT? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Saving weapons via mysql using TEXT? (
/showthread.php?tid=477832)
Saving weapons via mysql using TEXT? -
arko123 - 26.11.2013
Is it possible to save weapons in a text variable rather than making a bunch of slots and then putting them INT variable in a mysql database?
Re: Saving weapons via mysql using TEXT? -
Jefff - 26.11.2013
Yes it is
pawn Код:
new
pWeapon[13],
pAmmo[13]
;
for(new slot = 0; slot != sizeof(pWeapon); slot++)
GetPlayerWeaponData(playerid,slot,pWeapon[slot],pAmmo[slot]);
new str[128];
for(new slot = 0; slot != sizeof(pWeapon); slot++)
format(str,sizeof(str),"%s%d|",str,pWeapon[slot]);
str[strlen(str) - 1] = 0;
"UPDATE accounts SET Weapons = '%s' WHERE sql_id = %d",str,pData[playerid][userID]
and do the same with ammo
AW: Saving weapons via mysql using TEXT? -
BigETI - 26.11.2013
Yes, but it's not recommended. Also I would use VARCHAR instead of TEXT (see MySQL datatypes).
However you can compress weapon and ammo data up to 14 INT columns, instead of creating 26 INT columns (13 slots Ч (1 weapon + 1 Ч ammo data))
Re: Saving weapons via mysql using TEXT? -
arko123 - 27.11.2013
Then how I load them after saving
Re: Saving weapons via mysql using TEXT? -
arko123 - 29.11.2013
bump
Re: Saving weapons via mysql using TEXT? -
Vince - 29.11.2013
Multiple variables in a single field is a no-go. This defeats the purpose of SQL. I recommend setting up a table dedicated to weapons solely, like so:
Re: AW: Saving weapons via mysql using TEXT? -
Konstantinos - 29.11.2013
Quote:
Originally Posted by BigETI
Yes, but it's not recommended.
|
Quote:
Originally Posted by Vince
Multiple variables in a single field is a no-go.
|
In some cases, it's very useful. I'd prefer to save 100 variables (let's say for a minigame) false/true in a single string and update only 1 field than creating 100 fields for that. It can also be splitted up easily with sscanf for the loading part!