Game Development Community

Pickup Item While in Vehicle!

by Tom Feni · in General Discussion · 01/02/2005 (10:24 am) · 13 replies

Ok,
I have a script for picking up coins. When in player mode it picks up and scores the item. when I mount a vehicle it only picks up the coin..

this is all in script.. no engine changes.. :)

ok first in coins.cs
datablock ItemData(flowerCoin1)
{
   category = "Coins";
   shapeFile = "~/data/shapes/flowerIcon/flowerCoin.dts";
   item = flowerCoin1;
   
   mass = 55;
   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 6;
   pickUpName = "a Flower Coin";
   computeCRC = true;


   lightType = "PulsingLight";
   lightColor = "0.1 1.0 0.2 1.0";
   lightTime = "1000";
   lightRadius = "8";

   isInvincible = true;
   scoreValue = 25;// (or whatever score)

};

function flowerCoin1::onPickup(%this, %obj, %user, %amount)
{

   // The parent Item method performs the actual pickup.

     if (Parent::onPickup(%this, %obj, %user, %amount)) {
      serverPlay3D(CoinPickupSound,%obj.getTransform());

   }
}

function flowerCoin1::onCollision(%this,%obj,%col)
{
    if(%col.getDataBlock().className $= Armor)
      {
      %col.client.incScore(%this.scoreValue);
      %col.client.setScoreAmountHud(%col.client.score);
      messageClient(%col.client, 'MsgItemPickup', '\c1You got %1 points!!', %this.scoreValue);

      if (%col.client.score >= $Game::EndGameScore)
         cycleGame();

         return;
      }
}

now in car.cs
function Car::onCollision(%this,%obj,%col,%vec,%speed)
{
   // Collision with other objects, including items
   // need to set this up later
    if (%col.getClassName() $= "Item") {
   %obj.getMountNodeObject(0).pickup(%col);
   }
   if(%col.getDataBlock().className $= VehicleObjectType)
      {
       %col.getMountNodeObject(0).client.incScore(%this.scoreValue);
      //%col.getMountNodeObject(0).client.setScoreAmountHud(%col.client.score);
      %col.getMountNodeObject(0).client.setScoreAmountHud(%col.getMountedObject(0).client.score);

      }
    // Apply damage to the object all shape base objects
   if ( %speed >= 20 )
   {
      if (%col.getType() && $TypeMasks::ShapeBaseObjectType)
      %col.damage(%obj,%pos,( 3 * %speed ), "Car");
   }

}

now it will show up in the hud when I pickup the coin while in the vehicle but not show increase in score...

does anyone have any ideas on how to get the vehicle to track the coins the same as while in player mode..

in car
home.comcast.net/~theberk/car.jpg
player mode
home.comcast.net/~theberk/player.jpg
Any ideas?

#1
01/02/2005 (10:50 am)
Quote:
function flowerCoin1::onCollision(%this,%obj,%col)
{
if(%col.getDataBlock().className $= Armor)


In the bolded if check, you are limiting your pickup datablock to Armor, which is what the un-mounted player has as a datablock (assumption, you didn't actually show the function for it)

Since when the player is mounted in the car, the car is what collides with the coin. Therefore, the className check on %col is going to fail--it's not Armor, it would be Car.

Try either taking the check out entirely, or allowing collisions with Car classNames as well as Armor classNames, and see how that works.
#2
01/02/2005 (1:00 pm)
Hmm.. nothing seems to work..

guess with my limited scripting ability I am stuck with no vehicle pickups.. :)

oh well..
#3
01/02/2005 (2:36 pm)
How about posting your code for the car?
#4
01/02/2005 (3:06 pm)
Here is the link...

code to long for garagegames to handle I guess... :)

www.rafb.net/paste/results/QkUTDT58.html

this url will self destruct after 24 hours.. time is now 5 pm PST...
#5
01/02/2005 (3:37 pm)
Ok, wherever you are mounting the player to the car make sure you set the car's client to that player's client....

%car.client = %player.client;

And then do this....

function flowerCoin1::onCollision(%this,%obj,%col)
{
	if(%col.getDataBlock().className $= Armor || %col.getName() $= "Car")
	{
		%col.client.incScore(%this.scoreValue);
		%col.client.setScoreAmountHud(%col.client.score);
		messageClient(%col.client, 'MsgItemPickup', '\c1You got %1 points!!', %this.scoreValue);

		if(%col.client.score >= $Game::EndGameScore){ cycleGame(); }
	}
}


That should take care of it
#6
01/02/2005 (4:13 pm)
The %car.client = %player.client; should go in the onmount function?

I tried that and it still isnt working well...
so.....
:)

back to the drawing board..
#7
01/02/2005 (7:46 pm)
Player collisiion

function Armor::onCollision(%this, %obj, %col)
{
   if(%obj.getState() $= "Dead"){return;}

   if(%col.getClassName() $= "Item"){%obj.pickup(%col); return;}

   if(%obj.mountVehicle && %col.mountable)
   {
         %col.mountObject(%obj, 0);
   }
}
#8
01/02/2005 (10:58 pm)
You tried it like this?


function Armor::onCollision(%this, %obj, %col)
{
   if(%obj.getState() $= "Dead"){return;}

   if(%col.getClassName() $= "Item"){%obj.pickup(%col); return;}

   if(%obj.mountVehicle && %col.mountable)
   {
         %col.client = %obj.client;
         %col.mountObject(%obj, 0);
   }
}
#9
01/03/2005 (1:58 am)
Well now it will tell me what I picked up and now I can use the jump pads in the vehicle.. (?)

now to get it to score.. :)
#10
01/03/2005 (2:15 am)
In your flowerCoin1::onCollision:

try changing:

if(%col.getDataBlock().className $= Armor || %col.getName() $= "Car") {

to

if(%col.getDataBlock().getName() $= "Armor" || %col.getDataBlock().getDataBlock().getName() $= "Car") {
#11
01/03/2005 (12:04 pm)
Well I deleted the coin collision.. and move dit into item.cs...
function ItemData::onPickup(%this,%obj,%user,%amount)
{
   // Add it to the inventory, this currently ignores the request
   // amount, you get what you get.  If the object doesn't have
   // a count or the datablock doesn't have maxIventory set, the
   // object cannot be picked up.
   %count = %obj.count;
   if (%count $= "")
      if (%this.maxInventory !$= "") {
         if (!(%count = %this.maxInventory))
            return;
      }
      else
         %count = 1;
   %user.incInventory(%this,%count);

   // Inform the client what they got.
    if (%user.client)
       %user.client.incScore(%this.scoreValue);
       echo("score");
       %user.client.setScoreAmountHud(%client.score);
       messageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1', %this.pickupName);

   // If the item is a static respawn item, then go ahead and
   // respawn it, otherwise remove it from the world.
   // Anything not taken up by inventory is lost.
   if (%obj.isStatic())
      %obj.respawn();
   else
      %obj.delete();
   return true;
}

but now it double the points.. when in player mode.. in the vehicle it will pick up the coin, score, but it blanks out my score board... hitting f2 shows the true score, but if your in the vehicle the game wont end if you get to 500...

so not sure if this will work or not..

odd and odder..
#12
01/03/2005 (12:34 pm)
Ok figured out I had changed the cs file to a new name.. Doh! so all my changes were not even going into effect..
So I changed it somewhat and now the player cannot score but the car can.. lol

man weird...
#13
01/03/2005 (12:48 pm)
Ok fixed it
woohoo!

function waterCan3::onCollision(%this,%obj,%col)
{
   if(%col.getType() & ($TypeMasks::VehicleObjectType | $TypeMasks::PlayerObjectType))

      {
      
       %col.client.incScore(%this.scoreValue);
       %col.client.setScoreAmountHud(%col.client.score);

      messageClient(%col.client, 'MsgItemPickup', '\c1You got %1 points!!', %this.scoreValue);


      if (%col.client.score >= $Game::EndGameScore)
         cycleGame();

         return;
      }
      else if (%col.getDataBlock().getName() $= "Car")
    {
      %client = %col.getMountNodeObject(0).client;
      %client.incScore(%this.scoreValue);
      %client.setScoreAmountHud(%col.client.score);
      messageClient(%client, 'MsgItemPickup', '\c1You got %1 points!!', %this.scoreValue);

      if (%client.score >= $Game::EndGameScore)
         cycleGame();

         return;
    }
}

yay!