Added more scripting functions.

This commit is contained in:
Justin Marshall
2020-06-10 20:13:22 -07:00
parent 0b23dd5223
commit cc6c6092c7
4 changed files with 34 additions and 7 deletions
+26
View File
@@ -4,6 +4,30 @@
#include "FUNCTION.H"
#include "MapScript.h"
static int Script_GiveMoney(lua_State* L) {
int cashToGive = lua_tointeger(L, -1);
PlayerPtr->Refund_Money(cashToGive);
return 1;
}
static int Script_NumBuildingTypeForPlayer(lua_State* L) {
int houseType = lua_tointeger(L, 1);
int structType = lua_tointeger(L, 2);
int result = 0;
for (int b_index = 0; b_index < Buildings.Count(); b_index++) {
BuildingClass* building = Buildings.Ptr(b_index);
if (building->Owner() == houseType) {
if (building->Class->Type == structType) {
result++;
}
}
}
lua_pushnumber(L, result);
return 1;
}
static int Script_StartMissionTimer(lua_State* L) {
int ret = lua_tointeger(L, -1);
Scen.MissionTimer = Scen.MissionTimer + (ret * (TICKS_PER_MINUTE / 10));
@@ -63,6 +87,8 @@ bool MapScript::Init(const char* mapName) {
lua_register(L, "Speak", Script_Speak);
lua_register(L, "StartMissionTimer", Script_StartMissionTimer);
lua_register(L, "StopMissionTimer", Script_StopMissionTimer);
lua_register(L, "NumBuildingTypeForPlayer", Script_NumBuildingTypeForPlayer);
lua_register(L, "GiveMoney", Script_GiveMoney);
return true;
}