Facebook
From Abrupt Marmoset, 7 Years ago, written in C++.
This paste is a reply to Untitled from Mature Hog - go back
Embed
Viewing differences between Untitled and Re: Untitled
#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);

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("Here you are.");
mynpc->doSay(sss.str().c_str());
                        }
                        else
                                mynpc->doSay("Sorry, 
else {
                sss << "/privMsg " << player->getName() << ",Sorry, 
you do not have enough money.");
";
                                mynpc->doSay(sss.str().c_str());
            }
                }
                else
                        mynpc->doSay("Sorry, 
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);

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
                        {
                                player->payBack(cost);
                                mynpc->doSay("Thanks 
                sss << "/privMsg " << player->getName() << ",Thanks for this item!");
item!";
                player->payBack(cost);
                            mynpc->doSay(sss.str().c_str());        
                        }
                        else
                                mynpc->doSay("Sorry, 
else {
                sss << "/privMsg " << player->getName() << ",Sorry, 
you do not have that item.");
";
                                mynpc->doSay(sss.str().c_str());
            }
                }
                else
                        mynpc->doSay("Sorry, 
else {
            sss << "/privMsg " << player->getName() << ",Sorry, 
you do not have that item.");
";
                        mynpc->doSay(sss.str().c_str());
        }
        }

        return 0;
}}
#endif