Jump to content
  • 0

ItemSearch and ShopNPC


ankana

Question


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  05/29/12
  • Last Seen:  

Hi @all Scripter,

i need some help with a special npc.

I want to create a npc that can search for a given itemname within the database, show the output

within the text-window as a menu for the player - and then the player can klick on one of these

items and push a button for example "OK", and then the item will be given to the player.

I have tried to create this npc, but im not a well scripter, so this is everything i have written so foar:

prontera.gat,xxx,yyy,7<tab>script<tab>Item-Watcher<tab>811,{
   mes "[item-Watcher]";
   mes "Which item are you looking for?";
    input @item;
   query_sql "SELECT id,name_english FROM `itemdb` WHERE `name_english` LIKE @item", @liste;
   for(set @i, 0; @i < getarraysize(@liste); set @i,@i + 1){
       mes @liste[@i];
   }
   ....

Can please someone help me.

Kind Regards

Ankana

Link to comment
Share on other sites

5 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  05/29/12
  • Last Seen:  

I will test it - if im home later.

Thanks in Advance

Ankana

Yeah - i did it - now everything works as mentioned.

I'll post it here, if i'm home in the evening.

What is the npc doing:

1) search for a given itemname within the database

2) show a list of available items containing this part of item within the name as a menu (maybe i'll sort them within the menu)

3) ask for an amount of these item

4) put the amount of the selected item into the player's inventory

See ya later

Ankana

prontera.gat,150,186,5 script Item-Distributor 109,{

 mes "[item-Distributor]";
    mes "Which item are you looking for?";
 next;
    input .@item$;
 set @nb,query_sql("select `id`,`name_japanese`,`slots` from `item_db` where `name_japanese` LIKE '%"+.@item$+"%'",.@itemid,.@itemname$,.@slots);
 mes "[item-Distributor]";
    mes "Item Search for : "+.@item$;
 set $@menu$,"Cancel";
 for(set .@i, 0;.@i < getarraysize(.@itemid);set .@i, .@i + 1){
   set .@menu$,.@menu$+":"+.@itemname$[.@i]+"["+.@slots[.@i]+"]";
   //mes .@itemname$[.@i]+"["+.@slots[.@i]+"] (ID "+.@itemid[.@i]+")";
    }
 mes "Please select your wanted Item from the List.";
 set .@part,select(.@menu$);
 mes "How Many Items do you want ?";
 input .@number;
 next;
 set .@part,.@part -2;
 mes .@number+" "+.@itemname$[.@part]+"(ID "+.@itemid[.@part]+") was created.";
 getItem .@itemid[.@part],.@number;
 close;
}

Edited by ankana
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  351
  • Reputation:   52
  • Joined:  11/15/11
  • Last Seen:  

Your issue here, not going to far into scripting, with the script is that you didn't use @item correctly.

while input @item is ok, 1, it's not a string, so only numbers work, so you'd need to use input @item$, while I personally would use .@item$.

2, in the query you used, it doesn't know what @item is because you incorrectly placed it. It should be:

query_sql "SELECT `id`,`name_english` FROM `item_db` WHERE `name_english` LIKE "+.@item$, .@itemid, .@liste$;

Also unless you renamed your sql db to be named itemdb, it should be item_db, and you defined 2 variables to be selected, so unless you put them into variables, your map server will hate you, so add .@itemid.

The sql query above should work. Take note however that I modified @item to be .@item$ and @liste to be .@list$

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  05/29/12
  • Last Seen:  

Thanks for the quick answer. So referring to your answer i have (i hope correctly) changed the code into:

prontera.gat,xxx,yyy,7<tab>script<tab>Item-Watcher<tab>811,{
    mes "[item-Watcher]";
    mes "Which item are you looking for?";
		    input .@item$;
    query_sql "SELECT `id`,`name_english` FROM `item_db` WHERE `name_english` LIKE "+.@item$, .@itemid, .@itemname$;
    for(set @i, 0; @i < getarraysize(.@itemname); set @i,@i + 1){
   mes .@itemname$[@i]+"("+.@itemid$+")";
    }

So if this is now nearly correct, i now have to find a solution for the switch-menu of the listed items :)

Thanks

Ankana

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  351
  • Reputation:   52
  • Joined:  11/15/11
  • Last Seen:  

1 thing, you used the getarraysize correctly but you forgot 1 symbol, it's .@itemname$ not .@itemname

Use arrays~

below

for(set @i, 0; @i < getarraysize(.@itemname); set @i,@i + 1){

add

set .@menu$,.@menu$ + .@itemname$[.@i] + ":";

and then after the curly add..

select(.@menu$)

and this would be an example of how to get the item..

set .@i,.@menu$-1;
getitem .@itemid[.@i],1;
end;

Edited by Nameless2you
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  6
  • Reputation:   0
  • Joined:  05/29/12
  • Last Seen:  

If Anyone find this Code useful, maybe someone can move this thread to the "script releases".

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...