- exported one FraggleScript function for testing.

This commit is contained in:
Christoph Oelckers 2018-11-24 18:33:42 +01:00
parent 595208f2fd
commit 814af66864
2 changed files with 48 additions and 41 deletions

View file

@ -2588,50 +2588,11 @@ void FParser::SF_PlayerAmmo(void)
void FParser::SF_MaxPlayerAmmo()
{
int playernum, amount;
PClassActor * ammotype;
if (CheckArgs(2))
{
playernum=T_GetPlayerNum(t_argv[0]);
if (playernum==-1) return;
ammotype=T_GetAmmo(t_argv[1]);
if (!ammotype) return;
if(t_argc == 2)
{
}
else if(t_argc >= 3)
{
auto iammo = players[playernum].mo->FindInventory(ammotype);
amount = intvalue(t_argv[2]);
if(amount < 0) amount = 0;
if (!iammo)
{
players[playernum].mo->GiveAmmo(ammotype, 1);
iammo = players[playernum].mo->FindInventory(ammotype);
iammo->Amount = 0;
}
iammo->MaxAmount = amount;
for (AInventory *item = players[playernum].mo->Inventory; item != NULL; item = item->Inventory)
{
if (item->IsKindOf(NAME_BackpackItem))
{
if (t_argc>=4) amount = intvalue(t_argv[3]);
else amount*=2;
break;
}
}
iammo->IntVar("BackpackMaxAmount") = amount;
}
t_return.type = svt_int;
AInventory * iammo = players[playernum].mo->FindInventory(ammotype);
if (iammo) t_return.value.i = iammo->MaxAmount;
else t_return.value.i = ((AInventory*)GetDefaultByType(ammotype))->MaxAmount;
t_return.value.i = ScriptUtil::Exec("MaxPlayerAmmo", ScriptUtil::Pointer, T_GetPlayerActor(t_argv[0]), ScriptUtil::Class, T_ClassType(t_argv[1]),
ScriptUtil::Int, t_argc >= 3? intvalue(t_argv[2]) : INT_MIN, ScriptUtil::Int, t_argc >= 4 ? intvalue(t_argv[3]) : INT_MIN, ScriptUtil::End);
}
}

View file

@ -102,4 +102,50 @@ class ScriptUtil play
}
}
//==========================================================================
//
//
//
//==========================================================================
static int PlayerMaxAmmo(Actor activator, class<Actor> type, int newmaxamount = int.min, int newbpmaxamount = int.min)
{
if (activator == null) return 0;
let ammotype = (class<Ammo>)(type);
if (ammotype == null) return 0;
if (newmaxamount != int.min)
{
let iammo = Ammo(activator.FindInventory(ammotype));
if(newmaxamount < 0) newmaxamount = 0;
if (!iammo)
{
activator.GiveAmmo(ammotype, 1);
iammo = Ammo(activator.FindInventory(ammotype));
if (iammo)
iammo.Amount = 0;
}
for (Inventory item = activator.Inv; item != NULL; item = item.Inv)
{
if (item is 'BackpackItem')
{
if (newbpmaxamount == int.min) newbpmaxamount = newmaxamount * 2;
break;
}
}
if (iammo)
{
iammo.MaxAmount = newmaxamount;
iammo.BackpackMaxAmount = newbpmaxamount;
}
}
let rammo = activator.FindInventory(ammotype);
if (rammo) return rammo.maxamount;
else return GetDefaultByType(ammotype).MaxAmount;
}
}