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 "scriptapi.h"
21 #include "scriptapi_particles.h"
24 #include "scriptapi_types.h"
25 #include "scriptapi_common.h"
27 // add_particle(pos, velocity, acceleration, expirationtime,
28 // size, collisiondetection, texture, player)
29 // pos/velocity/acceleration = {x=num, y=num, z=num}
30 // expirationtime = num (seconds)
32 // texture = e.g."default_wood.png"
33 int l_add_particle(lua_State *L)
35 // Get server from registry
36 Server *server = get_server(L);
38 v3f pos = check_v3f(L, 1);
39 v3f vel = check_v3f(L, 2);
40 v3f acc = check_v3f(L, 3);
41 float expirationtime = luaL_checknumber(L, 4);
42 float size = luaL_checknumber(L, 5);
43 bool collisiondetection = lua_toboolean(L, 6);
44 std::string texture = luaL_checkstring(L, 7);
46 if (lua_gettop(L) == 8) // only spawn for a single player
48 const char *playername = luaL_checkstring(L, 8);
49 server->spawnParticle(playername,
50 pos, vel, acc, expirationtime,
51 size, collisiondetection, texture);
53 else // spawn for all players
55 server->spawnParticleAll(pos, vel, acc,
56 expirationtime, size, collisiondetection, texture);
61 // add_particlespawner(amount, time,
65 // minexptime, maxexptime,
67 // collisiondetection,
70 // minpos/maxpos/minvel/maxvel/minacc/maxacc = {x=num, y=num, z=num}
71 // minexptime/maxexptime = num (seconds)
72 // minsize/maxsize = num
73 // collisiondetection = bool
74 // texture = e.g."default_wood.png"
75 int l_add_particlespawner(lua_State *L)
77 // Get server from registry
78 Server *server = get_server(L);
80 u16 amount = luaL_checknumber(L, 1);
81 float time = luaL_checknumber(L, 2);
82 v3f minpos = check_v3f(L, 3);
83 v3f maxpos = check_v3f(L, 4);
84 v3f minvel = check_v3f(L, 5);
85 v3f maxvel = check_v3f(L, 6);
86 v3f minacc = check_v3f(L, 7);
87 v3f maxacc = check_v3f(L, 8);
88 float minexptime = luaL_checknumber(L, 9);
89 float maxexptime = luaL_checknumber(L, 10);
90 float minsize = luaL_checknumber(L, 11);
91 float maxsize = luaL_checknumber(L, 12);
92 bool collisiondetection = lua_toboolean(L, 13);
93 std::string texture = luaL_checkstring(L, 14);
95 if (lua_gettop(L) == 15) // only spawn for a single player
97 const char *playername = luaL_checkstring(L, 15);
98 u32 id = server->addParticleSpawner(playername,
103 minexptime, maxexptime,
107 lua_pushnumber(L, id);
109 else // spawn for all players
111 u32 id = server->addParticleSpawnerAll( amount, time,
115 minexptime, maxexptime,
119 lua_pushnumber(L, id);
124 // delete_particlespawner(id, player)
125 // player (string) is optional
126 int l_delete_particlespawner(lua_State *L)
128 // Get server from registry
129 Server *server = get_server(L);
131 u32 id = luaL_checknumber(L, 1);
133 if (lua_gettop(L) == 2) // only delete for one player
135 const char *playername = luaL_checkstring(L, 2);
136 server->deleteParticleSpawner(playername, id);
138 else // delete for all players
140 server->deleteParticleSpawnerAll(id);