texture = getstringfield_default(L, 1, "texture", "");
playername = getstringfield_default(L, 1, "playername", "");
}
- if (playername == "") { // spawn for all players
- getServer(L)->spawnParticleAll(pos, vel, acc,
+ getServer(L)->spawnParticle(playername, pos, vel, acc,
expirationtime, size, collisiondetection, vertical, texture);
- } else {
- getServer(L)->spawnParticle(playername.c_str(),
- pos, vel, acc, expirationtime,
- size, collisiondetection, vertical, texture);
- }
return 1;
}
texture = getstringfield_default(L, 1, "texture", "");
playername = getstringfield_default(L, 1, "playername", "");
}
- if (playername == "") { //spawn for all players
- u32 id = getServer(L)->addParticleSpawnerAll( amount, time,
- minpos, maxpos,
- minvel, maxvel,
- minacc, maxacc,
- minexptime, maxexptime,
- minsize, maxsize,
- collisiondetection,
- vertical,
- texture);
- lua_pushnumber(L, id);
- } else {
- u32 id = getServer(L)->addParticleSpawner(playername.c_str(),
- amount, time,
- minpos, maxpos,
- minvel, maxvel,
- minacc, maxacc,
- minexptime, maxexptime,
- minsize, maxsize,
- collisiondetection,
- vertical,
- texture);
- lua_pushnumber(L, id);
- }
+
+ u32 id = getServer(L)->addParticleSpawner(amount, time,
+ minpos, maxpos,
+ minvel, maxvel,
+ minacc, maxacc,
+ minexptime, maxexptime,
+ minsize, maxsize,
+ collisiondetection,
+ vertical,
+ texture, playername);
+ lua_pushnumber(L, id);
+
return 1;
}
{
// Get parameters
u32 id = luaL_checknumber(L, 1);
-
- if (lua_gettop(L) == 2) // only delete for one player
- {
- const char *playername = luaL_checkstring(L, 2);
- getServer(L)->deleteParticleSpawner(playername, id);
- }
- else // delete for all players
- {
- getServer(L)->deleteParticleSpawnerAll(id);
+ std::string playername = "";
+ if (lua_gettop(L) == 2) {
+ playername = luaL_checkstring(L, 2);
}
+
+ getServer(L)->deleteParticleSpawner(playername, id);
return 1;
}
SendChatMessage(PEER_ID_INEXISTENT,msg);
}
-void Server::spawnParticle(const char *playername, v3f pos,
+void Server::spawnParticle(const std::string &playername, v3f pos,
v3f velocity, v3f acceleration,
float expirationtime, float size, bool
collisiondetection, bool vertical, const std::string &texture)
{
- Player *player = m_env->getPlayer(playername);
- if(!player)
- return;
- SendSpawnParticle(player->peer_id, pos, velocity, acceleration,
- expirationtime, size, collisiondetection, vertical, texture);
-}
+ u16 peer_id = PEER_ID_INEXISTENT;
+ if (playername != "") {
+ Player* player = m_env->getPlayer(playername.c_str());
+ if (!player)
+ return;
+ peer_id = player->peer_id;
+ }
-void Server::spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
- float expirationtime, float size,
- bool collisiondetection, bool vertical, const std::string &texture)
-{
- SendSpawnParticle(PEER_ID_INEXISTENT,pos, velocity, acceleration,
+ SendSpawnParticle(peer_id, pos, velocity, acceleration,
expirationtime, size, collisiondetection, vertical, texture);
}
-u32 Server::addParticleSpawner(const char *playername, u16 amount, float spawntime,
+u32 Server::addParticleSpawner(u16 amount, float spawntime,
v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
float minexptime, float maxexptime, float minsize, float maxsize,
- bool collisiondetection, bool vertical, const std::string &texture)
+ bool collisiondetection, bool vertical, const std::string &texture,
+ const std::string &playername)
{
- Player *player = m_env->getPlayer(playername);
- if(!player)
- return -1;
-
- u32 id = 0;
- for(;;) // look for unused particlespawner id
- {
- id++;
- if (std::find(m_particlespawner_ids.begin(),
- m_particlespawner_ids.end(), id)
- == m_particlespawner_ids.end())
- {
- m_particlespawner_ids.push_back(id);
- break;
- }
+ u16 peer_id = PEER_ID_INEXISTENT;
+ if (playername != "") {
+ Player* player = m_env->getPlayer(playername.c_str());
+ if (!player)
+ return -1;
+ peer_id = player->peer_id;
}
- SendAddParticleSpawner(player->peer_id, amount, spawntime,
- minpos, maxpos, minvel, maxvel, minacc, maxacc,
- minexptime, maxexptime, minsize, maxsize,
- collisiondetection, vertical, texture, id);
-
- return id;
-}
-
-u32 Server::addParticleSpawnerAll(u16 amount, float spawntime,
- v3f minpos, v3f maxpos,
- v3f minvel, v3f maxvel,
- v3f minacc, v3f maxacc,
- float minexptime, float maxexptime,
- float minsize, float maxsize,
- bool collisiondetection, bool vertical, const std::string &texture)
-{
u32 id = 0;
for(;;) // look for unused particlespawner id
{
}
}
- SendAddParticleSpawner(PEER_ID_INEXISTENT, amount, spawntime,
+ SendAddParticleSpawner(peer_id, amount, spawntime,
minpos, maxpos, minvel, maxvel, minacc, maxacc,
minexptime, maxexptime, minsize, maxsize,
collisiondetection, vertical, texture, id);
return id;
}
-void Server::deleteParticleSpawner(const char *playername, u32 id)
+void Server::deleteParticleSpawner(const std::string &playername, u32 id)
{
- Player *player = m_env->getPlayer(playername);
- if(!player)
- return;
-
- m_particlespawner_ids.erase(
- std::remove(m_particlespawner_ids.begin(),
- m_particlespawner_ids.end(), id),
- m_particlespawner_ids.end());
- SendDeleteParticleSpawner(player->peer_id, id);
-}
+ u16 peer_id = PEER_ID_INEXISTENT;
+ if (playername != "") {
+ Player* player = m_env->getPlayer(playername.c_str());
+ if (!player)
+ return;
+ peer_id = player->peer_id;
+ }
-void Server::deleteParticleSpawnerAll(u32 id)
-{
m_particlespawner_ids.erase(
std::remove(m_particlespawner_ids.begin(),
m_particlespawner_ids.end(), id),
m_particlespawner_ids.end());
- SendDeleteParticleSpawner(PEER_ID_INEXISTENT, id);
+ SendDeleteParticleSpawner(peer_id, id);
}
Inventory* Server::createDetachedInventory(const std::string &name)
void notifyPlayer(const char *name, const std::wstring &msg);
void notifyPlayers(const std::wstring &msg);
- void spawnParticle(const char *playername,
+ void spawnParticle(const std::string &playername,
v3f pos, v3f velocity, v3f acceleration,
float expirationtime, float size,
bool collisiondetection, bool vertical, const std::string &texture);
- void spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
- float expirationtime, float size,
- bool collisiondetection, bool vertical, const std::string &texture);
-
- u32 addParticleSpawner(const char *playername,
- u16 amount, float spawntime,
+ u32 addParticleSpawner(u16 amount, float spawntime,
v3f minpos, v3f maxpos,
v3f minvel, v3f maxvel,
v3f minacc, v3f maxacc,
float minexptime, float maxexptime,
float minsize, float maxsize,
- bool collisiondetection, bool vertical, const std::string &texture);
-
- u32 addParticleSpawnerAll(u16 amount, float spawntime,
- v3f minpos, v3f maxpos,
- v3f minvel, v3f maxvel,
- v3f minacc, v3f maxacc,
- float minexptime, float maxexptime,
- float minsize, float maxsize,
- bool collisiondetection, bool vertical, const std::string &texture);
+ bool collisiondetection, bool vertical, const std::string &texture,
+ const std::string &playername);
- void deleteParticleSpawner(const char *playername, u32 id);
- void deleteParticleSpawnerAll(u32 id);
+ void deleteParticleSpawner(const std::string &playername, u32 id);
// Creates or resets inventory
Inventory* createDetachedInventory(const std::string &name);