Page 1 of 1

MissionScript does not work (destroy inventory!)

PostPosted: Sat Jan 08, 11 7:56 pm
by DxPlayer
Hello!
I'm trying to make a mission script for Deranged mod that removes the player inventory items at the first game map (player receives Pistol, Prod and medkit), but it doesn't seen to be working!

Here is the code:
Code: Select all
class DerangedMissionScript expands MissionScript;

var DRHuman DRPlayer;

function FirstFrame()
{
   DRPlayer = DRHuman(GetPlayerPawn());
   
   Super.FirstFrame();
   
   if (localURL == "54_Deranged_Training")
      {
         DRPlayer.DRKillInventory();
      }
}


DRKillInventory function is at player class (DRHuman) and it is like this:

Code: Select all
function DRKillInventory()
{
local inventory anItem;

//Original from ResetPlayerToDefaults() in DeusExPlayer class!

while(Inventory != None)
   {
      anItem = Inventory;
      DeleteInventory(anItem);
      anItem.Destroy();
      if (DeusExRootWindow(rootWindow) != None)
      DeusExRootWindow(rootWindow).hud.belt.ClearBelt();
      GiveInitialInventory();
   }
}


Any ideas? :(

PostPosted: Sat Jan 08, 11 9:11 pm
by ~ô¿ô~Nobody~
The Inventory is a linked list of inventory items.

if you want to delete all items, you need to iterate though the whole list.. just like you do it with the pawnlist.
..means you need a loop

Code: Select all
local Inventory inv;
local Inventory anItem;

inv=Inventory;

while(inv != none)
{
anItem=inv;
inv=inv.Inventory;
DeleteInventory(anItem);
anItem.Destroy();
}

if (DeusExRootWindow(rootWindow) != None)
      DeusExRootWindow(rootWindow).hud.belt.ClearBelt();
     
GiveInitialInventory();



That should do the job..
THe order in the loop is like it is because you cannot get the next item if you destroy the current before.

The clear belt and GiveInitialInventory (if you want to use that) doesn't need to be in the loop

PostPosted: Sat Jan 08, 11 10:14 pm
by DxPlayer
Thanks man, But no success!

I don't know where do that Pistol, Prod and Medkit come from! ResetPlayer() at DeusExPlayer indeed give it to the Player, but only if a bool is set to true!

The line that leads the player (DRHuman) to the map is it:

Code: Select all
   Player.StartNewGame(DRGameInfo(Player.Level.Game).StartMap $ "?Class=" $ PlayerClasses[portraitIndex]);


But I don't get out is ResetPlayer(True) being activated somehow.

I think there are two possibilities:

-Code do not work and player got that inventory from dx.dx
-MissionScript.FirstFrame() is faster than whatelse is giving the player the inventory and deletes a nule inventory, wich is replaced by the unwanted one.

PostPosted: Mon Jan 10, 11 3:05 am
by DxPlayer
I got it working, thanks to Wccc:

First I forgot to start the timer at the Mission Script:
Code: Select all
function Timer()
{
   Super.Timer();
}


It initialized the script into the map, however I was still getting the inventory.

Then he recommended me changing == to ~= in level name check:

Code: Select all
if (localURL ~= "54_Deranged_Training")
      {
         DRPlayer.DRKillInventory();
      }


That made the script check the map's name not case sensitive, and so those lines were executed.

Suggested by Nobody and Wccc, I changed the DRKillInventory() function to this, however I am pretty sure the old one should work since I got the script working:

Code: Select all

function DRKillInventory()
{
   local inventory i;
//Suggested by Nobody and Wccc:

   forEach AllActors(class'inventory', i)
      {
         if (i.owner == self && i.class != class'DeusEx.NanoKeyRing')
         {
            i.Destroy();
         }
      }
}


Thx guys!