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

    • Hello guys, gh0t from gh0tstudio here. This time we are putting to sale this beafitul landing page for your next server. Lineage 2 Server Landing Page Template u can check it here LINEAGE 2 DEMO SITE   Technology Stack - React 18 with TypeScript - Tailwind CSS for styling - Framer Motion for animations - Vite for fast development and builds - Multi-language support (i18n ready) Responsive Design The template is fully responsive and optimized for all screen sizes. Desktop, tablet, and mobile layouts have been carefully crafted to provide the best user experience on any device. The mobile version includes a unique notch-style hero design with custom clip paths. What is Included - Complete landing page source code - Hero section with parallax scroll effect - Server information section with animated cards - Character classes showcase with interactive gallery - Registration form (frontend only, styled and validated) - Donation packages display section - Download section for game client - Sticky navigation with transparency effects - Footer with social links - Multi-language system (Spanish/English ready) - All animations and transitions - Clean, documented code structure - Easy to customize colors and content   What is Not Included - Backend server or API - User registration panel/dashboard - Payment processing system for donations - Database integration - Connection to L2 game server - Online player counter module - Account management system - Hosting or domain   The template provides the complete frontend experience.  Price: $150 USD     Contact For purchase inquiries or questions about the template, please reach out directly.
    • 流量套利 + SMM 面板 — 强大的增长组合. 通过社交信号加强推广活动,提高信任度和转化率,加速扩张。 为套利专员和 SMM 提供的所有工具 — 在一个地方. 有效链接: SMM 面板: 前往 – 推广您的社交媒体账户。 其他服务和产品: 数字商品商店(网站): 前往 商店 Telegram 机器人: 前往 – 通过 Telegram 信使方便访问商店。 虚拟号码服务: 前往 用于购买 Telegram Stars 的 Telegram 机器人: 前往 – 在 Telegram 中快速且优惠地购买 Stars。 SMM 面板: 前往 – 推广您的社交媒体账户。 我们想向您展示当前促销和特别优惠列表,用于购买我们服务的产品和服务: 1. 您可以在首次购买时使用促销代码:SOCNET(15% 折扣) 2. 获取 $1 商店余额或 10–20% 折扣——只需在我们网站注册后按以下模板填写您的用户名:"SEND ME BONUS, MY USERNAME IS..." ——您需要在我们的论坛主题中发布! 3. SMM 面板首次试用可获得 $1:只需在我们的网站(Support)提交主题为 “Get Trial Bonus” 的工单。 4. 我们的 Telegram 频道和 Stars 购买机器人中每周都会赠送 Telegram Stars! 新闻: ➡ Telegram 频道: https://t.me/accsforyou_shop ➡ WhatsApp 频道: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord 服务器: https://discord.gg/y9AStFFsrh 联系方式和支持: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
  • 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