Lua API: PlaySound: Add 3rd parameter instaVoice to instantly play voice
authorWuzzy <Wuzzy2@mail.ru>
Thu, 08 Mar 2018 19:03:03 +0100
changeset 13122 d52d79f35558
parent 13121 de07c8423beb
child 13123 11f23afd84f2
Lua API: PlaySound: Add 3rd parameter instaVoice to instantly play voice
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Thu Mar 08 18:15:06 2018 +0100
+++ b/ChangeLog.txt	Thu Mar 08 19:03:03 2018 +0100
@@ -93,6 +93,7 @@
  + New call: HealHog(gearUid, healthBoost[, showMessage[, tint]]): Heal hedgehog with graphical effects and message
  + New call: SetTeamLabel(teamname[, label]): Set an arbitrary label for a team, will be displayed next to the team bar
  + New call: SetSoundMask(soundId, isMasked): Allows to disable playing a sound effect from engine
+ + New param: PlaySound accepts 3rd parameter for voices: instaVoice: If true, sound plays instantly instead of being queued
  + New callback: onEndTurn(): Called at the end of a turn (when gears have settled)
  + New hedgehog effect: heArtillery: Per-hedgehog artillery mode (can't walk). Values: 1 = permanently active. 2 = temporarily active (sniper rifle). 0 = not active
  * AddAmmo now automatically unselects weapon if it would remove current ammo from current hedgehog
--- a/hedgewars/uScript.pas	Thu Mar 08 18:15:06 2018 +0100
+++ b/hedgewars/uScript.pas	Thu Mar 08 19:03:03 2018 +0100
@@ -2048,11 +2048,12 @@
 function lc_playsound(L : Plua_State) : LongInt; Cdecl;
 var gear: PGear;
     n, s: LongInt;
+    instaVoice: boolean;
 const
     call = 'PlaySound';
-    params = 'soundId [, hhGearUid]';
+    params = 'soundId [, hhGearUid [, instaVoice]]';
 begin
-    if CheckAndFetchParamCount(L, 1, 2, call, params, n) then
+    if CheckAndFetchParamCountRange(L, 1, 3, call, params, n) then
         begin
         s:= LuaToSoundOrd(L, 1, call, params);
         if s >= 0 then
@@ -2064,7 +2065,15 @@
                 begin
                 gear:= GearByUID(Trunc(lua_tonumber(L, 2)));
                 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
-                    AddVoice(TSound(s), gear^.Hedgehog^.Team^.Voicepack, true)
+                    begin
+                    instaVoice:= false;
+                    if n = 3 then
+                        instaVoice:= lua_toboolean(L, 3);
+                    if instaVoice then
+                        PlaySoundV(TSound(s), gear^.Hedgehog^.Team^.Voicepack, false, true)
+                    else
+                        AddVoice(TSound(s), gear^.Hedgehog^.Team^.Voicepack, true);
+                    end;
                 end;
             end;
         end;