Exemple #1
0
int32_t NpcScriptInterface::luaActionSay(lua_State* L)
{
	//selfSay(words [[, target], publicize])
	// publicize defaults to true if there is no target, false otherwise
	uint32_t parameters = lua_gettop(L);
	uint32_t target = 0;
	bool publicize;
	if (parameters >= 3) {
		publicize = popBoolean(L);
	} else {
		publicize = true;
	}

	if (parameters >= 2) {
		target = popNumber(L);
		if (target != 0) {
			publicize = false;
		}
	}

	std::string text = popString(L);

	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		if (publicize) {
			npc->doSay(text);
		} else {
			npc->doSayToPlayer(g_game.getPlayerByID(target), text);
		}
	}

	return 0;
}
Exemple #2
0
int NpcScriptInterface::luaActionSay(lua_State* L)
{
    //selfSay(words[, target])
    Npc* npc = getScriptEnv()->getNpc();
    if (!npc) {
        return 0;
    }

    const std::string& text = getString(L, 1);
    if (lua_gettop(L) >= 2) {
        Player* target = getPlayer(L, 2);
        if (target) {
            npc->doSayToPlayer(target, text);
            return 0;
        }
    }

    npc->doSay(text);
    return 0;
}