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 "lua_api/l_particles.h"
21 #include "lua_api/l_internal.h"
22 #include "common/c_converter.h"
25 // add_particle(pos, velocity, acceleration, expirationtime,
26 // size, collisiondetection, texture, player)
27 // pos/velocity/acceleration = {x=num, y=num, z=num}
28 // expirationtime = num (seconds)
30 // texture = e.g."default_wood.png"
31 int ModApiParticles::l_add_particle(lua_State *L)
34 v3f pos = check_v3f(L, 1);
35 v3f vel = check_v3f(L, 2);
36 v3f acc = check_v3f(L, 3);
37 float expirationtime = luaL_checknumber(L, 4);
38 float size = luaL_checknumber(L, 5);
39 bool collisiondetection = lua_toboolean(L, 6);
40 std::string texture = luaL_checkstring(L, 7);
42 if (lua_gettop(L) == 8) // only spawn for a single player
44 const char *playername = luaL_checkstring(L, 8);
45 getServer(L)->spawnParticle(playername,
46 pos, vel, acc, expirationtime,
47 size, collisiondetection, texture);
49 else // spawn for all players
51 getServer(L)->spawnParticleAll(pos, vel, acc,
52 expirationtime, size, collisiondetection, texture);
57 // add_particlespawner(amount, time,
61 // minexptime, maxexptime,
63 // collisiondetection,
66 // minpos/maxpos/minvel/maxvel/minacc/maxacc = {x=num, y=num, z=num}
67 // minexptime/maxexptime = num (seconds)
68 // minsize/maxsize = num
69 // collisiondetection = bool
70 // texture = e.g."default_wood.png"
71 int ModApiParticles::l_add_particlespawner(lua_State *L)
74 u16 amount = luaL_checknumber(L, 1);
75 float time = luaL_checknumber(L, 2);
76 v3f minpos = check_v3f(L, 3);
77 v3f maxpos = check_v3f(L, 4);
78 v3f minvel = check_v3f(L, 5);
79 v3f maxvel = check_v3f(L, 6);
80 v3f minacc = check_v3f(L, 7);
81 v3f maxacc = check_v3f(L, 8);
82 float minexptime = luaL_checknumber(L, 9);
83 float maxexptime = luaL_checknumber(L, 10);
84 float minsize = luaL_checknumber(L, 11);
85 float maxsize = luaL_checknumber(L, 12);
86 bool collisiondetection = lua_toboolean(L, 13);
87 std::string texture = luaL_checkstring(L, 14);
89 if (lua_gettop(L) == 15) // only spawn for a single player
91 const char *playername = luaL_checkstring(L, 15);
92 u32 id = getServer(L)->addParticleSpawner(playername,
97 minexptime, maxexptime,
101 lua_pushnumber(L, id);
103 else // spawn for all players
105 u32 id = getServer(L)->addParticleSpawnerAll( amount, time,
109 minexptime, maxexptime,
113 lua_pushnumber(L, id);
118 // delete_particlespawner(id, player)
119 // player (string) is optional
120 int ModApiParticles::l_delete_particlespawner(lua_State *L)
123 u32 id = luaL_checknumber(L, 1);
125 if (lua_gettop(L) == 2) // only delete for one player
127 const char *playername = luaL_checkstring(L, 2);
128 getServer(L)->deleteParticleSpawner(playername, id);
130 else // delete for all players
132 getServer(L)->deleteParticleSpawnerAll(id);
137 void ModApiParticles::Initialize(lua_State *L, int top)
139 API_FCT(add_particle);
140 API_FCT(add_particlespawner);
141 API_FCT(delete_particlespawner);