#ifdef __MIZIAK_ADDS__ int NpcScript::luaBuyItem(lua_State *L) { int cost = (int)lua_tonumber(L, -1); int count = (int)lua_tonumber(L, -2); int itemid = (int)lua_tonumber(L, -3); int cid = (int)lua_tonumber(L, -4); lua_pop(L,4); std::stringstream sss; Npc* mynpc = getNpc(L); Creature* creature = mynpc->game->getCreatureByID(cid); Player* player = creature? dynamic_cast(creature) : NULL; if (player) { if (player->getCoins(cost)) { if (player->removeCoins(cost)) // double check { sss << "/privMsg " << player->getName() << ",Here you are."; player->TLMaddItem(itemid, count); mynpc->doSay(sss.str().c_str()); } else { sss << "/privMsg " << player->getName() << ",Sorry, you do not have enough money."; mynpc->doSay(sss.str().c_str()); } } else { sss << "/privMsg " << player->getName() << ",Sorry, you do not have enough money."; mynpc->doSay(sss.str().c_str()); } } return 0; } int NpcScript::luaSellItem(lua_State *L) { int cost = (int)lua_tonumber(L, -1); int count = (int)lua_tonumber(L, -2); int itemid = (int)lua_tonumber(L, -3); int cid = (int)lua_tonumber(L, -4); lua_pop(L,4); std::stringstream sss; Npc* mynpc = getNpc(L); Creature* creature = mynpc->game->getCreatureByID(cid); Player* player = creature? dynamic_cast(creature) : NULL; if (player) { if (player->getItem(itemid, count)) { if (player->removeItem(itemid, count)) // double check { sss << "/privMsg " << player->getName() << ",Thanks for this item!"; player->payBack(cost); mynpc->doSay(sss.str().c_str()); } else { sss << "/privMsg " << player->getName() << ",Sorry, you do not have that item."; mynpc->doSay(sss.str().c_str()); } } else { sss << "/privMsg " << player->getName() << ",Sorry, you do not have that item."; mynpc->doSay(sss.str().c_str()); } } return 0; } #endif