Add PlayMusicSound/StopMusicSound to Lua API
authorWuzzy <Wuzzy2@mail.ru>
Fri, 26 Oct 2018 04:07:35 +0200
changeset 13976 2828ec67c47c
parent 13975 350adfa0e896
child 13977 e340ce5500d7
Add PlayMusicSound/StopMusicSound to Lua API
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Fri Oct 26 03:59:20 2018 +0200
+++ b/ChangeLog.txt	Fri Oct 26 04:07:35 2018 +0200
@@ -157,6 +157,8 @@
  + New call: GetVampiric(): Returns true if vampirism is currently active
  + New call: GetLaserSight(): Returns true if laser sight (as utility) is currenctly active (ignoring sniper rifle)
  + New call: IsHogHidden(gear): Returns true if hog is hidden
+ + New call: PlayMusicSound(soundId): Play a sound as replacement for the main background music
+ + New call: StopMusicSound(soundId): Stop a “music sound” and resume the regular music
  + Changed call: AddTeam: 2nd param. color: Accepts negative value to use a default clan color from player settings
  + Changed call: HedgewarsScriptLoad: 2nd param. mustExist. If false, it's allowed for the script to not exist
  + Changed call: HedgewarsScriptLoad: Return true on success and false on failure
--- a/hedgewars/uScript.pas	Fri Oct 26 03:59:20 2018 +0200
+++ b/hedgewars/uScript.pas	Fri Oct 26 04:07:35 2018 +0200
@@ -2195,6 +2195,37 @@
     lc_playsound:= 0;
 end;
 
+function lc_playmusicsound(L : Plua_State) : LongInt; Cdecl;
+var s: LongInt;
+const
+    call = 'PlayMusicSound';
+    params = 'soundId';
+begin
+    if CheckLuaParamCount(L, 1, call, params) then
+        begin
+        s:= LuaToSoundOrd(L, 1, call, params);
+        if s >= 0 then
+            PlayMusicSound(TSound(s))
+        end;
+    lc_playmusicsound:= 0;
+end;
+
+function lc_stopmusicsound(L : Plua_State) : LongInt; Cdecl;
+var s: LongInt;
+const
+    call = 'StopMusicSound';
+    params = 'soundId';
+begin
+    if CheckLuaParamCount(L, 1, call, params) then
+        begin
+        s:= LuaToSoundOrd(L, 1, call, params);
+        if s >= 0 then
+            StopMusicSound(TSound(s))
+        end;
+    lc_stopmusicsound:= 0;
+end;
+
+
 function lc_setsoundmask(L : Plua_State) : LongInt; Cdecl;
 var s: LongInt;
     soundState: boolean;
@@ -4189,6 +4220,8 @@
 lua_register(luaState, _P'GetAmmo', @lc_getammo);
 lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
 lua_register(luaState, _P'PlaySound', @lc_playsound);
+lua_register(luaState, _P'PlayMusicSound', @lc_playmusicsound);
+lua_register(luaState, _P'StopMusicSound', @lc_stopmusicsound);
 lua_register(luaState, _P'SetSoundMask', @lc_setsoundmask);
 lua_register(luaState, _P'GetTeamName', @lc_getteamname);
 lua_register(luaState, _P'GetTeamIndex', @lc_getteamindex);