Capturing Bases
by Adam Gardner · 03/30/2012 (12:12 am) · 1 comments
OK so my name is Adam, and I have been programming in vc++ 2005-2010 for about 4-5 years but just recently bought torque. So I was going to join a team here to start a portfolio for my future game design job, and well see they gave me a kind of "test" project to work on to show them what I can do and decided to share with you guys.
Information wise this product is not even near flawless at the moment as it only works for single-player and a 1 Time capture during game play and doesn't work with teams.
So here is how it works before we get to the coding part of this.
----------------------
Capture Bases.
Basically what this does is if you enter the trigger area it will allow you to press the certain button right now it is "C" For Capture =), and if your not in the area then it wont do anything at all. When you are in the trigger area and you press and hold C down ( This took forever since torque script only knows when you press the key down and release not in between so I found a work around using schedule();) It will then make a progress-bar Appear on your screen using the .setVisible(true/false) statements and as long as your in the area otherwise known as the trigger (Good for making sure people are in range for just about any thing.) if you release the "C" button or leave the trigger area it will restart back at 0 which means you have to capure it from the start.
This will also hide the progress bar so that the only time its actually visible is if your in the range of the base and holding C otherwise it will not be visible, That's pretty much all of it.
Ok now that you know what it does lets dig into implementing it into YOUR game!
--------------------
OK now go to your Game/scripts/server and Create a new script call it what ever you want, now copy and past this into that new script you created,
I left a ton of comments in this code because I LOVE to comment things for my short-term memory loss so I wont forget what Ideas I have come up with.
This was coded from scratch and all into "1" script no source edit or any thing.
You can do a TON of things with this code even though it looks pretty simple here is some ideas,
Capture the flag, Hack a computer as a mission, Use it for a timed Teleporter, and a lot more!
TODO:
I have a lot to add to this, I was wanting to work on making it more easy to add more then one base and have a less impact on the game with extra coding, that Is why I added the Base to a array.
Any ways hope you guys learn something from this any comments are welcome!
Information wise this product is not even near flawless at the moment as it only works for single-player and a 1 Time capture during game play and doesn't work with teams.
So here is how it works before we get to the coding part of this.
----------------------
Capture Bases.
Basically what this does is if you enter the trigger area it will allow you to press the certain button right now it is "C" For Capture =), and if your not in the area then it wont do anything at all. When you are in the trigger area and you press and hold C down ( This took forever since torque script only knows when you press the key down and release not in between so I found a work around using schedule();) It will then make a progress-bar Appear on your screen using the .setVisible(true/false) statements and as long as your in the area otherwise known as the trigger (Good for making sure people are in range for just about any thing.) if you release the "C" button or leave the trigger area it will restart back at 0 which means you have to capure it from the start.
This will also hide the progress bar so that the only time its actually visible is if your in the range of the base and holding C otherwise it will not be visible, That's pretty much all of it.
Ok now that you know what it does lets dig into implementing it into YOUR game!
--------------------
OK now go to your Game/scripts/server and Create a new script call it what ever you want, now copy and past this into that new script you created,
$Base[0] = false;//base 1 can be any base just used as a referance on adding multiple bases in arrays.
$Base[1] = false;//base 2 same as base 1
$i = 0;
$Basecaptime[0] = 0;
//possibly allow this function to be more dynamic on allowing it to capture new bases if added into the game just
//by calling this certain function Might have to create different functions but in my opinion would be a bit too much
//todo
//might have thought adding a paremiter into the function will allow dynamic access if so
function Void_BaseEnter($i)
{
echo("capping Base Trigger");
//do a range check
//possibly if we want can do a team check here too
//call the gui to show for the progressbar timer to start
//Todo Code range check
BaseCaptureBar.setVisible(true);
%Basegetseconds = BaseCaptureBar.getValue();
if($Base[$i] == false)
{
if($Basecaptime[$i] >=1)
{
capturebaseMines(0);
}
else
{
BaseCaptureBar.setValue($Basecaptime[$i]);
//.setValue("LOADING DATABLOCKS");
$Basecaptime[$i] += .10;
}
}
else
{
}
}
function Void_BaseLeave($i)
{
echo("Left Base 1 Trigger");
BaseCaptureBar.setVisible(false);
BaseCaptureBar.setValue(0);
$Basecaptime[$i] = 0;
}
function moveUp(%val)
{
if(%val)
{
$keyPress = %val;
schedule(1000, 0, sendItUp); // 1000 = 1 sec
}
else
$keyPress = 0; // key released, stop calling function
BaseCaptureBar.setVisible(false);
BaseCaptureBar.setValue(0);
$Basecaptime[$i] = 0;
}
function sendItUp($i)
{
if($keyPress)
{
if ($Base[$i] == false){
Void_BaseEnter();
schedule(1000, 0, sendItUp); // call until %val = 0
}
else
{
BaseCaptureBar.setVisible(false);
BaseCaptureBar.setValue(0);
$Basecaptime[$i] = 0;
}
}
}
function Base::onEnterTrigger( %this, %trigger, %obj) {
//Void_BaseEnter(0);
%player = %client.playerName;
echo(%player, " Entered Base Trigger");
}
function Base::onLeaveTrigger( %this, %trigger, %obj) {
Void_BaseLeave(0);
}
function Base::onTickTrigger(%this,%trigger) {
moveMap.bind(keyboard, "c", moveUp);
}
function capturebaseMines($i) { //capturing function // not sure how well this will work in torque script but worth a shot
//todo code for capturing the base
//Will start the base capping if the base is not already capped If base is not capped then will use this if
//statement and will turn to true
if ($Base[$i] == false) { $Base[$i] = true; }
//if base wasnt already capped then this will check if it is now true and begin the capping process!
if ($Base[$i]){
//start capping process
// Probably do a Check function to check what team the player is on
// Then to do a distance check to see if the player is in range
// If the player is in range then start a timer of some sort for capping
//in other words just call the function above Rangecheck to check range from base and if player is close enough
//then return true
BaseCaptureBar.setVisible(false);
//todo might add a check if the player leaves the area then restart timer
// if the timer reaches 10 seconds then fully capture the base.
echo("Base Captured");
}
}I left a ton of comments in this code because I LOVE to comment things for my short-term memory loss so I wont forget what Ideas I have come up with.
This was coded from scratch and all into "1" script no source edit or any thing.
You can do a TON of things with this code even though it looks pretty simple here is some ideas,
Capture the flag, Hack a computer as a mission, Use it for a timed Teleporter, and a lot more!
TODO:
I have a lot to add to this, I was wanting to work on making it more easy to add more then one base and have a less impact on the game with extra coding, that Is why I added the Base to a array.
Any ways hope you guys learn something from this any comments are welcome!

Torque 3D Owner JeffH