Advertisement
Rochet2

Untitled

Jun 23rd, 2013
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. static int GetPlayersInRange(lua_State* L)
  2. {
  3.     WorldObject* obj = sEluna->CHECK_WORLDOBJECT(L, 1);
  4.     float range = luaL_optnumber(L, 2, SIZE_OF_GRIDS);
  5.     if (!obj)
  6.         return 0;
  7.  
  8.     std::list<Player*> list;
  9.     Trinity::AnyPlayerInObjectRangeCheck checker(obj, range);
  10.     Trinity::PlayerListSearcher<Trinity::AnyPlayerInObjectRangeCheck> searcher(obj, list, checker);
  11.     obj->VisitNearbyGridObject(range, searcher);
  12.     Trinity::ObjectGUIDCheck guidCheck(obj->GetGUID());
  13.     list.remove_if(guidCheck);
  14.  
  15.     lua_newtable(L);
  16.     int tbl = lua_gettop(L);
  17.     uint32 i = 0;
  18.  
  19.     for (std::list<Player*>::const_iterator it = list.begin(); it != list.end(); ++it)
  20.     {
  21.         sEluna->PushUnsigned(L, ++i);
  22.         sEluna->PushUnit(L, *it);
  23.         lua_settable(L, tbl);
  24.     }
  25.  
  26.     lua_settop(L, tbl);
  27.     return 1;
  28. }
  29.  
  30. // works
  31. static int GetPlayersInRange(lua_State* L)
  32. {
  33.     WorldObject* obj = sEluna->CHECK_WORLDOBJECT(L, 1);
  34.     float range = luaL_optnumber(L, 2, SIZE_OF_GRIDS);
  35.     if (!obj)
  36.         return 0;
  37.  
  38.     std::list<Player*> playerList;
  39.     Trinity::AnyPlayerInObjectRangeCheck checker(obj, range);
  40.     Trinity::PlayerListSearcher<Trinity::AnyPlayerInObjectRangeCheck> searcher(obj, playerList, checker);
  41.     obj->VisitNearbyWorldObject(range, searcher);
  42.     Trinity::ObjectGUIDCheck guidCheck(obj->GetGUID());
  43.     playerList.remove_if(guidCheck);
  44.  
  45.     lua_newtable(L);
  46.     int tbl = lua_gettop(L);
  47.     uint32 i = 0;
  48.  
  49.     for(std::list<Player*>::const_iterator itr = playerList.begin(); itr != playerList.end(); ++itr)
  50.     {
  51.         ++i;
  52.         sEluna->PushUnsigned(L, i);
  53.         sEluna->PushUnit(L, (*itr));
  54.         lua_settable(L, tbl);
  55.     }
  56.  
  57.     lua_settop(L, tbl);
  58.     return 1;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement