home home

downloads files

forum forum

docs docs

wiki wiki

faq faq

Cube & Cube 2 FORUM


How to make health effect speed

by phoenixsux on 11/22/2007 22:31, 14 messages, last message: 01/05/2008 22:09, 1410 views, last view: 04/24/2024 09:44

in some games, such as America's Army, the more injured you are then the slower you move.

here is how to accomplish this in your mod should you choose to add it.

(keep in mind, i'm not a native C or C++ coder, so some of this code may be excessive or unnecessary.)

In
Void Self Damage (int damage, int actor, fpsent *act)

after this line:
player1->health = player1->health - damage;

add in:

player1->damaged(damage);

in Struct: Physent void reset()
add this line at the end of the sub before the }:

//set maximum speed here for player movement
maxspeed = 100;

in Struct: Physent
after
void reset()
{
code
}

add in:
void damaged (int damage)
{
maxspeed = maxspeed - damage;
//cap your minimum speed here
if (maxspeed < 20) maxspeed = 20;
//cap your maximum speed here
if (maxspeed > 100) maxspeed = 100;
}


in Struct dynent : physent
after
void normalize_yaw(float angle)
{
code
}
add:
void damaged (int damage)
{
maxspeed = maxspeed - damage;
//cap your minimum speed here
if (maxspeed < 20) maxspeed = 20;
//cap your maximum speed here
if (maxspeed > 100) maxspeed = 100;
}


the end results appear to cooperate over the network - when you are injured your speed drops.
when you die, your speed resets to normal.

if you want your speed to increase when your health inproves then simply pass on the negative value of your speed improvement to the damaged routine.

for example - if you pickup a 5 point helth then you want to
d->damaged(-5); to inprove your speed by the 5 points.

note: not tested over dialup or other laggy connections.

   Board Index   

#1: ..

by MovingTarget on 11/23/2007 15:41

Hmmm, nice work. Seems to be the best way to do it, but one question: why do you declare "void damaged(int damage)" in both physent AND dynent? Since dynent is inherited from physent, you need only declare it in physent. Other than that, good work!

reply to this message

#2: ..

by phoenixsux on 11/23/2007 20:14

Thanks, i was wondering which one it belonged in. :)

reply to this message

#3: Re: ..

by MovingTarget on 11/23/2007 20:17, refers to #2

You can figure that out by looking at the declaration of the class: struct dynent : physent, for example. The : physent means dynent is inheriting the features of physent.

reply to this message

#4: ..

by phoenixsux on 11/25/2007 03:26

heh, no YOU can figure it out that way. Me, i'm running around and bumping my head into walls with C++ and am still learning.

i only get about 30 mins of online time a week so it's slow going for me.

reply to this message

#5: usefull

by ATIRULE on 11/25/2007 04:03

hmm nice work may be useful for blood frontier

reply to this message

#6: ..

by slider on 11/25/2007 12:22

These tuts are useful....how hard would it be to add damage to falling from heights and even death from a really high fall ?

reply to this message

#7: Re: ..

by Wolf on 11/25/2007 13:59, refers to #6

Not that hard at all, it is already in my mod...

reply to this message

#8: Re: ..

by slider on 11/25/2007 14:07, refers to #7

can you link me to this ? pleez

reply to this message

#9: ..

by ljdp on 12/27/2007 20:33

In Game.h where you pickup health:

case I_HEALTH:
health = min(health+is.add, maxhealth);

how would i call
the damage function? =/

reply to this message

#10: Re: ..

by SheeEttin on 01/02/2008 23:48, refers to #9

What are you trying to do, make it so that health hurts you?

reply to this message

#11: Re: ..

by MovingTarget on 01/03/2008 00:14, refers to #10

No, if you read the last part of Pheonix's post, he says you should make it so that when you pick up health, your speed increases, or damaged(-25);. And if you think about it, if you have 1 health, you will be going pretty slow, but when you pick up health and have 100 again, with his code, you will still be going as slow as if you had 1.

And to #9, keep in mind that the code he is working with is old stuff now.

reply to this message

#12: Yeah..

by ljdp on 01/05/2008 16:30

I noticed, also you couldn't call the function from game.h because one was static the other was dynamic.

But i've managed to work it out,
theres a low and high cap, and the health regains if you pickup health, plus you'll get a boost in speed if you pick up health boost.

I'll probably post the code later.

reply to this message

#13: pings

by conorkirk@mac.com on 01/05/2008 21:40

One problem though, when your gamespeed changes, it messes with the netcode, causing people to get pings of 6578235647835628479 or -5.

reply to this message

#14: Re: pings

by SheeEttin on 01/05/2008 22:09, refers to #13

So don't change the gamespeed, just the movement speed.

reply to this message

   Board Index   


Unvalidated accounts can only reply to the 'Permanent Threads' section!


content by Aardappel & eihrul © 2001-2024
website by SleepwalkR © 2001-2024
53863363 visitors requested 71638475 pages
page created in 0.021 seconds using 10 queries
hosted by Boost Digital