Increase score for blowing up things
by Jesse P · in General Discussion · 12/24/2007 (12:18 am) · 12 replies
Hey I've got my score display to work in my game for when I kill the AI bots but now what I want to do is have it add points for when I shoot my exploding barrels. I've got the barrels to explode when shot but I can't for the life of me figure out how to get it to add to my score. For the AI bad guys I was using the %sourceClient.incScore(1); somewhere in the player.cs but I don't have a clue how to get it to work in my exploding barrel script. Any suggestions? I'm not the best coder so please word things as simple as possible, thanks.
#2
I tried putting that in my explodingBarrel.cs that I made, but it doesn't do anything. hmm
For the AI bot I had put a %sourceClient.incScore(1); in the player.cs and it works for the bot, but I don't think it knows what the %sourceClient is for the barrel (just my theory I'm not much of a coder yet) but I don't know
12/24/2007 (12:01 pm)
Dang it's not working. That first line it doesn't complain about but it doesn't know what the rest of it is and my score doesn't update.I tried putting that in my explodingBarrel.cs that I made, but it doesn't do anything. hmm
For the AI bot I had put a %sourceClient.incScore(1); in the player.cs and it works for the bot, but I don't think it knows what the %sourceClient is for the barrel (just my theory I'm not much of a coder yet) but I don't know
#3
(This may also come in handy for anyone who needs an exploding barrel, they'll need to of course change the model, damageType, and the two explosion datablocks [you only need one explosion though], and I put this in a new explodingBarrel.cs and then added an exec for that script in the game.cs)
But I really want it to give me a score, see down at the bottom of the code where I was thinking of having the score
12/24/2007 (12:06 pm)
Here's my exploding barrel script that I pieced together from code I found around the forums, the exploding barrel works great but no score :((This may also come in handy for anyone who needs an exploding barrel, they'll need to of course change the model, damageType, and the two explosion datablocks [you only need one explosion though], and I put this in a new explodingBarrel.cs and then added an exec for that script in the game.cs)
But I really want it to give me a score, see down at the bottom of the code where I was thinking of having the score
datablock StaticShapeData(ExplodingBarrel)
{
category = "Misc";
shapeFile = "~/data/shapes/explosionshapes/barrel.dts";
damageRadius = 10;
radiusDamage = 50;
damageType = TargetMinorDebris;
damageImpulse = 2000;
maxDamage = 10;
};
function ExplodingBarrel::Damage(%data,%obj,%sourceObject,%pos,%damage,%damagetype)
{
%obj.applyDamage(%damage);
if(%obj.getDamageLevel() >= %obj.maxDamage)
{
blowup(%obj,%pos);
}
}
function blowup(%obj,%pos)
{
%source = %obj.getDataBlock();
if(%obj.exploded)
return;
%obj.exploded = true;
%p = new Explosion()
{
datablock = TargetMinorExplosion;
position = %pos;
sourceObject = %obj.sourceObject;
sourceSlot = %obj.sourceSlot;
client = %obj.client;
};
%p = new Explosion()
{
datablock = MolotovExplosion;
position = %pos;
sourceObject = %obj.sourceObject;
sourceSlot = %obj.sourceSlot;
client = %obj.client;
};
MissionCleanup.add(%p);
radiusDamage(%obj,%pos,%source.damageRadius,
%source.radiusDamage,%source.damageType,%source.damageImpulse);
alxPlay(explosion);
%sourceClient.incScore(100); // This line doesn't work though
echo("foo");
%obj.schedule(99, "delete");
}
#4
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11144
which was based off of the ammo display system here:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1786
12/24/2007 (12:48 pm)
And for my scoring system I used this:http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11144
which was based off of the ammo display system here:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1786
#7
12/24/2007 (6:27 pm)
Put the points in your onDamage player.cs make the arrow worth points.
#8
12/24/2007 (6:46 pm)
What do you mean the arrow? Do you mean the barrel? What would an example look like of the code that I would put in the onDamage? Thanks
#9
Tom is right. You can do it by using incScore(). But instead %player.incScore(100), you have to use %client.incScore(100). And probably you will have a variable to save that inside each %client. If you see
the function
COLYD
Color Your Dream
12/24/2007 (7:22 pm)
@Jesse,Tom is right. You can do it by using incScore(). But instead %player.incScore(100), you have to use %client.incScore(100). And probably you will have a variable to save that inside each %client. If you see
the function
function GameConnection::onConnect( %client, %name )you'll know what I mean.
COLYD
Color Your Dream
#10
It worked when I put it for the AI bad guy in player.cs but not for my barrel in my explodingBarrel.cs
Not to sure what variable I need to add or how to make it to work
12/24/2007 (8:47 pm)
Hmm, tried %client.incScore(100); and %clientSource.incScore(100); but both say can't find incScoreIt worked when I put it for the AI bad guy in player.cs but not for my barrel in my explodingBarrel.cs
Not to sure what variable I need to add or how to make it to work
#11
In your blowup(%obj,%pos) function, %obj is not a player object. That is a barrel. I wonder if you can
get sourceObject by %obj.sourceObject. If that works OK, the game connection %client will be sourceObject.client. But if it doesn't give you desired result, you will need to pass it as a parameter in blowup(), maybe something like this.
The point is to get appropriate game connection %client. If you don't you will get error message like you have.
Hope this may help
COLYD
Color Your Dream
12/25/2007 (2:18 am)
@JesseIn your blowup(%obj,%pos) function, %obj is not a player object. That is a barrel. I wonder if you can
get sourceObject by %obj.sourceObject. If that works OK, the game connection %client will be sourceObject.client. But if it doesn't give you desired result, you will need to pass it as a parameter in blowup(), maybe something like this.
function blowup(%obj,%sourceObject,%pos)Then, you can call incScore like this.
%sourceObject.client.incScore(100);
The point is to get appropriate game connection %client. If you don't you will get error message like you have.
Hope this may help
COLYD
Color Your Dream
#12
12/25/2007 (9:34 am)
Aha! The last suggestion about passing it as a parameter worked! Thanks COLYD!
Torque 3D Owner Tom Feni
$player::score += 25; scorecounter.setCounterValue($Player::score); // save the score saveGame();maybe its different for you but it is basically where you want to look..
since you dont want it scoring onDamage.. :)
TomFeni