HugoBoss Posted May 7, 2019 Posted May 7, 2019 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
0 zconll Posted May 7, 2019 Posted May 7, 2019 You is using incorrect syntax, change: myself.OwnItemCount -> OwnItemCount
0 HugoBoss Posted May 8, 2019 Author Posted May 8, 2019 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 Anarchy Posted May 8, 2019 Posted May 8, 2019 (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 May 8, 2019 by Anarchy 1
0 HugoBoss Posted May 8, 2019 Author Posted May 8, 2019 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 hugolez Posted May 14, 2019 Posted May 14, 2019 maybe u use this if (myself::OwnItemCount(talker, myItemID) > 0)
0 HugoBoss Posted May 15, 2019 Author Posted May 15, 2019 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!
0 hugolez Posted May 22, 2019 Posted May 22, 2019 Remenber: reload ai.obj after at inyected new ai from npc.exe menu reload AI.-
Question
HugoBoss
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
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 accountSign in
Already have an account? Sign in here.
Sign In Now