From 5f3cc5e2d5a430e02d6f7af4fc70c13b260f3bac Mon Sep 17 00:00:00 2001
From: jsalmon3 <>
Date: Sun, 17 Oct 2004 16:03:47 +0000
Subject: [PATCH] Error checking in GetThisPlayer

---
 src/stratagus/script_player.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/stratagus/script_player.cpp b/src/stratagus/script_player.cpp
index 5a1259264..aef7059bb 100644
--- a/src/stratagus/script_player.cpp
+++ b/src/stratagus/script_player.cpp
@@ -407,7 +407,11 @@ static int CclGetThisPlayer(lua_State* l)
 	if (lua_gettop(l) != 0) {
 		LuaError(l, "incorrect argument");
 	}
-	lua_pushnumber(l, ThisPlayer - Players);
+	if (ThisPlayer) {
+		lua_pushnumber(l, ThisPlayer - Players);
+	} else {
+		lua_pushnumber(l, 0);
+	}
 	return 1;
 }