Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Help with my Heal Cog
Help with my Heal Cog
2001-12-12, 5:52 AM #1
Basically, I've been editing SBX 2.0 for personal uses in my office. Apologies and all, but I need to get back in touch with programming and stuff.

Anyway, what I've been trying to do with force_heal.cog is have it so that a do{}while() loop runs and keeps healing the player a little bit while the mana is greater than the cost.

The loop looks something like this:
do
{
HEALING STUFF
}
while(mana > cost);

A problem I always had in class was certain syntaxes would be incorrect, I'd miss a semi-colon or something. Is there ANYTHING you can see that is wrong with this:

if(GetThingHealth(player) < 100)
{
mana = GetInv(player, 14);
{
if(GetInv(player, 65) != 1)-->
ChangeInv(player, 14, -cost);
SetInvActivated(player, 25, 1);
PlayMode(player, 24);
soundChannel = PlaySoundThing(healingSound, player, 1.0, -1, -1, 0x80);
rank = GetInv(player, 25);
position = VectorAdd(GetThingPos(player), '0.0 0.0 0.01');
sphere = CreateThingAtPosNR(sphere_tpl, GetThingSector(player), position, '0.0 0.0 0.0');
AttachThingToThingEx(sphere, player, 0x8);
Sleep(0.6);
SetParticleGrowthSpeed(sphere, -3.0)
do
{
if(GetThingHealth(player) > 0)
{
HealThing(player, 1 * rank);
//jkPrintUNIString(player, 303);
}
Sleep(0.40);
DestroyThing(sphere);
mana=mana-cost;
}
while(mana > cost);

}

I know, no word wrap and stuff, but I hope you get the gist.

Seth
BLEAH

AIM:SethTAlbright
2001-12-12, 5:59 AM #2
I dont see a reason to do it like that. The simplest way would be to run a high pulse, checking evry time to see if there is enough mana, and if so, healing the player.

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2001-12-12, 6:01 AM #3
you see, my knowledge of programming is limited to beginning c++, like HS level, so a lot of this stuff is not known to me, how do I make a high pulse like that, give me an example.

Seth

------------------
BLEAH

AIM:SethTAlbright
BLEAH

AIM:SethTAlbright
2001-12-12, 6:53 AM #4
see, the problem is that the code I submitted in the above message doesn't work. I get this message:

=expected, { found
Variable, function, or keyword expected, but ; found
unexpected }
BLEAH

AIM:SethTAlbright
2001-12-12, 8:35 AM #5
[edit]Scratch what I said about the do..while loop. It does work.

2) What's with the "-->"? Cog doesn't use that.

You should put your code in code tags so it's readable.

------------------
Incognito

[This message has been edited by SaberMaster (edited December 13, 2001).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-12-12, 8:41 AM #6
I got the Do While to work, to a point. It won't take mana away other than the initial casting cost, so in actuality, it replenishes all your health gradually for like 20 mana. ARGH.


------------------
BLEAH

AIM:SethTAlbright
BLEAH

AIM:SethTAlbright
2001-12-12, 8:48 AM #7
To set up a pulse:

Add 'Message Pulse' to your symbols section.

Add 'Setpulse(0.1);' to start the pulse.

'Pulse:' starts the pulse code. Add your conditional statements and heal code here.


'Setpulse(0);' will stop the pulse.

 

Essentially, that will create a re-uccuring message, that will trigger evry 0.1 seconds.

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2001-12-12, 8:55 AM #8
okay, Now I see how that works, and that might be better than the Do While, but I need a way to take mana away each time it does it, because right now it runs, but only takes mana away once.

------------------
BLEAH

AIM:SethTAlbright
BLEAH

AIM:SethTAlbright
2001-12-12, 11:54 AM #9
In the pulse put ChangeInv(player, 14, #); where # is like -5.

------------------
-Hell Raiser
Cogging type person that does, umm, stuff.
"Free, your, mind."
-Hell Raiser
2001-12-12, 12:00 PM #10
Thank you very much!
BLEAH

AIM:SethTAlbright
2001-12-12, 12:23 PM #11
Okay, that worked...partly. I can't seem to get the SetPulse to work, so I returned to my good ol' DoWhile. Here is what it looks like, and then I'll tell you the problem:

do
{

if((GetThingHealth(player) > 0) && (mana > cost))
{
HealThing(player, 1 * rank);
ChangeInv(player, 14, -25);
//jkPrintUNIString(player, 303);
}
Sleep(1.0);

}
while((mana > 0) || (GetThingHealth(player)!=100));


The problem is, yeah, it takes the mana, and yeah, it refills until health is full, but it doesn't STOP. Health can be at 100, and it will still be active. Mana can be at 0, and whatever mana gets recharged gets taken away. ARGH!



------------------
BLEAH

AIM:SethTAlbright
BLEAH

AIM:SethTAlbright
2001-12-12, 5:18 PM #12
Change:

while((mana > 0) || (GetThingHealth(player)!=100));

to

while((mana > 0) && (GetThingHealth(player)!=100));

You need to use && to make it work because, well, if your health is 100, it would still run cuz mana > 0. Also the other way around. If mana was 0, but your health was not 100, it would still run.

------------------
-Hell Raiser
Cogging type person that does, umm, stuff.
"Free, your, mind."

[This message has been edited by Hell Raiser (edited December 12, 2001).]
-Hell Raiser
2001-12-13, 3:52 AM #13
Okay, new problem, well not quite.
The power never de-activates. It keeps running and running, sapping out force power and not refilling life. How would I work the SetPulse, since my DoWhile seems to be doing absolutely nothing. Here's the code though, if you can see anything wrong with it.

do
{

if((GetThingHealth(player) > 0) && (mana > cost))
{
HealThing(player, 1 * rank);
ChangeInv(player, 14, -25);
//jkPrintUNIString(player, 303);
}
Sleep(1.0);

}
while((mana > 0 && mana != 0) && (health != 100));
call stop_power;
return;
Those &&'s at the bottom used to be ||'s, but it didn't change anything.

------------------
BLEAH

AIM:SethTAlbright
BLEAH

AIM:SethTAlbright
2001-12-13, 8:34 AM #14
I'm not a C++ expert, but I do see this problem, which proably isn't you're current problem:

Quote:
HealThing(player, 1 * rank);[/qupte]

What's the 1 * for? What is 1 * rank supposed to be doing that rank can't? I think it just _may_ be a typo. Maybe. [http://forums.massassi.net/html/smile.gif]

Oh, and I agree that pulse would be better for your code... I'm not an expert in COG either, but I suggest you look at some examples, like the original JK Force cogs, to teach yourself how to use pulses.

I hope I was of some help.

------------------
"You know when you've been away from the Zone too long when none of your Zone friends recognize you." - /me

2001-12-13, 8:45 AM #15
where your do loop starts, put SetPulse(1); then put message pulse in the symbols section, and cut'n'paste this:

Code:
pulse:
  if((mana > 0) && (GetThingHealth(player) < 100) && (GetThingHealth(player) > 0))
  {
  HealThing(player, 1 * rank);
  ChangeInv(player, 14, -25); 
  //jkPrintUNIString(player, 303);
  }
  else
  {SetPulse(0);}
return;


And like ZZTer said, in the 1 * rank, the 1 * is useless, unless yo change the 1. Because 1 * rank is rank.


------------------
-Hell Raiser
Cogging type person that does, umm, stuff.
"Free, your, mind."
-Hell Raiser
2001-12-14, 11:53 AM #16
Okay, the cog is done and it works. If anyone wants it FOR ANYTHING just ask. I ended up using a while instead of a doWhile
BLEAH

AIM:SethTAlbright

↑ Up to the top!