09.09.2017, 21:40
Hi People! Please write mysql r41-2 save,, noo dini... thank you bro
this is include!!
INVENTORY SCRIPT - SAVE AND LOAD!!!!
this is include!!
INVENTORY SCRIPT - SAVE AND LOAD!!!!
Код:
stock SaveItems(playerid) { new m[36],itemfile[64]; format(itemfile,sizeof(itemfile),"Inv/%s.ini",GetNamei(playerid)); for(new i; i<MAX_ITEMS; i++) { format(m,36,"Item%d",i); dini_Set(itemfile,m,srItemName[playerid][i]); format(m,36,"Itemcat%d",i); dini_Set(itemfile,m,srItemCat[playerid][i]); format(m,36,"Itemamount%d",i); dini_IntSet(itemfile,m,srItemAmount[playerid][i]); } return 1; } stock LoadItems(playerid) { new m[128],itemfile[128]; format(itemfile,sizeof(itemfile),"Inv/%s.ini",GetNamei(playerid)); if(dini_Exists(itemfile)) { ResetPlayerItems(playerid); for(new i; i<MAX_ITEMS; i++) { format(m,128,"Item%d",i); format(srItemName[playerid][i],24,"%s",dini_Get(itemfile,m)); format(m,128,"Itemcat%d",i); format(srItemCat[playerid][i],36,"%s",dini_Get(itemfile,m)); format(m,128,"Itemamount%d",i); srItemAmount[playerid][i] = dini_Int(itemfile,m); } } else { dini_Create(itemfile); ResetPlayerItems(playerid); SaveItems(playerid); } return 1; }
Код:
/* Inventory System */ #include <dini> #if defined _INC_inventory #endinput #endif #define _INC_inventory #define SFMC(%0,%1,%2) do{new _str[128]; format(_str,128,%2); SendClientMessage(%0,%1,_str);}while(INVFALSE) #define MAX_ITEMS 100 #define MAX_DROP_ITEMS 200 #define ITEM_DIALOG 5842 #define ITEM_DIALOG_EX ITEM_DIALOG+10 #define ITEM_DIALOG_CAT ITEM_DIALOG_EX+10 #define ITEM_DIALOG_ULTRA ITEM_DIALOG_CAT+10 /* native AddItem(playerid,item[],amount,cat[]); native RemoveItem(playerid,item[],amount,cat[]); native ShowItems(playerid); native ShowItemsEx(playerid,id); native ShowRealItems(playerid,cat[]); native GetItemSlot(playerid,item[],cat[]); native SaveItems(playerid); native LoadItems(playerid); native OnItemResponse(playerid,response,listitem,inputtext[]); native GetItemAmount(playerid,item[],cat[]); native IsPlayerOwnItem(playerid,item[]); native ResetPlayerItems(playerid); native GetItemName(playerid,itemslot); native GetItemCategory(playerid,itemslot); */ new INVFALSE = false; new srItemName[MAX_PLAYERS][MAX_ITEMS][36]; new srItemCat[MAX_PLAYERS][MAX_ITEMS][36]; new srItemAmount[MAX_PLAYERS][MAX_ITEMS]; new ItemID[MAX_PLAYERS]; new listItem[MAX_ITEMS]; new ItemPlayer[MAX_PLAYERS] = INVALID_PLAYER_ID; new ItemPlayerID[MAX_PLAYERS]; enum ditInfo { Text3D:ittext, Float:posX, Float:posY, Float:posZ, VW, INV, itname[36], itcat[36], itamount, itobject }; new DropItemInfo[MAX_ITEMS][ditInfo]; forward OnPlayerUseItem(playerid,item[]); forward OnPlayerUseItemEx(playerid,fromplayerid,item[]); stock RemoveHexColorFromString(string[]) { new pos[2]; pos[0] = strfind(string,"{",true,0); pos[1] = strfind(string,"}",true,0); for(new i;i < strlen(string); i++) { if(pos[0]+7 == pos[1]) { strdel(string, pos[0], pos[1]+1); pos[0] = strfind(string,"{",true,0); pos[1] = strfind(string,"}",true,0); } } return 1; } stock GetNamei(playerid) { new n[MAX_PLAYER_NAME]; GetPlayerName(playerid,n,sizeof(n)); return n; } stock CompareEx(comp[], with[]) //By: Fl0rian { 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 DropItem(playerid,id,amount) { for(new i; i<MAX_DROP_ITEMS; i++) { if(!IsValidObject(DropItemInfo[i][itobject])) { new Float:Xp,Float:Yp,Float:Zp; GetPlayerPos(playerid, Xp, Yp, Zp); DropItemInfo[i][itobject] = CreateObject(1210, Xp, Yp, Zp-1, 0.0, 0.0, 0.0); DropItemInfo[i][ittext] = Create3DTextLabel(srItemName[playerid][id], -1, Xp,Yp,Zp, 10.0,GetPlayerVirtualWorld(playerid),1); DropItemInfo[i][posX] = Xp; DropItemInfo[i][posY] = Yp; DropItemInfo[i][posZ] = Zp; DropItemInfo[i][VW] = GetPlayerVirtualWorld(playerid); DropItemInfo[i][INV] = GetPlayerInterior(playerid); format(DropItemInfo[i][itname],36,srItemName[playerid][id]); format(DropItemInfo[i][itcat],36,srItemCat[playerid][id]); DropItemInfo[i][itamount] = amount; RemoveItem(playerid,srItemName[playerid][id],amount,srItemCat[playerid][id]); return 1; } } return 1; } stock PickUpItem(playerid) { for(new i; i<MAX_DROP_ITEMS; i++) { if(IsPlayerInRangeOfPoint(playerid,3.0,DropItemInfo[i][posX],DropItemInfo[i][posY],DropItemInfo[i][posZ]) && GetPlayerVirtualWorld(playerid) == DropItemInfo[i][VW] && GetPlayerInterior(playerid) == DropItemInfo[i][INV]) { new sucess = AddItem(playerid,DropItemInfo[i][itname],DropItemInfo[i][itamount],DropItemInfo[i][itcat]); if(sucess) { Delete3DTextLabel(DropItemInfo[i][ittext]); DestroyObject(DropItemInfo[i][itobject]); return 1; } } } return 1; } stock AddItem(playerid,item[],amount,category[] = "Egyйb") { if(amount <= 0) return 0; if(strlen(item) > 128) return 0; new bool: count[2] = false; for(new i; i<MAX_ITEMS; i++) { if(CompareEx(srItemName[playerid][i],item) && CompareEx(srItemCat[playerid][i],category)) { count[0] = true; srItemAmount[playerid][i] += amount; return 1; } } if(count[0] == false) { for(new i; i<MAX_ITEMS; i++) { if(CompareEx(srItemName[playerid][i],"Empty")) { count[1] = true; format(srItemName[playerid][i],36,"%s",item); format(srItemCat[playerid][i],36,"%s",category); srItemAmount[playerid][i] = amount; return 1; } } } if(count[1] != true) return SendClientMessage(playerid,-1,"none"),0; return 1; } stock RemoveItemEx(playerid,i) { format(srItemName[playerid][i],36,"%s","Ьres"); format(srItemCat[playerid][i],36,"%s","Ьres"); srItemAmount[playerid][i] = 0; return 1; } stock RemoveItem(playerid,item[],amount,category[]) { for(new i; i<MAX_ITEMS; i++) { if(CompareEx(srItemName[playerid][i],item) && CompareEx(srItemCat[playerid][i],category)) { if(srItemAmount[playerid][i] > amount) { srItemAmount[playerid][i] -= amount; } else if(srItemAmount[playerid][i] == amount || srItemAmount[playerid][i] < amount) { format(srItemName[playerid][i],36,"%s","Empty"); format(srItemCat[playerid][i],36,"%s","Empty"); srItemAmount[playerid][i] = 0; } return 1; } } return 1; } stock ShowItems(playerid) { new msg[128],dialogstr[3000],bool:c; for(new i; i<MAX_ITEMS; i++) { if(!CompareEx(srItemCat[playerid][i],"Ьres")) { c = true; format(msg,128,"\n%s",srItemCat[playerid][i]); if(strfind(dialogstr, msg, true) == -1) { strcat(dialogstr,msg); } } } if(c != false) { ShowPlayerDialog(playerid,ITEM_DIALOG_CAT,DIALOG_STYLE_LIST,"Inventory",dialogstr,"Vбlaszt","Mйgsem"); } else SendClientMessage( playerid, -1, "Itt nincs semmi-" ); return 1; } stock ShowRealItems(playerid,cat[]) { new msg[128],dialogstr[3000],bool:c,count=-1; for(new i; i<MAX_ITEMS; i++) { if(!CompareEx(srItemName[playerid][i],"Ьres") && CompareEx(srItemCat[playerid][i],cat)) { c = true; count++; format(msg,128,"\n[%d] %s",srItemAmount[playerid][i],srItemName[playerid][i]); strcat(dialogstr,msg); listItem[count] = i; } } if(c != false) ShowPlayerDialog(playerid,ITEM_DIALOG,DIALOG_STYLE_LIST,"Inventory",dialogstr,"Vбlaszt","Mйgsem"); else SendClientMessage( playerid, -1, "Itt nincs semmi." ); return 1; } stock ShowItemsEx(playerid,srid,bool:use = false) { new msg[128],dialogstr[3000],bool:c; for(new i; i<MAX_ITEMS; i++) { if(!CompareEx(srItemName[playerid][i],"Ьres")) { c = true; format(msg,128,"\n[%d] %s",srItemAmount[playerid][i],srItemName[playerid][i]); strcat(dialogstr,msg); } } if(use == false) { if(c != false) ShowPlayerDialog(srid,ITEM_DIALOG_EX,DIALOG_STYLE_LIST,"Inventory",dialogstr,"","Okй"); else SendClientMessage( srid, -1, "Nincs semmi a tбskбjбban." ); } else { ItemPlayer[srid] = playerid; if(c != false) ShowPlayerDialog(srid,ITEM_DIALOG_EX+1,DIALOG_STYLE_LIST,"Inventory",dialogstr,"","Okй"); else SendClientMessage( srid, -1, "Nincs semmi a tбskбjбban." ); } return 1; } stock GetItemSlot(playerid,item[],cat[]) { for(new i; i<MAX_ITEMS; i++) { if(CompareEx(srItemName[playerid][i],item) && CompareEx(srItemCat[playerid][i],cat)) return i; } return -1; } stock IsPlayerOwnItem(playerid,item[]) { for(new i; i<MAX_ITEMS; i++) { if(CompareEx(srItemName[playerid][i],item)) return 1; } return 0; } stock GetItemAmount(playerid,item[],cat[]) { for(new i; i<MAX_ITEMS; i++) { if(CompareEx(srItemName[playerid][i],item) && CompareEx(srItemCat[playerid][i],cat)) return srItemAmount[playerid][i]; } return -1; } stock GetItemName(playerid,itemslot) return srItemName[playerid][itemslot]; stock GetItemCategory(playerid,itemslot) return srItemCat[playerid][itemslot]; stock ResetPlayerItems(playerid) { for(new i; i<MAX_ITEMS; i++) { format(srItemName[playerid][i],36,"%s","Ьres"); format(srItemCat[playerid][i],36,"%s","Ьres"); srItemAmount[playerid][i] = 0; } return 1; } stock OnItemResponse(playerid, dialogid, response,listitem, inputtext[]) { if(dialogid == ITEM_DIALOG_CAT) { if(!response) return 1; ShowRealItems(playerid,inputtext); return 1; } if(dialogid == ITEM_DIALOG) { if(!response) return 1; ShowPlayerDialog(playerid,ITEM_DIALOG_ULTRA+1,DIALOG_STYLE_LIST,"Mi legyen vele?","Hasznбlat\nEldobбs\nБtadбs","Okй","Mйgsem"); ItemID[playerid] = listItem[listitem]; } if(dialogid == ITEM_DIALOG_EX) { if(!response) return 1; if(listitem != 0) return SendClientMessage(playerid,-1,"Mбsok tбrgyбt nem hasznбlhatod!"); } if(dialogid == ITEM_DIALOG_EX+1) { if(!response) return 1,ItemPlayer[playerid] = INVALID_PLAYER_ID; if(listitem != 0) { new str[128]; RemoveHexColorFromString(inputtext); format(str,128,inputtext[strfind(inputtext,"]")+1]); CallLocalFunction( "OnPlayerUseItemEx", "iis", playerid,ItemPlayer[playerid], str ); ItemPlayer[playerid] = INVALID_PLAYER_ID; } } if(dialogid == ITEM_DIALOG_ULTRA) { if(response) ShowItems(playerid); else ShowItems(playerid); return 1; } if(dialogid == ITEM_DIALOG_ULTRA+1) { if(!response) return 1; //ShowPlayerDialog(playerid,11,DIALOG_STYLE_LIST,"Mi legyen vele?","Hasznбlat\nEldobбs\nБthelyezйs","Okй","Mйgsem"); if(listitem == 0) { CallLocalFunction( "OnPlayerUseItem", "is", playerid, srItemName[playerid][ItemID[playerid]] ); ItemID[playerid] = -1; } if(listitem == 1) { ShowPlayerDialog(playerid,ITEM_DIALOG_ULTRA+3,DIALOG_STYLE_INPUT,"Eldobбs","Mennyit szeretnйl eldobni?","Okй","Mйgsem"); } if(listitem == 2) { ShowPlayerDialog(playerid,ITEM_DIALOG_ULTRA+4,DIALOG_STYLE_INPUT,"Бtadбs","Нrd be a felhasznбlу ID-jйt, akinek бt szeretnйd adni:","Okй","Mйgsem"); } } if(dialogid == ITEM_DIALOG_ULTRA+3) { if(!response) return 1; if(!strval(inputtext)) return SendClientMessage(playerid,-1,"Csak szбmokat adj meg!"),ShowPlayerDialog(playerid,ITEM_DIALOG_ULTRA+3,DIALOG_STYLE_INPUT,"Eldobбs","Mennyit szeretnйl eldobni?","Okй","Mйgsem"); if(strval(inputtext) > srItemAmount[playerid][ItemID[playerid]]) return SendClientMessage(playerid,-1,"Nincs ennyid ebből a tбrgybуl!"),ShowPlayerDialog(playerid,ITEM_DIALOG_ULTRA+3,DIALOG_STYLE_INPUT,"Eldobбs","Mennyit szeretnйl eldobni?","Okй","Mйgsem"); DropItem(playerid,ItemID[playerid],strval(inputtext)); ItemID[playerid] = -1; return 1; } if(dialogid == ITEM_DIALOG_ULTRA+4) { if(!response) return 1; if(!strval(inputtext) && !CompareEx(inputtext,"0")) return SendClientMessage(playerid,-1,"Csak szбmokat adj meg!"),ShowPlayerDialog(playerid,ITEM_DIALOG_ULTRA+4,DIALOG_STYLE_INPUT,"Бtadбs","Нrd be a felhasznбlу ID-jйt, akinek бt szeretnйd adni:","Okй","Mйgsem"); if(!IsPlayerConnected(strval(inputtext))) return SendClientMessage(playerid,-1,"Nincs ilyen jбtйkos!"),ShowPlayerDialog(playerid,ITEM_DIALOG_ULTRA+4,DIALOG_STYLE_INPUT,"Бtadбs","Нrd be a felhasznбlу ID-jйt, akinek бt szeretnйd adni:","Okй","Mйgsem"); if(!srPTP(playerid,strval(inputtext))) return SendClientMessage(playerid,-1,"Nem vagy a jбtйkos kцzelйben."); if(strval(inputtext) == playerid) return SendClientMessage(playerid,-1,"Magadnak nem adhatod бt!"); SFMC(strval(inputtext),-1,"%s бt szeretnй adni ezt a tбrgyat: %s. Elfogadod?",GetNamei(playerid),srItemName[playerid][ItemID[playerid]]); ShowPlayerDialog(strval(inputtext),ITEM_DIALOG_ULTRA+5,DIALOG_STYLE_LIST,"Бtadбs","Elfogadom.\nNem fogadom el.","Okй","Mйgsem"); ItemPlayerID[strval(inputtext)] = playerid; return 1; } if(dialogid == ITEM_DIALOG_ULTRA+5) { if(!response) return 1; if(listitem == 0) { new id = ItemPlayerID[playerid]; new i = ItemID[id]; new sucess = AddItem(playerid,srItemName[id][i],srItemAmount[id][i],srItemCat[id][i]); if(sucess) { SFMC(id,-1,"%s elfogadta a tбrgyat.",GetNamei(playerid)); SendClientMessage(playerid,-1,"Sikeresen elfogadtad a tбrgyat, elhelyezted a zsebedben."); RemoveItem(playerid,srItemName[id][i],1,srItemCat[id][i]); ItemID[id] = -1; ItemPlayerID[playerid] = -1; return 1; } else { SendClientMessage(playerid,-1,"Nincs elйg hely a zsebedben!"); return 1; } } if(listitem == 2) { new id = ItemPlayerID[playerid]; SFMC(id,-1,"%s nem fogadta el a tбrgyat.",GetNamei(playerid)); SendClientMessage(playerid,-1,"Elutasнtottad a tбrgyat."); ItemID[id] = -1; ItemPlayerID[playerid] = -1; return 1; } return 1; } return 1; } stock SaveItems(playerid) { new m[36],itemfile[64]; format(itemfile,sizeof(itemfile),"Inv/%s.ini",GetNamei(playerid)); for(new i; i<MAX_ITEMS; i++) { format(m,36,"Item%d",i); dini_Set(itemfile,m,srItemName[playerid][i]); format(m,36,"Itemcat%d",i); dini_Set(itemfile,m,srItemCat[playerid][i]); format(m,36,"Itemamount%d",i); dini_IntSet(itemfile,m,srItemAmount[playerid][i]); } return 1; } stock LoadItems(playerid) { new m[128],itemfile[128]; format(itemfile,sizeof(itemfile),"Inv/%s.ini",GetNamei(playerid)); if(dini_Exists(itemfile)) { ResetPlayerItems(playerid); for(new i; i<MAX_ITEMS; i++) { format(m,128,"Item%d",i); format(srItemName[playerid][i],24,"%s",dini_Get(itemfile,m)); format(m,128,"Itemcat%d",i); format(srItemCat[playerid][i],36,"%s",dini_Get(itemfile,m)); format(m,128,"Itemamount%d",i); srItemAmount[playerid][i] = dini_Int(itemfile,m); } } else { dini_Create(itemfile); ResetPlayerItems(playerid); SaveItems(playerid); } return 1; } stock srPTP(playerid,id,Float:radi = 2.0) { new Float:pos[3]; GetPlayerPos(id,pos[0],pos[1],pos[2]); if(IsPlayerInRangeOfPoint(playerid,radi,pos[0],pos[1],pos[2])) return 1; else return 0; }