hedgewars/uScript.pas
changeset 14663 bc4296649bbf
parent 14662 7de65fa1f686
child 14666 9e7092e5990a
--- a/hedgewars/uScript.pas	Mon Jan 21 05:51:35 2019 +0100
+++ b/hedgewars/uScript.pas	Mon Jan 21 05:57:01 2019 +0100
@@ -1361,13 +1361,29 @@
     hht  : THedgehog;
     hhp  : PHedgehog;
     i, j : LongInt;
+    colorArg: Int64;
+    color: LongWord;
 begin
     if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then
         begin
         i:= Trunc(lua_tonumber(L,1));
         if i >= ClansCount then exit(0);
         clan := ClansArray[i];
-        clan^.Color:= Trunc(lua_tonumber(L, 2)) shr 8;
+        colorArg:= Trunc(lua_tonumber(L, 2));
+        if (colorArg < 0) and (abs(colorArg) <= cClanColors) then
+            // Pick clan color from settings (recommended)
+            color:= ClanColorArray[Pred(abs(colorArg))]
+        else if (colorArg >= 0) and (colorArg <= $ffffffff) then
+            // Specify color directly
+            color:= colorArg shr 8
+        else
+            begin
+            OutError('Lua error: SetClanColor: Invalid ''color'' argument, must be between '+IntToStr(-cClanColors)+' and 0xffffffff!', true);
+            lc_setclancolor:= 0;
+            exit;
+            end;
+
+        clan^.Color:= color;
 
         for i:= 0 to Pred(clan^.TeamsNumber) do
             begin