LuaAPI sendstat finds correct clan colors by team names on siPlayerKills
authorPeriklis Ntanasis <pntanasis@gmail.com>
Thu, 06 Jun 2013 03:35:59 +0300
changeset 9173 575dd8fe4a55
parent 9172 72bfa6a3e8e2
child 9174 d328fe17b195
LuaAPI sendstat finds correct clan colors by team names on siPlayerKills
hedgewars/uScript.pas
--- a/hedgewars/uScript.pas	Tue Jun 04 00:10:48 2013 +0300
+++ b/hedgewars/uScript.pas	Thu Jun 06 03:35:59 2013 +0300
@@ -1288,15 +1288,37 @@
 
 function lc_sendstat(L : Plua_State) : LongInt; Cdecl;
 var statInfo : TStatInfoType;
+var i : LongInt;
 begin
+	//TODO print better error messages
 	statInfo := TStatInfoType(GetEnumValue(TypeInfo(TStatInfoType),lua_tostring(L, 1)));
-	if lua_gettop(L) <> 2 then
+	if (lua_gettop(L) <> 2) and (statInfo <> siPlayerKills) then
         begin
         LuaError('Lua: Wrong number of parameters passed to SendStat!');
         end
+    else if (lua_gettop(L) <> 3) and (statInfo = siPlayerKills) then
+		begin
+        LuaError('Lua: Wrong number of parameters passed to SendStat!');
+        end
     else
 		begin
-		SendStat(statInfo,lua_tostring(L, 2));
+		if(statInfo = siPlayerKills) then
+			begin
+			// 3: team name
+			for i:= 0 to Pred(TeamsCount) do
+				begin
+				with TeamsArray[i]^ do
+					begin
+					if TeamName = lua_tostring(L, 3) then
+						SendStat(siPlayerKills, uUtils.IntToStr(Clan^.Color) + ' ' +
+							lua_tostring(L, 2) + ' ' + TeamName);
+					end;
+				end;
+			end
+		else
+			begin
+			SendStat(statInfo,lua_tostring(L, 2));
+			end;
 		end;
     lc_sendstat:= 0
 end;