• 0
HugoBoss

Help How to check if an item exists in users inventory

Question

Hello guys,

 

I want to check through ai if an item exists in the users inventory.

 

I have tried using function: OwnItemCount but i got compilation error: Undefined function. (Using l2shrine compiler shared by Eressea).

 

Below is an example of my code as i am trying to compile it:

set_compiler_opt base_event_type(@NTYPE_NPC_EVENT)
class default_npc
{
}

class citizen : default_npc
{
}
class myclass : citizen
{
...
  EventHandler MENU_SELECTED( talker, ask, reply) {
    ...
    if(myself.OwnItemCount(talker, 57) > 0 )
    {
    //do something
    }
  }
...
}

 

I have also tried using GlobalObject::OwnItemCount like gg.OwnItemCount but i get the message that gg is an unknown variable..

 

Do you use some other function for this? 

If anyone could shed some light on this i'd appreciate it. 

 

Thanks,

Hugo

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0
14 hours ago, zconll said:

You is using incorrect syntax, change:

 

myself.OwnItemCount -> OwnItemCount

 

 

It works that way! Thank you.

 

Can you elaborate a bit on that, why it works that way and the difference between your proposed way and myself.OwnItemCount?

 

Also, it would be better instead of using direct item id in the code, i place a paramter and use that instead, so:

 

if(OwnItemCount(talker, 57) > 0)

becomes:

 

if(OwnItemCount(talker, myItemID) > 0)

I have also created this parameter section:

 

class myclass : citizen
{
parameter:
  int	  myItemID = 57;

}

 

But i get an error that this is an "abnormal" parameter when the NPC reaches that part of the code.

 

Am i not using it correctly?

 

Thanks,

Hugo

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

functions from the event object (myself) or the global object (gg) don't have myself./gg. to call them, thats just how it works :D

 

using a defined parameter in the AI class is only really useful if you plan on changing it later and want an easier way to edit it, or if you want to set those parameters via npcdata or npcpos, otherwise just using the id is fine, but you can also use the pch name for it, so OwnItemCount(talker, @adena)

 

as for what it errors on you, could just be it doesn't like your spacing on it, so try just

int myItemID = 57;

 

which you can also use the pch name on, so int myItemID = @adena; should work too

 

the l2off parsers are very bitchy about formatting :D

Edited by Anarchy
  • Thanks 1

Share this post


Link to post
Share on other sites
  • 0
1 hour ago, Anarchy said:

functions from the event object (myself) or the global object (gg) don't have myself./gg. to call them, thats just how it works :D

 

using a defined parameter in the AI class is only really useful if you plan on changing it later and want an easier way to edit it, or if you want to set those parameters via npcdata or npcpos, otherwise just using the id is fine, but you can also use the pch name for it, so OwnItemCount(talker, @adena)

 

as for what it errors on you, could just be it doesn't like your spacing on it, so try just

int myItemID = 57;

 

which you can also use the pch name on, so int myItemID = @adena; should work too

 

the l2off parsers are very bitchy about formatting :D

 

Very insightful, thank you for taking the time!

 

I will play a little bit with the spacing and report back!

 

Thanks,

Hugo

Share this post


Link to post
Share on other sites
  • 0
23 hours ago, hugolez said:

maybe u use this

 


if (myself::OwnItemCount(talker, myItemID) > 0)

 

Hey,

 

well after i restarted the processes everything works.

 

So the spacing was ok.

 

Thank you for your reply!

Share this post


Link to post
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.


  • Recently Browsing   0 members

    No registered users viewing this page.