Jump to content
  • 0

How to check if an item exists in users inventory


Question

Posted

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

7 answers to this question

Recommended Posts

  • 0
Posted
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

  • 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
  • 0
Posted
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

  • 0
Posted
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!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • what do u mean i want to change the normal weapons some weapons are working perftect some not getting th effect and the arcana has the effect above the weapons as u see ... i dont what is the probkenm
    • Stop paying for files that are already public and free. Here you can download a fully working Interlude server with C4-like gameplay, including source code so you can compile it yourself and verify everything. People will try to convince you that free releases are “broken”, “full of backdoors”, etc. That’s exactly why I’m also providing the SVN with the full source – so you can: Review the code yourself Remove / modify whatever you don’t like Compile your own binaries What’s included GX-EXT Interlude server (C4-style gameplay) – L2Off Client Interlude tweaked for C4 gameplay Public SVN with source code Downloads: Server GX-EXT: https://www.mediafire.com/file/q5ipkjd36tnhfxv/L2OFF_C4_C4_ACU_GXEXT.rar/file Client Interlude C4 Gameplay: https://www.mediafire.com/file/rdkfc8wwau042oh/Cliente_Interlude_Jugabilidad_C4.rar/file SVN (source code, delayed a couple of months to avoid reselling fresh work): https://svn.l2servers.com.ar/!/#GX-EXT_INTERLUDE User: gx Pass: gx How to compile To compile the source you will need: Visual Studio 2005 (x64 toolset) (Classic L2Off toolchain – yes, it’s old, but that’s what the original server uses.) Use this as you want: learn, test, open your own server, or just audit the code. But please, stop buying the same leaked/resold files over and over when you can get them here for free, with source, and actually know what you’re running.  
    • @GX-Ext Please reupload the pack+web+client because all the links inside that post or in the https://l2servers.com.ar/ are dead
    • Weapon dat is not the same for all, since you have custom things for sure no. You can contact @NevesOma
    • hello guys im facing a problem with the weapons .. i want to add hero glow on s weapons arcana ,dragonic bow etc.. some weapons are work peftect .. some not for example i add the line  LineageEffect.e_u092_h for fists and didnt work didnt even get the hero glow.. and the arcana the glow is on the top of weapon not down side like hero zeus mace any ideas?.. or does anybody has the weapongrp.dat file ready ?
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock