[Include] [INC]Player Inventory[v2] -- Now with Saving/Loading functions
#21

Quote:
Originally Posted by MisterTickle
Why am I getting j_inventory.inc(66) : error 001: expected token: ")", but found "continue"

when I use ifplayerhasitem
Show the line that ifplayerhasitem is on.
Reply
#22

I don't understand what you mean...
Reply
#23

Quit spamming,

pawn Код:
public OnPlayerCommandText(playerid,cmdtext[])
{
  if(!strcmp(cmdtext,"/buy",true))
  {
    ShowPlayerDialog(playerid,13337,DIALOG_STYLE_LIST,"Store","Medkit -$500\nM4-$1000","Buy","Close");
    return 1;
  }
  return 0;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
  InventoryOnDialogResponse(playerid, dialogid, response, inputtext);
  if(dialogid==13337)
  {
    if(response)
    {
      switch(listitem)
      {
        case 0:
        {
          if(GetPlayerMoney(playerid)<500)SendClientMessage(playerid,0xFF0000FF,"You do not have enough cash!");
          else{
            GivePlayerMoney(playerid,-500);
            AddItem(playerid,"Medkit",1);
          }
          ShowPlayerDialog(playerid,13337,DIALOG_STYLE_LIST,"Store","Medkit -$500\nM4-$1000","Buy","Close");
          return 1;
        }
        case 1:
        {
          if(GetPlayerMoney(playerid)<1000)SendClientMessage(playerid,0xFF0000FF,"You do not have enough cash!");
          else{
            GivePlayermoney(playerid,-1000);
            AddItem(playerid,"M4 Assault Rifle",1);
          }
          ShowPlayerDialog(playerid,13337,DIALOG_STYLE_LIST,"Store","Medkit -$500\nM4-$1000","Buy","Close");
          return 1;
        }
      }
    }
  }
  return 1;
}
public OnPlayerUseItem(playerid,ItemName[])
{
  if(!PlayerHasItem(playerid,ItemName))return SendClientMessage(playerid,0xFF0000FF,"You no longer have that item!");
  if(!strcmp(ItemName,"Medkit",true))
  {
    new Float:hp;
    GetPlayerHealth(playerid,hp);
    if(hp>=100)return SendClientMessage(playerid,0xFF0000FF,"You have full health.");
    if(hp>75)SetPlayerHealth(playerid,100);
    else SetPlayerHealth(playerid,hp+25);
    RemoveItem(playerid,ItemName,1);
    return SendClientMessage(playerid,0xFF0000FF,"You've used a medkit.");
  }
  if(!strcmp(ItemName,"M4 Assault Rifle",true))
  {
    GivePlayerWeapon(playerid,31,30);
    RemoveItem(playerid,ItemName,1);
    return SendClientMessage(playerid,0xFF0000FF,"You pulled out an M4.");
  }
  return 0;
}
That's an example, you should be able to convert your current /buy with what I've given you.
Reply
#24

For some reason, It lets me add more than 10 items (what I listed under Max_Items)
Reply
#25

Would be nice if u can overwrite it with pVars
Reply
#26

I create /time command and not working
/time code:
Код:
if(strcmp(cmd, "/time", true) == 0)
{
if(PlayerHasItem(playerid,"Zegarek"))
{
new godzina, minuta, sekunda;
gettime(godzina, minuta, sekunda);
new string[150];
format(string, sizeof(string), "Jest godzina %d:%d:%d.",godzina, minuta, sekunda);
SendClientMessage(playerid, COLOR_PURPLE, string);
ShowInventory(playerid);
}
else
{
SendClientMessage(playerid, COLOR_RED, "Nie posiadasz zegarka.");
}
return 1;
}
Please help, fast
//edit: I fix this problem.
Reply
#27

I have a problem... When I copy in "public OnPlayerUseItem (playerid, ItemName [])" this line: if (! PlayerHasItem (playerid, ItemName)) return SendClientMessage (playerid, 0xFFFFFFFF, "You no longer have that item!"); there is an error: gf _SCR.pwn (704): error 001: expected token: ")", but found"continue" . What to do?
Reply
#28

Quote:
Originally Posted by Her
I have a problem... When I copy in "public OnPlayerUseItem (playerid, ItemName [])" this line: if (! PlayerHasItem (playerid, ItemName)) return SendClientMessage (playerid, 0xFFFFFFFF, "You no longer have that item!"); there is an error: gf _SCR.pwn (704): error 001: expected token: ")", but found"continue" . What to do?
Problem fixed - download new version


Version 2 uploaded:
-Adds SaveInventory(playerid) and LoadInventory(playerid)
-Fixes reported bugs
-Converted to use PVars
Reply
#29

Nice work, thanks
Reply
#30

lol to be honest...

too many errors :P

Quote:

C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(52 : error 017: undefined symbol "SaveInventory"
C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(531) : warning 235: public function lacks forward declaration (symbol "OnPlayerUseItem")
C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(53 : warning 213: tag mismatch
C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(539) : error 017: undefined symbol "RemoveItem"
C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(663) : error 017: undefined symbol "AddItem"
C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(667) : error 017: undefined symbol "PlayerHasItem"
C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(670) : error 017: undefined symbol "RemoveItem"
C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(677) : warning 219: local variable "idx" shadows a variable at a preceding level
C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(677) : error 017: undefined symbol "MAX_ITEM_NAME"
C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(677) : error 009: invalid array size (negative, zero or out of bounds)
C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(677) : error 036: empty statement
C:\Documents and Settings\Owen\Desktop\owen's server\gamemodes\GOT.pwn(677) : fatal error 107: too many error messages on one line

Reply
#31

I need it
pls reupload it ^^
Reply
#32

I am also very necessary. Who can not make at least help.
And if removing almost everything is destroy immediately the subject, rather than hide files and other ... Why then do the whole topic, if you hid behind .....
Reply
#33

Epic job man, very useful for any server!
Reply
#34

the url on the first post is now a TinyURL to the same link...


works now...
Reply
#35

Hm .. I do not know, but I do not work for some reason.
Complite get it done, but nothing else.
I am writing team / or inventory to be determined by your and nothing anyway.
These commands are not found ...
Arrange full script ....
Reply
#36

Here the code for the one who cannot download it:

pawn Code:
#define INV_DIALOG_ID 13337
#define MAX_ITEMS 99
#define MAX_ITEM_STACK 99
#define MAX_ITEM_NAME 128
forward OnPlayerUseItem(playerid,ItemName[]);
new gItemList[(MAX_ITEMS+1)*(MAX_ITEM_NAME+3)];
/*
native AddItem(playerid,ItemName[],Amount);
native RemoveItem(playerid,ItemName[],Amount);
native PlayerHasItem(playerid,ItemName[]);
native GetPlayerItemInfo(playerid,&idx,const ItemName[],len=sizeof(ItemName),&Amount);
native ResetPlayerInventory(playerid);
native ShowInventory(playerid);
native InventoryOnDialogResponse(playerid, dialogid, response, inputtext[]);
native SaveInventory(playerid);
native LoadInventory(playerid);
*/

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 ShowInventory(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));
    }
    format(gItemList,sizeof(gItemList),"Amount\t\tItem Name%s",gItemList);
    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,"Inventory/%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,"Inventory/%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); //Delete last character
        fread(file,tstring2);
        AddItem(playerid,tstring,strval(tstring2));
        fread(file,tstring);
    }
    fclose(file);
    GetPlayerName(playerid,tstring,24);

    return 1;
}
InventoryOnDialogResponse(playerid, dialogid, response, inputtext[])
{
    if(dialogid!=INV_DIALOG_ID)return 1;
    if(!GetPVarInt(playerid,"PUSINGDIALOG"))return 1;
    if(!response)return 1;
    if(!strcmp(inputtext,"Amount",true,6))
    {
        ShowInventory(playerid);
        return 1;
    }
    format(gItemList,MAX_ITEM_NAME,inputtext[strfind(inputtext,"\t")+2]);
    if(CallLocalFunction("OnPlayerUseItem","is",playerid,gItemList))ShowInventory(playerid);
    else SetPVarInt(playerid,"PUSINGDIALOG",0);
    return 1;
}
Reply
#37

I downloaded this one script, but it does not work for me ... Does not show any signs ...
Type the following commands is not a write to any specific team.
Reply
#38

This is a Suggestion
I think it will be very usefull to add a function that will defined the Max Item Slot per player something like
DefindePlayerMaxItems(Playerid,MaxSlot) and samething for the STAKS, it will be good for server (for example in TDM rank up = more Slots/stacks && for rp server you can buy bigger Inventoryes/backpacks)
Reply
#39

if i want to give someone my items so what should i do?
Reply
#40

This does not handle accented characters.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)