• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Play sound to all nearby players

Status
Not open for further replies.

Kaev

Super Moderator
Hiho,

i have a problem.. again. :<
I want to play a sound to all nearby players.
I found the following command: player->PlayDistanceSound(id, target);
Now i need to iterate through all nearby players to play the sound.
Is there a command like player->GetNearbyPlayersInDistance(10.0f)?

~Kaev
 

Rochet2

Moderator / Eluna Dev
The sound methods allow you to do it without getting players.
You just have to find the right way.
.. Ofc you can also get all players and so.

Eluna has a lot of methods coded. Its usually easy to go about and check those out :)
At least for me..
Code:
    {"PlayDirectSound", &LuaUnit::PlayDirectSound},         // :PlayDirectSound(soundId, player) - [COLOR="#00FF00"]Unit plays soundID to player, or everyone around if no player[/COLOR]
    {"PlayDistanceSound", &LuaUnit::PlayDistanceSound},     // :PlayDistanceSound(soundId, player) - [COLOR="#00FF00"]Unit plays soundID to player, or everyone around if no player.[/COLOR][COLOR="#FF8C00"] The sound fades the further you are[/COLOR]

    int PlayDirectSound(lua_State* L, Unit* unit)
    {
        uint32 soundId = luaL_checkunsigned(L, 1);
        Player* player = sEluna->CHECK_PLAYER(L, 2);
        if (!sSoundEntriesStore.LookupEntry(soundId))
            return 0;

[COLOR="#00FF00"]        if (player)
            unit->PlayDirectSound(soundId, player);
        else
            unit->PlayDirectSound(soundId);[/COLOR]
        return 0;
    }

    int PlayDistanceSound(lua_State* L, Unit* unit)
    {
        uint32 soundId = luaL_checkunsigned(L, 1);
        Player* player = sEluna->CHECK_PLAYER(L, 2);
        if (!sSoundEntriesStore.LookupEntry(soundId))
            return 0;

[COLOR="#00FF00"]        if (player)
            unit->PlayDistanceSound(soundId, player);
        else
            unit->PlayDistanceSound(soundId);[/COLOR]
        return 0;
    }

To get players you can do :
Code:
    float range = 10.0f;
    std::list<Player*> targets;
    Trinity::AnyPlayerInObjectRangeCheck check(player, range, false);
    Trinity::PlayerListSearcher<Trinity::AnyPlayerInObjectRangeCheck> searcher(player, targets, check);
    VisitNearbyWorldObject(range, searcher);

And then do w/e you want with targets list.
player can be any WorldObject to be used as the center of the radius.
 
Last edited:
Status
Not open for further replies.
Top