Game Development Community

AIPlayer setInventory causes crash - RESOLVED

by J · in Torque 3D Professional · 05/24/2010 (9:25 am) · 5 replies

*T3D 1.1 Beta 1

I'm helping with a top-down shooter and I'm having wierd problems using setInventory on the AIPlayer.

In my AIPlayer.cs I have the usual setup:
%player.setInventory(Rifle, 1);
    %player.setInventory(RifleAmmo, 20); //comment out this line to prevent crash
    %player.mountImage(RifleImage, 0);
If I comment out %player.setInventory(RifleAmmo, 20);, then my mission loads, I can tilde, and setinventory on the AIPlayer, but he still won't shoot. If I don't comment out the setInventory, then my mission crashes when loading. I've tried this with the rocketLauncher, an assaultRifle and a the gravity gun off of the physX demo, multiple Player datablocks; all with the same result. I haven't changed weapon.cs or anything. Created a new project but with same result. Anyone else ran into this?

EDIT 1: I did notice on Alpha that in your player.cs, maxInv[RocketLauncher] = 1; was followed by a invRocketLaucher = 1; but this doesn't seem to make a difference.

EDIT 2: Maybe a namespace issue, as my RifleImage is based off of my AssaultRifleImage; created in the editor.

I can mount my player with the RifleImage, setInventory doesn't work in script; I have to tilde, then setInventory for the ammo to get my player to fire. (Doesn't do this for assaultRifle or rocketLauncher)

If I change my spawnObject to spawn an AIPlayer instead of a Player, then again, it crashes on mission load.

About the author

I used to be obsessed with building my own open-ended RPG and a 3D Side Scroller RPG. But the job/house/girlfriend got in the way. I know, I know. Now I concentrate on doing architectural renderings (with the help of T3D of course) and VBA programming.


#1
05/24/2010 (11:31 am)
(art)Aiplayer.cs should inherit everything from (art)player.cs, so if it can equip with it, it should. So, just to check you do have maxInv set for both weapon and ammo? And you have the (art)Rifle.cs fully functioning and exec'd with it's item data set for both it's ammo and weaponimage? And if you've based it on another weapon.cs you have replaced all the names and not left "assaultrifle" where you should have "rifle"?
#2
05/24/2010 (12:16 pm)
I have it all setup correctly. I'm 99.9999% sure anyways, lol, there could be that one little item/character/thingy that might be eluding me, but, the rocketLauncher has never been changed from stock and it does the same thing.
I've recreated the Rifle.cs. Once using a whole new, independant Rifle.cs made from the rocketLauncher, and the other two times using the Rifle : AssaultRifle method; just changing the namespace on the ammo/projectile/items. I get it working on the player every time, just not on an AIPlayer. It seems very odd to me, but I sure can't figure it out.
#3
05/25/2010 (12:39 pm)
Alright, I've figured it out if anyone runs into the same problem...

It had nothing to do with the weaponImages, nor the inventory.

I had a function that moved the AIPlayer out of the player's view when spawned. Well, this was using a getRandom and placing the random number into the vectorAdd method with a "@". (as I seen on some resource, can't find it). You need a "SPC" in order for it to work.

Now why commenting out the setInventory method allowed the function to pass? I don't have a clue!

Another problem though... If you spawn the DefaultPlayerData as an AIPlayer, then the mission doesn't load a player and a little error message pops up too quickly to be read.
That is a little annoying as I need the setMoveDestination functionallity for this game.

And ideas?
#4
05/28/2010 (1:10 pm)
bug logged Key: TQA-160
#5
09/02/2010 (3:29 pm)
This was fixed in 1.1 Beta 2. The ticket for it slipped through the cracks prior to it's release.