Saving weapons via mysql using TEXT?
#1

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?
Reply
#2

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
Reply
#3

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))
Reply
#4

Then how I load them after saving
Reply
#5

bump
Reply
#6

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:

Reply
#7

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)