Hi Luan, i think that your code is from Hercules and not from Rathena, i recommend to see the npc_click function in npc.c
int npc_click(struct map_session_data* sd, struct npc_data* nd)
{
nullpo_retr(1, sd);
if (sd->npc_id != 0) {
ShowError("npc_click: npc_id != 0\n");
return 1;
}
if(!nd) return 1;
if ((nd = npc_checknear(sd,&nd->bl)) == NULL)
return 1;
//Hidden/Disabled npc.
if (nd->class_ < 0 || nd->sc.option&(OPTION_INVISIBLE|OPTION_HIDE))
return 1;
switch(nd->subtype) {
case NPCTYPE_SHOP:
clif_npcbuysell(sd,nd->bl.id);
break;
case NPCTYPE_CASHSHOP:
case NPCTYPE_ITEMSHOP:
case NPCTYPE_POINTSHOP:
clif_cashshop_show(sd,nd);
break;
case NPCTYPE_MARKETSHOP:
#if PACKETVER >= 20131223
{
unsigned short i;
for (i = 0; i < nd->u.shop.count; i++) {
if (nd->u.shop.shop_item[i].qty)
break;
}
if (i == nd->u.shop.count) {
clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 534), false, SELF);
return false;
}
sd->npc_shopid = nd->bl.id;
clif_npc_market_open(sd, nd);
}
#endif
break;
case NPCTYPE_SCRIPT:
run_script(nd->u.scr.script,0,sd->bl.id,nd->bl.id);
break;
case NPCTYPE_TOMB:
run_tomb(sd,nd);
break;
}
return 0;
}
you can see here all the things you need