Site  •  Wiki  •  FAQ  •  Login

[EXAMPLE] Jetpack SCV in dangerous conditions

<<

BroodKiller

User avatar

Posts: 134

Joined: June 6th, 2009, 3:46 am

Post July 2nd, 2009, 3:52 pm

[EXAMPLE] Jetpack SCV in dangerous conditions

Hey, it's uncle Broody again with another sample plugin. This time please welcome a brave Jetpack SCV working in dangerous conditions. It is a normal SCV, but it works with radiated resources. Whenever it carries some valuable minerals to the Command Center, it puts it health at risk and looses some of it until it deposits them, or face a sad end. As a warning, his suit turns to black at the same time. To aid in this perilous endeavor he is equipped with jetpacks, that are ignited by the radiated minerals. They allow the SCV to cross over any obstacle on its way back to base. On succesful completion, his suit returns to its original colors and he's read for another mission :)

  Code:
UNIT* Jetscv;
for (int i=0;i<1700;i++) {
   Jetscv = &unitTable[i];
   if (Jetscv->unitId == 7 && Jetscv->healthPoints >= 256) {
      if (Jetscv->carryingResourceAmount > 0) {
         Jetscv->sprite->teamColor = 160;
         Jetscv->sprite->animationLevel = 16;
         if (Jetscv->healthPoints >= 256) {
            Jetscv->healthPoints = Jetscv->healthPoints - 16;
         }
         if (Jetscv->healthPoints < 256) {
            Jetscv->mainOrderId = Die;
         }
      }
      else {
         Jetscv->sprite->teamColor = Jetscv->playerId;
         Jetscv->sprite->animationLevel = 4;
         if (Jetscv->healthPoints < 256*60) {
            Jetscv->healthPoints = Jetscv->healthPoints + 16;
         }
      }
   }
}


Again, let's go through this code piece-by-piece.

  Code:
UNIT* Jetscv;
for (int i=0;i<1700;i++) {
   Jetscv = &unitTable[i];

As usual, we cycle through all the units in search of our brave worker.
  Code:
if (Jetscv->unitId == 7 && Jetscv->healthPoints >= 256) {

Once we find him, we also check if he is strong enough and not dying already.
  Code:
if (Jetscv->carryingResourceAmount > 0) {

Then we check if he's currently carrying anything valuable. In case he is...
  Code:
Jetscv->sprite->teamColor = 160;

...we change his colors to black...
  Code:
Jetscv->sprite->animationLevel = 16;

...and turn on his jetpack, placing him a few levels above the ground.
  Code:
if (Jetscv->healthPoints >= 256) {
   Jetscv->healthPoints = Jetscv->healthPoints - 16;
}

If he has any life left, it is slowly consumed by the radiation.
  Code:
if (Jetscv->healthPoints < 256) {
   Jetscv->mainOrderId = Die;
}

It he gets too much radiation, he has unfortunately to die.

In case he is not carrying anything anymore:
  Code:
else {
   Jetscv->sprite->teamColor = Jetscv->playerId;

We give him back his original suit....
  Code:
Jetscv->sprite->animationLevel = 4;

...turn off the jetpack, placing him back on the ground...
  Code:
if (Jetscv->healthPoints < 256*60) {
   Jetscv->healthPoints = Jetscv->healthPoints + 16;
}

...and regenerate his health, should he has less than his maximum.

Consult the other topic on how to create the plugin on your own, nothing has changed in this regard. To test simple run any map playing the Terran race :)

-Uncle Broody
Attachments
jetscv.zip
1.15.1-compatible
(191.82 KiB) Downloaded 287 times
Last edited by BroodKiller on July 5th, 2009, 4:24 am, edited 2 times in total.
Clean...simple...devious. I like it.
<<

TassadarZeratul

User avatar

Posts: 288

Joined: June 7th, 2009, 1:00 am

Location: Behind myself

Post July 2nd, 2009, 4:04 pm

Re: Plugin example: Jetpack SCV in dangerous conditions

Ah, that's how you make a unit fly via plugins. I've been wondering if that's possible. Thank you.
Image
<<

BroodKiller

User avatar

Posts: 134

Joined: June 6th, 2009, 3:46 am

Post July 2nd, 2009, 4:10 pm

Re: Plugin example: Jetpack SCV in dangerous conditions

An important note - it only works like this if the unit's movement is flingy-controlled, not iscript-controlled. You can manipulate this property through a plugin as well, though.
Clean...simple...devious. I like it.
<<

TassadarZeratul

User avatar

Posts: 288

Joined: June 7th, 2009, 1:00 am

Location: Behind myself

Post July 2nd, 2009, 4:39 pm

Re: Plugin example: Jetpack SCV in dangerous conditions

Can I have an example of changing iscript/flingy control via plugin?
Image
<<

BroodKiller

User avatar

Posts: 134

Joined: June 6th, 2009, 3:46 am

Post July 2nd, 2009, 11:53 pm

Re: Plugin example: Jetpack SCV in dangerous conditions

Using the unit->flingyMovementType property should do the trick, although I will not be by head on it. It may get trickier, since if you switch iscript->flingy you probably would have to set some other properties as well, like flingySpeed, flingyAcceleration and probably more.
Clean...simple...devious. I like it.
<<

bajadulce

Posts: 102

Joined: June 7th, 2009, 2:53 pm

Location: Santa Cruz, CA

Post July 3rd, 2009, 10:53 am

Re: Plugin example: Jetpack SCV in dangerous conditions

very nice.. and well documented! Really easy to follow understand. You are a well organized and well structured program coder. Quick question, what part of the code represents the timer, i.e the loop that deals damage. Not quite getting that part.
<<

TassadarZeratul

User avatar

Posts: 288

Joined: June 7th, 2009, 1:00 am

Location: Behind myself

Post July 3rd, 2009, 11:02 am

Re: Plugin example: Jetpack SCV in dangerous conditions

nextFrame() executes once every frame. It deals a fraction of HP of damage every frame. That's the timer.
Image
<<

BroodKiller

User avatar

Posts: 134

Joined: June 6th, 2009, 3:46 am

Post July 3rd, 2009, 3:25 pm

Re: Plugin example: Jetpack SCV in dangerous conditions

Thanks baja, I am happy to hear it, because I want these examples to be easy to grasp regardless of the technicalities. And TZ is correct, I am relying on the template's internal hook of nextFrame() as a measure of timing things. I obtain the proper result by carefully adjusting the amount of health that is subtracted. Sure, I could introduce an external timer, but I don't want to overcomplicate these first few examples. AofST has a custom timer implemented in his variation of the vampyric aura, IIRC, check the Vampire Firebat thread, if you want :)
Clean...simple...devious. I like it.
<<

Debardus

Posts: 45

Joined: June 8th, 2009, 5:35 am

Post July 5th, 2009, 6:23 am

Re: Plugin example: Jetpack SCV in dangerous conditions

Haha, fun little plugin. However, the scv continues to fly after it has dropped off its minerals until it is given a non-gather order! You can abuse this by telling your scv to mine a mineral patch across the map after he has dropped off his minerals and he will fly over :P

Return to Plugins

Who is online

Users browsing this forum: No registered users and 1 guest

cron
phpBBST Software