Jump to content
  • 0

Check inventory for weapons/shields


Succubusty

Question


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  11
  • Reputation:   0
  • Joined:  04/07/13
  • Last Seen:  

I'm working on my custom event & I need to be able to check if players have any weapons or shields in their inventory. So something kind of like countitem but instead of just checking for one item, checking for a whole item type (weapons & shields). Here's a snippet of what I have going on.

 

    else
    {
        if(getequipweaponlv(4)==0 && getequipweaponlv(3)==0)
        {
            next;
            mes @npc$;
            mes " ";
            mes "When you enter the event, don't forget to read the rules and requirements from the ^008000Ceres Event Staff^000000 NPC inside.";
            close2;
            warp "turbo_n_1.gat",383,163;
            npctalk "The player "+ strcharinfo(0) +" has joined the Ceres Track Event!";
            end;
        }
        else
        {
            if(____________________)
            {
                next;
                mes @npc$;
                mes " ";
                mes "^CC0000Sorry, You can't have any weapons or shields when entering this event.";
                mes " ";
                mes "Go store your weapons and shields and try again.^000000";
                close;
            }
        }
    }


 

I couldn't find what I needed for the life of me... anyone care to help me out?

Edited by Succubusty
Link to comment
Share on other sites

3 answers to this question

Recommended Posts


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

I think you should use Getinventorylist to retrieve the item ID of the inventory with @inventorylist_id[] like icabit said.

Then make a loop to check each Item with Getiteminfo

 

 

Loc: Equipment's placement. Values are:
    2^8  256 = Upper Headgear
    2^9  512 = Middle Headgear
    2^0  001 = Lower Headgear
    2^4  016 = Armor
    2^1  002 = Weapon
    2^5  032 = Shield
    2^2  004 = Garment
    2^6  064 = Footgear
    2^3  008 = Accessory 1
    2^7  128 = Accessory 2
    2^10 1024 = Costume Top Headgear
    2^11 2048 = Costume Mid Headgear
    2^12 4096 = Costume Low Headgear
    2^13 8192 = Costume Garment/Robe

 

 

	getinventorylist;
	while ( .@i < @inventorylist_count && getiteminfo( @inventorylist_id[ .@i ] ,5 ) != 32 && getiteminfo( @inventorylist_id[ .@i ] ,5 ) != 2 ) .@i++;
	if ( .@i < @inventorylist_count ) {
		mes "Sorry you have a weapon or a shield in your inventory.";
		close;
	}
	mes "you pass.";
	close;
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  353
  • Reputation:   70
  • Joined:  07/14/12
  • Last Seen:  

http://rathena.org/wiki/Getinventorylist
 

something like this could help but problem is you can't check their weapon lvl in the inventory since

getweaponlv is only used for equipment slot

 

maybe could use
@inventorylist_id[]
and get the range of item numbers for weapon in item_db and your item_db2

example

 

    getinventorylist;
    for(set .@i,0; .@i < @inventorylist_count; set .@i,.@i+1){
        if((@inventorylist_id[.@i] >= 1000)||(@inventorylist_id[.@i] <= 10000)){// this will trigger if the item number of a specific item in your inventory in on or between 1000 and 10000
            mes "YOUR MESSAGE";
            close;
        }
    }

 

or

use ur sql item_db

note equiplocation 32 = lefthand

note equiplocation 2 = righthand

note equiplocation 34 = bothhands

    getinventorylist;
    for(set .@i,0; .@i < @inventorylist_count; set .@i,.@i+1){
       query_sql ("SELECT `equip_locations` FROM `item_db` WHERE `id` ="+@inventorylist_id[.@i]+"",.@eloc);// make sure you are reading the right database im using item_db
       if(.@eloc==32 || .@eloc==2 || .@eloc==34)
            {
               mes "You are not Allowed to bring any weapon or shield";
               close;
               break;//ends the loop
            }
    }

if you wanna use item_db and item_db2 in your sql database use this

note equiplocation 32 = lefthand

note equiplocation 2 = righthand

note equiplocation 34 = bothhands

    getinventorylist;
    for(set .@i,0; .@i < @inventorylist_count; set .@i,.@i+1){
       query_sql ("SELECT `equip_locations` FROM `item_db` WHERE `id` ="+@inventorylist_id[.@i]+"",.@eloc);// make sure you are reading the right database im using item_db
       query_sql ("SELECT `equip_locations` FROM `item_db2` WHERE `id` ="+@inventorylist_id[.@i]+"",.@eloc2);// make sure you are reading the right database im using item_db2
       if(.@eloc==32 || .@eloc==2 || .@eloc==34)
            {
               mes "You are not Allowed to bring any weapon or shield";
               close;
               break;//ends the loop
            }
       if(.@eloc2==32 || .@eloc2==2 || .@eloc2==34)
            {
               mes "You are not Allowed to bring any weapon or shield";
               close;
               break;//ends the loop
            }
    }

 

i haven't tested this but using item_db in your sql database is the best solution for these kinds of scenario since like i said above getweaponlv is only used for equipment slot. it doesn't support items in your inventory

Edited by icabit
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  11
  • Reputation:   0
  • Joined:  04/07/13
  • Last Seen:  

I tried to incorporate what both of you said. Here's what I've got:
 

 
else
    {
        getinventorylist;
        while ( .@i < @inventorylist_count && getiteminfo( @inventorylist_id[ .@i ] ,5 ) != 32 && getiteminfo( @inventorylist_id[ .@i ] ,5 ) != 2 ) .@i++;
        if ( .@i < @inventorylist_count )
        {
            next;
            mes @npc$;
            mes " ";
            mes "^CC0000Sorry, You can't have any weapons or shields when entering this event.";
            mes " ";
            mes "Go store your weapons and shields and try again.^000000";
            close;
        }
        else
        {
            if(getequipweaponlv(4)==0 && getequipweaponlv(3)==0)
            {
                next;
                mes @npc$;
                mes " ";
                mes "^CC0000Sorry, You can't have any weapons or shields when entering this event.";
                mes " ";
                mes "Go store your weapons and shields and try again.^000000";
                close;
            }
            else
            {
                next;
                mes @npc$;
                mes " ";
                mes "When you enter the event, don't forget to read the rules and requirements from the ^008000Ceres Track Staff^000000 NPC inside.";
                close2;
                warp "turbo_n_1.gat",383,163;
                npctalk "The player "+ strcharinfo(0) +" has joined the Ceres Track Event!";
                end;
            }
        }
    }
 

 
However, when I use it, it tells me I have something a weapon/shield equipped even if I don't. I think I might be working myself in circles here with the if/then statements, but maybe y'all can see something that I can't.
 
I'm trying to get it to first check the inventory to see if you have a weapon or shield in your inventory. If you do, it tells you to go store your items. If you don't, then it checks to see if you have a weapon or shield equipped. If you do, it tells you to store it. if you don't, then you're allowed to continue on to the event.
 
Where did I go wrong?

 

 

EDIT: NVM. I figured it out. xD I switched the last two functions by mistake.

Thanks very much for the help. c:

Edited by Succubusty
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...