3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "cpp_api/scriptapi.h"
21 #include "common/c_converter.h"
22 #include "lua_api/l_base.h"
23 #include "lua_api/l_particles.h"
25 #include "common/c_internal.h"
27 bool ModApiParticles::Initialize(lua_State *L, int top) {
30 retval &= API_FCT(add_particle);
31 retval &= API_FCT(add_particlespawner);
32 retval &= API_FCT(delete_particlespawner);
37 // add_particle(pos, velocity, acceleration, expirationtime,
38 // size, collisiondetection, texture, player)
39 // pos/velocity/acceleration = {x=num, y=num, z=num}
40 // expirationtime = num (seconds)
42 // texture = e.g."default_wood.png"
43 int ModApiParticles::l_add_particle(lua_State *L)
46 v3f pos = check_v3f(L, 1);
47 v3f vel = check_v3f(L, 2);
48 v3f acc = check_v3f(L, 3);
49 float expirationtime = luaL_checknumber(L, 4);
50 float size = luaL_checknumber(L, 5);
51 bool collisiondetection = lua_toboolean(L, 6);
52 std::string texture = luaL_checkstring(L, 7);
54 if (lua_gettop(L) == 8) // only spawn for a single player
56 const char *playername = luaL_checkstring(L, 8);
57 getServer(L)->spawnParticle(playername,
58 pos, vel, acc, expirationtime,
59 size, collisiondetection, texture);
61 else // spawn for all players
63 getServer(L)->spawnParticleAll(pos, vel, acc,
64 expirationtime, size, collisiondetection, texture);
69 // add_particlespawner(amount, time,
73 // minexptime, maxexptime,
75 // collisiondetection,
78 // minpos/maxpos/minvel/maxvel/minacc/maxacc = {x=num, y=num, z=num}
79 // minexptime/maxexptime = num (seconds)
80 // minsize/maxsize = num
81 // collisiondetection = bool
82 // texture = e.g."default_wood.png"
83 int ModApiParticles::l_add_particlespawner(lua_State *L)
86 u16 amount = luaL_checknumber(L, 1);
87 float time = luaL_checknumber(L, 2);
88 v3f minpos = check_v3f(L, 3);
89 v3f maxpos = check_v3f(L, 4);
90 v3f minvel = check_v3f(L, 5);
91 v3f maxvel = check_v3f(L, 6);
92 v3f minacc = check_v3f(L, 7);
93 v3f maxacc = check_v3f(L, 8);
94 float minexptime = luaL_checknumber(L, 9);
95 float maxexptime = luaL_checknumber(L, 10);
96 float minsize = luaL_checknumber(L, 11);
97 float maxsize = luaL_checknumber(L, 12);
98 bool collisiondetection = lua_toboolean(L, 13);
99 std::string texture = luaL_checkstring(L, 14);
101 if (lua_gettop(L) == 15) // only spawn for a single player
103 const char *playername = luaL_checkstring(L, 15);
104 u32 id = getServer(L)->addParticleSpawner(playername,
109 minexptime, maxexptime,
113 lua_pushnumber(L, id);
115 else // spawn for all players
117 u32 id = getServer(L)->addParticleSpawnerAll( amount, time,
121 minexptime, maxexptime,
125 lua_pushnumber(L, id);
130 // delete_particlespawner(id, player)
131 // player (string) is optional
132 int ModApiParticles::l_delete_particlespawner(lua_State *L)
135 u32 id = luaL_checknumber(L, 1);
137 if (lua_gettop(L) == 2) // only delete for one player
139 const char *playername = luaL_checkstring(L, 2);
140 getServer(L)->deleteParticleSpawner(playername, id);
142 else // delete for all players
144 getServer(L)->deleteParticleSpawnerAll(id);
149 ModApiParticles modapiparticles_prototyp;