Jump to content

How to create a proxy mine item?


Duion

Recommended Posts

I'm trying to create an item that can be picked up that adds ammo to the proxymine, but somehow it does not work, this is my Datablock:

 

datablock ItemData(ProxMineAmmo)
{
  // Mission editor category
  category = "Ammo";

  // Add the Ammo namespace as a parent.  The ammo namespace provides
  // common ammo related functions and hooks into the inventory system.
  className = "Ammo";

  // Basic Item properties
  shapeFile = "art/shapes/weapons/ProxMine/TP_ProxMine.DAE";
  mass = 1;
  elasticity = 0.2;
  friction = 0.6;

  // Dynamic properties defined by the scripts
  pickUpName = "Proxy Mine";
  maxInventory = 4;
};

 

I also added below:

 

   ammo = ProxMineAmmo;

 

The player datablock also has maxInventory = 4 allowed.


I can place the ammo-item, but I cannot pick it up, any ideas?

Link to comment
Share on other sites

Where to add? In the proxyMine itself it does not work. The other weapons are also "WeaponImage" and have separate ammo items.

For example the lurker:

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
  // provides some hooks into the inventory system.
  class = "WeaponImage";
  className = "WeaponImage";

  // Projectiles and Ammo.
  item = Lurker;
  ammo = LurkerAmmo;
  clip = LurkerClip;

Link to comment
Share on other sites

In the datablock editor I created a new ItemData and used LurkerGrenadeAmmo as the copied from values.


In the dynamic variables I changed pickupName to "a proximity mine" and it seemed to work.


Here's the managed datablock.

 

datablock ItemData(proxAmmo : LurkerGrenadeAmmo)
{
   elasticity = "0.198436";
   pickupName = "a proximity mine";
   shapeFile = "art/shapes/weapons/ProxMine/TP_ProxMine.cached.dts";
};
Link to comment
Share on other sites

I can't seem to figure out how to change it in code but if you place your scripted Ammo(ProxMineAmmo) into the scene then in the properties under Game change the dataBlock pulldown to ProxMine and it works but changing your script to:


datablock ItemData(ProxMineAmmo : ProxMine)


does not accomplish this.


I suppose you can just manually change each Ammo item once added or copy it.


Perhaps there is a way to change this in script?

Link to comment
Share on other sites

How does the code in the player datablock look like?

maxInv[ProxMineAmmo] = 4;

or

maxInvProxMineAmmo = "4";

The proximitymine class doesn't work with ammo. It only works with states (deployed, triggered, etc.), that's all. The proxmine as a weapon image is a method to get it into the inventory (it's more like a hack if you ask me). So if you would be able to pick up your new created item, you'd still need to modify the proximitymine class and add a ammo system. Another option would be to create a function ProxMineAmmo::onPickup to add a proximity mine to the inventory instead of the ammo.

Link to comment
Share on other sites

Okay, I used your code and made a file in datablocks called proxyMineAmmo.cs


Of course I opened datablockExec.cs and added:


exec("./proxyMineAmmo.cs");


Started up T3D.


Went to Library - Scripted -Ammo and added your item - ProxMineAmmo


Once it was in the scene I selected it and went into the properties.


Under Game - DataBlock: I changed it to ProxMine (see image below) and:


It works.


I'm just trying to figure out how to use that dataBlock in script, so far I can't.

Untitled-2.thumb.jpg.c31361d22049b0f78b09408185b6b489.jpg

Link to comment
Share on other sites

You can place it as a weapon, but then it blows up and kills you if you move close, but if you make an item and set it to use the same datablock that killed you before you can pick it up.

If you look at the code itself, the proxymine itself already seems to be set up as item that can be picked up, since it has pickup name, maxInventory etc: https://github.com/GarageGames/Torque3D/blob/development/Templates/Full/game/art/datablocks/weapons/ProxMine.cs#L44

But I would still like an option to define this in code, so that you don't have to change the datablock properties for each item, this can be confusing, for example people try to place it and don't know about it and then they complain, so best solution would be to have it in code.

Link to comment
Share on other sites

  • 2 weeks later...

Alright, I been thinking on this. The code below works to a certain extent. You can place the item and pick it up. It will increment the ProxMine by 1 if you do not have max amount. It plays the correct sound. The problem is that the item will disappear even when you have max amount of mines. Also I can't get the respawn to work. I will work on this more but I'm on the right track. Basically we have to rewrite Item code. If anyone else could look it over and give some input, that would be great.


 

datablock ItemData(ProxMineAmmo)
{
   // Mission editor category
   category = "Ammo";
 
   // Add the Ammo namespace as a parent.  The ammo namespace provides
   // common ammo related functions and hooks into the inventory system.
   className = "Weapon";
   item = ProxMine;
 
 
   // Basic Item properties
   shapeFile = "art/shapes/weapons/ProxMine/TP_ProxMine.cached.dts";
   mass = 1;
   elasticity = 0.2;
   friction = 0.6;
   count = 1;
   // Dynamic properties defined by the scripts
   pickUpName = "a proximity mine";
   maxInventory = 5;
 
 
 
};
 
function ProxMineAmmo::respawn(%this)
{
   // This method is used to respawn static ammo and weapon items
   // and is usually called when the item is picked up.
   // Instant fade...
   %this.startFade(0, 0, true);
   %this.setHidden(true);
 
   // Shedule a reapearance
   %this.schedule($Item::RespawnTime, "setHidden", false);
   %this.schedule($Item::RespawnTime + 100, "startFade", 1000, 0, false);
}
 
 
function ProxMineAmmo::onCollision(%this, %obj, %col)  
{  
   echo(%obj);
 
    if(%col.getClassName() $= "Player")  
    {  
       //%currentAmmo = %col.getFieldValue( ProxMine );
 
       if (%obj.getInventory( ProxMine) < ProxMine.maxInventory )
       {
        %obj.delete();
        serverPlay3D(AmmoPickupSound, %col.getTransform());  
       %col.incInventory(ProxMine, 1);
       %this.respawn();  
       }
    }  
}
Link to comment
Share on other sites

How about a workaround that automatically selects the correct datablock like you did on your first solution? I am using this at the moment, the only drawback is, that you have to know to set it to use the proxy mine datablock in the properties editor, could be confusing for people who do not know this and just want to place some items.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...