Hi People! How to write my inventory script with MYSQL R41-2!!? Thank You and Respect!!!
Code:
Code:
Code:
#define ITEMS 500
enum items
{
iID,
tulaj[24],
nev[24],
menny
//object
}
new ItemInfo[ITEMS][items];
new itemek;//Betöltött itemek számát tárolja (Loop-ok hoz)
new CurrentItem[MAX_PLAYERS];
stock ShowItems(p)
{
new str[512] = "{284bd6}Név\t{284bd6}Mennyiség\n",str2[56],talalat;
for(new i = 0; i < itemek; i++)
{
if(Compare(ItemInfo[i][tulaj],GetName(p)))
{
format(str2,sizeof(str2),"%s\t{ffffff}(({284bd6}%i{ffffff}))\n",ItemInfo[i][nev],ItemInfo[i][menny]);
strcat(str,str2);
talalat = 1;
}
}
if(talalat == 0) return SendClientMessage(p,1,"{ff0000}Nincs nálad semmi..");
ShowPlayerDialog(p,I_MAIN, DIALOG_STYLE_TABLIST_HEADERS,"{284bd6}Inventory",str, "Haznál", "Kilép");
return 1;
}
stock LoadItems()
{
mysql_tquery(sql, "SELECT * FROM items", "LoadItemz");
}
stock TakeItem(ki,mi[],meny){
mysql_format(sql, query, 256, "SELECT * FROM items WHERE IOwner='%s' AND IName='%s' LIMIT 1",GetName(ki),mi);
mysql_tquery(sql, query, "ItemElvetel", "dsd", ki,mi,meny);
return 1;
}
stock SaveItems()
{
for(new i = 0; i < itemek; i++)
{
mysql_format(sql, query, 256, "UPDATE items SET iOwner='%s' ,iName='%s' ,iQuan='%d' WHERE ID='%d' LIMIT 1",ItemInfo[i][tulaj],ItemInfo[i][nev],ItemInfo[i][menny],ItemInfo[i][iID]);
mysql_tquery(sql, query);
}
printf("%d DB item lett elmentve",itemek);
return 1;
}
stock GiveItem(ki,mi[],meny)
{
print(mi);
mysql_format(sql, query, 256, "SELECT * FROM items WHERE IOwner='%s' AND IName='%s' LIMIT 1",GetName(ki),mi);
mysql_tquery(sql, query, "ItemAdas", "dsd", ki,mi,meny);
return 1;
}
forward OnPlayerUseItem(p,mi[],id);
public OnPlayerUseItem(p,mi[],id)
{
if(Compare(mi,"Sör")) // mi , tárgyneve
{
print("Sör");
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
if(playerid == clickedplayerid) return ShowItems(playerid);
return 1;
}
forward LoadItemz();
public LoadItemz()
{
for(new i = 0; i < cache_get_row_count(); i++)
{
ItemInfo[i][iID] = cache_get_row_int(i,0);
cache_get_row(i, 1,ItemInfo[i][tulaj],1,24);
cache_get_row(i, 2,ItemInfo[i][nev],1,24);
ItemInfo[i][menny] = cache_get_row_int(i,3);
itemek ++;
}
printf("[MGRP - Item System] %d DB item lett betötlve!",itemek);
return 1;
}
forward ItemAdas(ki,mi[],meny);
public ItemAdas(ki,mi[],meny) {
new rows = cache_get_row_count();
if(rows == 0){
mysql_format(sql, query, 256, "INSERT INTO items (IOwner,IName,IQuan) VALUES ('%s','%s','%d')",GetName(ki),mi,meny);
mysql_tquery(sql, query, "ItemGive", "dsd", ki,mi,meny);
}
else
{
new q=cache_get_row_int(0, 3);
mysql_format(sql, query, 384, "UPDATE items SET IQuan='%d' WHERE IOwner='%s' AND IName='%s'",q+meny,GetName(ki),mi);
mysql_tquery(sql, query);
for(new i = 0; i < itemek; i++)
{
if(Compare(ItemInfo[i][tulaj],GetName(ki)))
{
if(Compare(ItemInfo[i][nev],mi))
{
ItemInfo[i][menny] += meny;
break;
}
}
}
}
return 1;
}
forward ItemGive(p,mi[],q);
public ItemGive(p,mi[],q)
{
itemek++;
new id = cache_insert_id();
ItemInfo[itemek][iID] = id;
strins(ItemInfo[itemek][tulaj],GetName(p),0);
strins(ItemInfo[itemek][nev],mi,0);
ItemInfo[itemek][menny] = q;
return 1;
}
forward ItemElvetel(ki,mi[],meny);
public ItemElvetel(ki,mi[],meny)
{
new q=cache_get_row_int(0, 3);
new id = cache_get_row_int(0,0);
if(q > 1)
{
mysql_format(sql, query, 384, "UPDATE items SET IQuan='%d' WHERE IOwner='%s' AND IName='%s'",q-meny,GetName(ki),mi);
mysql_tquery(sql, query);
for(new i = 0; i < itemek; i++)
{
if(ItemInfo[i][iID] == id)
{
ItemInfo[i][menny] = q-meny;
break;
}
}
}
else
{
mysql_format(sql, query, 384, "DELETE FROM items WHERE IOwner='%s' AND IName='%s'",GetName(ki),mi);
mysql_tquery(sql, query);
for(new i = 0; i < itemek; i++)
{
if(ItemInfo[i][iID] == id)
{
strins(ItemInfo[itemek][tulaj],"Törölve",0);
strins(ItemInfo[itemek][nev],"Törölve",0);
ItemInfo[i][menny] = 0;
break;
}
}
}
return 1;
}
stock Compare( comp[], with[] ) {
new LenghtComp = strlen( comp );
new LenghtWith = strlen( with );
new Character;
if( LenghtComp != LenghtWith ) return false;
for( new i = 0; i < LenghtComp; i++ ) {
if( comp[i] == with[i] ) {
Character++;
}
}
if( LenghtComp == Character ) return true;
return false;
}
stock GetName(k){
new name[MAX_PLAYER_NAME];
GetPlayerName(k, name, sizeof(name));
return name;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == I_MAIN)
{
if(response)
{
for(new i = 0; i < itemek; i++)
{
if(Compare(ItemInfo[i][tulaj],GetName(playerid)))
{
if(Compare(ItemInfo[i][nev],inputtext))
{
CurrentItem[playerid] = i;
OnPlayerUseItem(playerid,inputtext,i);
break;
}
}
}
}
return 1;
}
return 1;
}