Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*$$$$$$$$ $$$$$$$ $$$$$$$$$ $$$$$ IIIIIIIIIIIII|IIIIIIIIIIIII|IIIIIIIII|
- $$$ $$$$$$$$ $$$ $$$$ $$$$ |IIII| |IIIIIIIIIIIII|IIII|
- $$$ $$$$ $$$ $$$ $$$$ $$$$ |IIII| IIII IIIIIIIII|
- $$$ $$$$ $$$ $$$ $$$$ $$$$ & |IIII| IIII IIIIIIIII|
- $$$ $$$$ $$$$$$ $$$ $$$ IIIIIIIIIIIIII| IIII IIII|
- $$$$$$$$$$$$$$ $$$$$$ $$$$$ entory |IIIIIIIIIIIII| IIII IIIIIIIII|M
- Iventory And Item SYSTEM
- Inventory by Joe Staff
- Item by Vinpure
- */
- #include <a_samp>
- #include <streamer>
- #include <zcmd>
- #include <sscanf2>
- //====================DEFINE=======================================================================================================================================================================
- #define MAX_DROP_ITEMS 1000
- #define MAX_ITEMS 20
- #define MAX_ITEM_STACK 99
- #define MAX_ITEM_NAME 24
- #define PRESSED(%0) \
- (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
- //==================DIALOG
- #define INV_DIALOG_ID 13337
- #define DIALOG_CITEM 13333
- #define DIALOG_DROPITEM 13332
- //ITEM MODEL
- #define IPizza 1582
- #define IWater 1950
- //===========================================================================================================================================================================================
- new DropObject[MAX_DROP_ITEMS];
- new Text3D:Label[MAX_DROP_ITEMS];
- //==============ITEM INFO============================================================================================================================================================
- enum ItemData
- {
- ItemModel,//ModelID das
- Float:ItemPosX,
- Float:ItemPosY,
- Float:ItemPosZ,
- Float:ItemRotX,
- Float:ItemRotY,
- Float:ItemRotZ,
- ItemVWorld,
- ItemInterior,
- };
- new ItemInfo[MAX_DROP_ITEMS][ItemData];
- //========Forward===================================================================================================================================================================================
- forward OnPlayerPickupItem(playerid);
- forward OnPlayerUseItem(playerid,ItemName[]);
- //============NEW====================================================================================================================================================================================
- new gItemList[(MAX_ITEMS+1)*(MAX_ITEM_NAME+3)];
- //===========================================================================================================================================================================================
- public OnFilterScriptInit()
- {
- print("---------Inventory And Item------------\n");
- print("*Inventory System By:Joe Staff---------\n");
- print("*Item System By:Vinpure----------------\n");
- print("---------------------------------------\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- LoadInventory(playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid,reason)
- {
- SaveInventory(playerid);
- return 1;
- }
- //==================CMD
- CMD:createitem(playerid,params[])
- {
- ShowPlayerDialog(playerid,DIALOG_CITEM,1,"Create Item","Item Name:pizza|waterbottle","Create","Close");
- return 1;
- }
- CMD:pickupitem(playerid,params[])
- {
- OnPlayerPickupItem(playerid);
- return 1;
- }
- CMD:dropitem(playerid,params[])
- {
- ShowPlayerDialog(playerid,DIALOG_DROPITEM,1,"Use Item","Write Name Item you has","Use","Cancel");
- return 1;
- }
- CMD:useitem(playerid,params[])
- {
- UseItemInInventory(playerid);
- return 1;
- }
- //===========================================================================================================================================================================================
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- new Float:x,Float:y,Float:z;
- GetPlayerPos(playerid,x,y,z);
- InventoryOnDialogResponse(playerid, dialogid, response, inputtext);
- if(dialogid == DIALOG_CITEM && response == 1)
- {
- if(strcmp(inputtext[0],"pizza",true) == 0)
- {
- CreateItem(IPizza,x,y,z-1,0,0,0,0,0);
- }
- else if(strcmp(inputtext[0],"WATERBOTTLE",true) == 0)
- {
- CreateItem(IWater,x,y,z-1,0,0,0,0,0);
- }
- }
- //=============USE ITEM=|
- if(dialogid == DIALOG_DROPITEM && response == 1)
- {
- if(strcmp(inputtext[0],"pizza",true) == 0)
- {
- if(!PlayerHasItem(playerid,"Pizza")) return SendClientMessage(playerid,-1,"You no have Item Pizza");
- RemoveItem(playerid,"Pizza",1);
- DropItem(IPizza,x,y,z,0,0);
- }
- else if(strcmp(inputtext[0],"waterbottle",true) == 0)
- {
- if(!PlayerHasItem(playerid,"WaterBottle")) return SendClientMessage(playerid,-1,"You No have Item Water bottle");
- RemoveItem(playerid,"Waterbottle",1);
- DropItem(IWater,x,y,z,0,0);
- }
- }
- return 1;
- }
- public OnPlayerPickupItem(playerid)
- {
- for(new i = 0; i < sizeof(ItemInfo); i++)
- {
- if (IsPlayerInRangeOfPoint(playerid, 2.0,ItemInfo[i][ItemPosX],ItemInfo[i][ItemPosY],ItemInfo[i][ItemPosZ]))
- {
- if(GetPlayerVirtualWorld(playerid) == ItemInfo[i][ItemVWorld] && GetPlayerInterior(playerid) == ItemInfo[i][ItemVWorld])
- {
- ItemInfo[i][ItemPosX] = 0.0;
- ItemInfo[i][ItemPosY] = 0.0;
- ItemInfo[i][ItemPosZ] = 0.0;
- ItemInfo[i][ItemRotX] = 0.0;
- ItemInfo[i][ItemRotY] = 0.0;
- ItemInfo[i][ItemRotZ] = 0.0;
- PlayAnim(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0, 1);
- if(ItemInfo[i][ItemModel] == IPizza)
- {
- Delete3DTextLabel(Label[i]);
- DestroyDynamicObject(DropObject[i]);
- AddItem(playerid,"Pizza",1);
- }
- if(ItemInfo[i][ItemModel] == IWater)
- {
- Delete3DTextLabel(Label[i]);
- DestroyDynamicObject(DropObject[i]);
- AddItem(playerid,"WaterBottle",1);
- }
- return 1;
- }
- }
- }
- return 1;
- }
- public OnPlayerUseItem(playerid,ItemName[])
- {
- if(!strcmp(ItemName,"Pizza",true))
- {
- RemoveItem(playerid,"Pizza",1);
- PlayAnim(playerid, "FOOD", "EAT_Burger", 4.0, 0, 0, 0, 0, 0, 1);
- return 1;
- }
- if(!strcmp(ItemName,"WaterBottle",true))
- {
- RemoveItem(playerid,"WaterBottle",1);
- PlayAnim(playerid, "BAR", "dnk_stndF_loop",4.0, 0, 0, 0, 0, 0, 1);
- return 1;
- }
- return 1;
- }
- //===========================================================================================================================================================================================
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- return 1;
- }
- //==========================================STOCK=======================================================================================================================================================================================================================================================================================
- //anim
- PlayAnim(playerid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time, forcesync)
- {
- ApplyAnimation(playerid, animlib, animname, fDelta, loop, lockx, locky, freeze, time, forcesync);
- }
- //===================ITEM===================
- stock CreateItem(ItemM, Float:X, Float:Y, Float:Z,Float:RX,Float:RY,Float:RZ, world,interior)
- {
- if(ItemM != 0)
- {
- for(new i = 0; i < sizeof(ItemInfo); i++)
- {
- if(ItemInfo[i][ItemPosX] == 0.0 && ItemInfo[i][ItemPosY] == 0.0 && ItemInfo[i][ItemPosZ] == 0.0)
- {
- ItemInfo[i][ItemModel] = ItemM;
- ItemInfo[i][ItemPosX] = X;
- ItemInfo[i][ItemPosY] = Y;
- ItemInfo[i][ItemPosZ] = Z;
- ItemInfo[i][ItemRotX] = RX;
- ItemInfo[i][ItemRotY] = RY;
- ItemInfo[i][ItemRotZ] = RZ;
- ItemInfo[i][ItemVWorld] = world;
- ItemInfo[i][ItemInterior] = interior;
- Label[i] = Create3DTextLabel("Item", 0x008080FF,X,Y,Z, 5.0,world, 0);
- DropObject[i] = CreateDynamicObject(ItemM, X, Y, Z,RX,RY,RZ, world);
- return 1;
- }
- }
- return 1;
- }
- return 1;
- }
- stock DropItem(ItemM, Float:X, Float:Y, Float:Z, world, interior)
- {
- if(ItemM != 0)
- {
- for(new i = 0; i < sizeof(ItemInfo); i++)
- {
- if(ItemInfo[i][ItemPosX] == 0.0 && ItemInfo[i][ItemPosY] == 0.0 && ItemInfo[i][ItemPosZ] == 0.0)
- {
- ItemInfo[i][ItemModel] = ItemM;
- ItemInfo[i][ItemPosX] = X;
- ItemInfo[i][ItemPosY] = Y;
- ItemInfo[i][ItemPosZ] = Z;
- ItemInfo[i][ItemVWorld] = world;
- ItemInfo[i][ItemInterior] = interior;
- Label[i] = Create3DTextLabel("Item", 0x008080FF,X,Y,Z, 5.0,world, 0);
- DropObject[i] = CreateDynamicObject(ItemM, X, Y, Z-1, 0.0, 0.0, 0.0, world);
- return 1;
- }
- }
- return 1;
- }
- return 1;
- }
- //===================INVENTORY===================
- stock _GetItemNamePVar(playerid,item)
- {
- new tmp[32];
- new tmp2[MAX_ITEM_NAME];
- format(tmp,32,"PITEMNAME%d",item);
- GetPVarString(playerid,tmp,tmp2,MAX_ITEM_NAME);
- return tmp2;
- }
- stock _SetItemNamePVar(playerid,item,ItemName[])
- {
- new tmp[MAX_ITEM_NAME];
- format(tmp,MAX_ITEM_NAME,"PITEMNAME%d",item);
- SetPVarString(playerid,tmp,ItemName);
- }
- stock _GetItemAmountPVar(playerid,item)
- {
- new tmp[16];
- format(tmp,16,"PITEMAMOUNT%d",item);
- return GetPVarInt(playerid,tmp);
- }
- stock _SetItemAmountPVar(playerid,item,Amount)
- {
- new tmp[16];
- format(tmp,16,"PITEMAMOUNT%d",item);
- SetPVarInt(playerid,tmp,Amount);
- }
- stock AddItem(playerid,ItemName[],Amount)
- {
- new slot=-1;
- for(new item;item<MAX_ITEMS;item++)
- {
- if(!_GetItemAmountPVar(playerid,item))
- {
- if(slot==-1)slot=item;
- continue;
- }
- if(!strcmp(_GetItemNamePVar(playerid,item),ItemName,true))
- {
- _SetItemAmountPVar(playerid,item,_GetItemAmountPVar(playerid,item)+Amount);
- if(_GetItemAmountPVar(playerid,item)<=0)_SetItemAmountPVar(playerid,item,0);
- if(_GetItemAmountPVar(playerid,item)>MAX_ITEM_STACK)
- {
- _SetItemAmountPVar(playerid,item,MAX_ITEM_STACK);
- return 2;
- }
- return 1;
- }
- }
- if(slot>-1)
- {
- _SetItemNamePVar(playerid,slot,ItemName);
- _SetItemAmountPVar(playerid,slot,Amount);
- if(_GetItemAmountPVar(playerid,slot)>MAX_ITEM_STACK)
- {
- _SetItemAmountPVar(playerid,slot,MAX_ITEM_STACK);
- return 2;
- }
- return 1;
- }
- return 0;
- }
- stock RemoveItem(playerid,ItemName[],Amount)
- {
- for(new item;item<MAX_ITEMS;item++)
- {
- if(!_GetItemAmountPVar(playerid,item))continue;
- if(!strcmp(_GetItemNamePVar(playerid,item),ItemName,true))
- {
- _SetItemAmountPVar(playerid,item,_GetItemAmountPVar(playerid,item)-Amount);
- if(_GetItemAmountPVar(playerid,item)<=0)_SetItemAmountPVar(playerid,item,0);
- if(_GetItemAmountPVar(playerid,item)>MAX_ITEM_STACK)
- {
- _SetItemAmountPVar(playerid,item,MAX_ITEM_STACK);
- return 2;
- }
- return 1;
- }
- }
- return 0;
- }
- stock PlayerHasItem(playerid,ItemName[])
- {
- for(new item;item<MAX_ITEMS;item++)
- {
- if(!_GetItemAmountPVar(playerid,item))continue;
- if(!strcmp(_GetItemNamePVar(playerid,item),ItemName,false))return _GetItemAmountPVar(playerid,item);
- }
- return 0;
- }
- stock GetPlayerItemInfo(playerid,&idx,ItemName[],len=sizeof(ItemName),&Amount)
- {
- if(idx>=MAX_ITEMS)return 0;
- format(ItemName,len,_GetItemNamePVar(playerid,idx));
- Amount=_GetItemAmountPVar(playerid,idx);
- idx++;
- return 1;
- }
- stock ResetPlayerInventory(playerid)
- {
- for(new item;item<MAX_ITEMS;item++)_SetItemAmountPVar(playerid,item,0);
- }
- stock UseItemInInventory(playerid)
- {
- gItemList="";
- for(new item;item<MAX_ITEMS;item++)
- {
- if(!strlen(_GetItemNamePVar(playerid,item))||!_GetItemAmountPVar(playerid,item))continue;
- format(gItemList,sizeof(gItemList),"%s\n%d\t\t%s",gItemList,_GetItemAmountPVar(playerid,item),_GetItemNamePVar(playerid,item));
- }
- ShowPlayerDialog(playerid,INV_DIALOG_ID,DIALOG_STYLE_LIST,"Inventory",gItemList,"Use","Close");
- SetPVarInt(playerid,"PUSINGDIALOG",1);
- }
- stock SaveInventory(playerid)
- {
- gItemList="";
- new filename[48];
- GetPlayerName(playerid,filename,24);
- format(filename,48,"Inv/%s.inv",filename);
- new File:file=fopen(filename,io_write);
- for(new item;item<MAX_ITEMS;item++)
- {
- if(!strlen(_GetItemNamePVar(playerid,item))||!_GetItemAmountPVar(playerid,item))continue;
- format(gItemList,sizeof(gItemList),"%s%s\n%d\n",gItemList,_GetItemNamePVar(playerid,item),_GetItemAmountPVar(playerid,item));
- }
- fwrite(file,gItemList);
- fclose(file);
- GetPlayerName(playerid,filename,24);
- printf("[INV] %s[%d]'s inventory saved.",filename,playerid);
- }
- stock LoadInventory(playerid)
- {
- new tstring[48];
- new tstring2[12];
- GetPlayerName(playerid,tstring,48);
- format(tstring,48,"Inv/%s.inv",tstring);
- if(!fexist(tstring))return 0;
- new File:file=fopen(tstring,io_read);
- fread(file,tstring);
- while(tstring[0])
- {
- format(tstring,strlen(tstring),"%s",tstring);
- fread(file,tstring2);
- AddItem(playerid,tstring,strval(tstring2));
- fread(file,tstring);
- }
- fclose(file);
- GetPlayerName(playerid,tstring,24);
- printf("[INV] %s[%d]'s inventory loaded.",tstring,playerid);
- return 1;
- }
- InventoryOnDialogResponse(playerid, dialogid, response, inputtext[])
- {
- if(dialogid!=INV_DIALOG_ID)return 1;
- if(!GetPVarInt(playerid,"PUSINGDIALOG"))return 1;
- if(!response)return 1;
- format(gItemList,MAX_ITEM_NAME,inputtext[strfind(inputtext,"\t")+2]);
- if(CallLocalFunction("OnPlayerUseItem","is",playerid,gItemList))UseItemInInventory(playerid);
- else SetPVarInt(playerid,"PUSINGDIALOG",0);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement