2012-08-04 10:54:37 +00:00
|
|
|
// sound lib for lua
|
|
|
|
|
|
|
|
#include "g_lua.h"
|
|
|
|
|
|
|
|
#ifdef G_LUA
|
|
|
|
|
2013-04-29 21:45:53 +00:00
|
|
|
/***
|
2013-05-09 17:40:15 +00:00
|
|
|
A documentation to play sounds.
|
2013-04-29 21:45:53 +00:00
|
|
|
@module sound
|
|
|
|
*/
|
|
|
|
|
2013-05-09 17:40:15 +00:00
|
|
|
/***
|
|
|
|
Play a sound on a given entity.
|
|
|
|
@function PlaySound
|
|
|
|
@param ent The entity the sound will be played on
|
|
|
|
@param sound The sound file which will be played
|
|
|
|
@param chan The sound channel the sound will be played on
|
|
|
|
*/
|
2012-08-04 10:54:37 +00:00
|
|
|
static int Sound_PlaySound(lua_State *L) {
|
|
|
|
char *sound;
|
|
|
|
int snd;
|
|
|
|
int chan;
|
|
|
|
lent_t *l;
|
|
|
|
|
|
|
|
l = Lua_GetEntity(L,1);
|
|
|
|
if(!l || !l->e) return 1;
|
|
|
|
|
|
|
|
sound = (char*)luaL_checkstring(L,2);
|
|
|
|
if(!sound[0]) return 1;
|
|
|
|
|
|
|
|
chan = luaL_checknumber(L,3);
|
|
|
|
|
|
|
|
snd = G_SoundIndex(sound);
|
|
|
|
G_AddEvent(l->e, EV_SCRIPT_SOUND, snd + (chan << 8));
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const luaL_Reg lib_sound[] = {
|
2013-05-08 23:59:07 +00:00
|
|
|
{ "PlaySound", Sound_PlaySound },
|
|
|
|
{ NULL, NULL }
|
2012-08-04 10:54:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int Luaopen_Sound(lua_State *L) {
|
|
|
|
luaL_register(L, "sound", lib_sound);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|