From 4e6971e59358b40956bb4c25f8f85e4cc018dbec Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 25 Jul 2015 11:56:24 +0200 Subject: Cleanup server addparticle(spawner) by merge two identical functions. --- src/script/lua_api/l_particles.cpp | 58 ++++++++++++-------------------------- 1 file changed, 18 insertions(+), 40 deletions(-) (limited to 'src/script') diff --git a/src/script/lua_api/l_particles.cpp b/src/script/lua_api/l_particles.cpp index d99d8f6a9..2532b2b08 100644 --- a/src/script/lua_api/l_particles.cpp +++ b/src/script/lua_api/l_particles.cpp @@ -96,14 +96,8 @@ int ModApiParticles::l_add_particle(lua_State *L) 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; } @@ -195,30 +189,18 @@ int ModApiParticles::l_add_particlespawner(lua_State *L) 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; } @@ -228,16 +210,12 @@ int ModApiParticles::l_delete_particlespawner(lua_State *L) { // 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; } -- cgit v1.2.3