PDA

View Full Version : TG energy bar hack



Peter
23-03-07, 01:09 PM
here is how to implement the TG Energy Bar Hack in your own dizzyage games

1. create the following new functions to player.gs

// This function provides animation to the players lifebar
// when being replenished
func PlayerLifeBar() {

// if the deduct has a value greater than 1 then deduct it from the players lifeforce
if( p_lifebardeduct >= 1 ) PlayerLifeBarDeduct();

// if the lifebar is set to 0 then no increase is needed so exit.
if(p_lifebar==0) return;

l = PlayerGet(P_LIFE);
if (l>=62) { p_lifebar = 0; return; }
l += 1;
p_lifebar -= 1;
PlayerSet(P_LIFE,l);
if(p_lifebar<=0) p_lifebar=0;
PlayLifeBarFX(l);
}

func PlayerLifeBarDeduct() {

l = PlayerGet(P_LIFE);
if (l==0) { p_lifebardeduct = 0; return; }
l -= 1;
p_lifebardeduct -= 1;
PlayerSet(P_LIFE,l);
if(p_lifebardeduct<=0) p_lifebardeduct=0;
PlayLifeBarFX(l);
}

func PlayLifeBarFX( life ) {

l2 = FX_LIFEBAR + ( (int)life/2 ) - 1;
if(l2<= FX_LIFEBAR) l2=FX_LIFEBAR;
SamplePlay(l2);
}


then in the function PlayerLoseLife replace
PlayerSet(P_LIFE,100);
with
PlayerSet(P_LIFE,1); p_lifebar=61;

then in PlayerHurt find
SamplePlay(FX_HURT);
and releace with
PlayLifeBarFX(life);

then add the following onto the end of def.gs
int p_lifebar
int p_lifebardeduct


then in handlers.gs add the following on the end of HandlerGameUpdate
PlayerLifeBar();

then in HandlerDrawHud find
PlayerGet(P_LIFE)/100;
and change to
PlayerGet(P_LIFE)/62;

then in sounds.gs add the following onto the end of SoundInit
// Load lifebar sounds
// Leave at the bottom of the sampleload list!!!!
for(n=1;n<=32;n++)
SampleLoad( "Data\\Sounds\\fx_life"+(str)n+".wav", 1);

then add the following #def last on the FX_ list
// Lifebar FX leave at bottom of the sampleload list!!!!
#def FX_LIFEBAR x
remember to replace x with the next number in the sequence


then in files.gs add the following after the load brushes
if(!gs_filereadint(&val, f)) goto fileerror;
p_lifebar = val;
if(!gs_filereadint(&val, f)) goto fileerror;
p_lifebardeduct = val;

then the following after the save brushes

if(!gs_filewriteint(p_lifebar, f)) goto fileerror;
if(!gs_filewriteint(p_lifebardeduct, f)) goto fileerror;


Now in intro.gs add the following after PlayerSetPos

PlayerSet(P_LIFE,1);
p_lifebar = 61;

now just unzip the contents of the attached file into data/sounds.

the energy bar should now be working, to add energy to the bar when picking things up etc, use the following p_lifebar=x replacing x with the amount to add to the energy bar. to deduct is very simlarly done by using the following p_lifebardeduct=x and again replacing the x with the amount of energy to deduct.

delta
23-03-07, 01:47 PM
what does that do then? *is curious*

Peter
23-03-07, 02:10 PM
it makes the energy bar work and sound like it does in all the original dizzy games (magicland, Spellbound, POTY) I've added it to my prince of the yolkfolk remake if you want to take a look

delta
23-03-07, 02:31 PM
ah right i see.

yeah it made that sound as it increased at the start of the game or when respawned didn't it. i remember now...

delta
23-03-07, 02:38 PM
i like that sound. might have to use it in Dreamworld Dizzy. :p

i'm not sure i like the sound as he lands, cause if he rolls, it only makes the sound when he's stopped rolling, and he also makes the sound on clouds too...

overall tho, very good! :)

delta
09-05-07, 06:43 PM
just a couple of things:

after p_lifebardeduct=x and p_lifebar=x , you need to put a ';' to end the line.
eg:

p_lifebardeduct=x ;

also the attachment no longer seems to be there, i'll have to get the sounds out of the POTYF sounds file. luckily, i think i know which ones they are... :p

delta
09-05-07, 06:59 PM
hmmmm the only real trouble i'm having is that when in water, the energy bar decreases about twice as fast, and when you set it to decrease by 1 instead of 2, it doesn't make the sound, even though the only thing i've changed is a couple of 2s to a couple of 1s.

:v2_dizzy_confused2:

EDIT: got it! for some reason, the check in the new bit in player.gs checks if the energy to be deducted is above 1 instead of above 0, so as it wasn't above 1, it wasn't playing the sound.

all done! :)

Peter
09-05-07, 07:46 PM
i'll update this sometime next week for v2

delta
15-05-07, 09:33 PM
in player.gs you need to add

if(l2>= 39) return;

after

func PlayLifeBarFX( life ) {

l2 = FX_LIFEBAR + ( (int)life/2 ) - 1;
if(l2<= FX_LIFEBAR) l2=FX_LIFEBAR;

so that it doesn't throw an error up when eating food thats been changed to only add a bit.

delta
28-12-07, 07:20 PM
to get the hack to work in v2, you use all the previously mentioned code, then you need to change the following code:

in sound.gs, remove:



// Load lifebar sounds
// Leave at the bottom of the sampleload list!!!!
for(n=1;n<=32;n++)
SampleLoad( "Data\\Sounds\\fx_life"+(str)n+".wav", 1);


and add the samples in as normal AT THE END OF THE SAMPLE LIST, in sequential order. it doesn't matter at all what you call them. eg:



#def FX_LIFEBAR1 11
#def FX_LIFEBAR2 12
#def FX_LIFEBAR3 13
#def FX_LIFEBAR4 14
#def FX_LIFEBAR5 15
#def FX_LIFEBAR6 16
#def FX_LIFEBAR7 17
#def FX_LIFEBAR8 18
#def FX_LIFEBAR9 19
#def FX_LIFEBAR10 20
#def FX_LIFEBAR11 21
#def FX_LIFEBAR12 22
#def FX_LIFEBAR13 23
#def FX_LIFEBAR14 24
#def FX_LIFEBAR15 25
#def FX_LIFEBAR16 26
#def FX_LIFEBAR17 27
#def FX_LIFEBAR18 28
#def FX_LIFEBAR19 29
#def FX_LIFEBAR20 30
#def FX_LIFEBAR21 31
#def FX_LIFEBAR22 32
#def FX_LIFEBAR23 33
#def FX_LIFEBAR24 34
#def FX_LIFEBAR25 35
#def FX_LIFEBAR26 36
#def FX_LIFEBAR27 37
#def FX_LIFEBAR28 38
#def FX_LIFEBAR29 39
#def FX_LIFEBAR30 40
#def FX_LIFEBAR31 41
#def FX_LIFEBAR32 42
#def FX_LIFEBAR33 43


in player.gs, change



func PlayLifeBarFX( life ) {

l2 = FX_LIFEBAR + ( (int)life/2 ) - 1;
if(l2<= FX_LIFEBAR) l2=FX_LIFEBAR;
if(l2>= 39) return;
SamplePlay(l2);
}


to



func PlayLifeBarFX( life )
{
snd = ( (int)life/2 ) - 1;
if(snd<= 1) snd=1;
if(snd>= 39) return;
SamplePlay(snd+10);
}


the line: <b>SamplePlay(snd+10);</b> at the end has the number 10 in it. this needs to be the number of the sound sample BEFORE the first lifebar sample. in the example above, the first lifebar sample is sample number 11, so the number in the above line needs to be 10.

oh and don't forget you need to rename the samples so that they all start with numbers. eg '11 fx_lifebar.mp3', '12 fx_lifebar.mp3' etc

the lifebar FX will now work in v2 :v2_dizzy_happy:

delta
03-01-09, 02:24 PM
Just a little note, i've updated this whole function somewhat in IID (while also standardising a load of other custom functions i've done over time), mainly so that you don't have to change anything in the save or load file functions, but also to try and standardise it. I may post the new version once i'm certain it all works.

delta
24-01-09, 10:38 PM
to implement the Energy Bar hack seen in TTD, WWD, RRD, MSD and IID (all are games made with DizzyAGE v2.2), you'll need to change some functions in various scripts. You'll also need to copy the lifebar samples from the 'samples' folder in one of the above mentioned games data folders into the 'samples' folder in your games data folder. these are called xx fx_life.ogg, where xx is a number.

code needed:

add the red highlighted code in gamedef.gs:



// player variables starting from P_USER=64 up to P_MAX=128
#def P_LIFEBAR 64 // new lifebar
#def P_LIFEBARDEDUCT 65 // new lifebar


=================================================

add the following three functions in player.gs:



/////////////////////////////////////////////////////////////////////////////////
// This function provides animation to the players lifebar
// when being replenished
/////////////////////////////////////////////////////////////////////////////////
func PlayerLifeBar()
{
// if the deduct has a value greater than 1 then deduct it from the players lifeforce
if( PlayerGet(P_LIFEBARDEDUCT) >= 1 ) PlayerLifeBarDeduct();

// if the lifebar is set to 0 then no increase is needed so exit.
if(PlayerGet(P_LIFEBAR)==0) return;

l = PlayerGet(P_LIFE);
if (l > =62) { PlayerSet(P_LIFEBAR,0); return; }
if (l==0) { PlayerSet(P_LIFEBAR,0); return; }
l += 1;
PlayerSet(P_LIFEBAR,PlayerGet(P_LIFEBAR)-1);
PlayerSet(P_LIFE,l);
if(PlayerGet(P_LIFEBAR) < =0) PlayerSet(P_LIFEBAR,0);
PlayLifeBarFX(l);
}

func PlayerLifeBarDeduct()
{
l = PlayerGet(P_LIFE);
if (l==0) { PlayerSet(P_LIFEBARDEDUCT,0); return; }
l -= 1;
PlayerSet(P_LIFEBARDEDUCT,PlayerGet(P_LIFEBARDEDUC T)-1);
PlayerSet(P_LIFE,l);
if(PlayerGet(P_LIFEBARDEDUCT) < =0) PlayerSet(P_LIFEBARDEDUCT,0);
PlayLifeBarFX(l);
}

func PlayLifeBarFX( life )
{
snd = ( (int)life/2 ) - 1;
if(snd < = 1) snd=1;
if(snd > = 39) return;
SamplePlay(snd+10);
}


you may need to remove the spaces before and after < and > , these spaces have been inserted to get around the filters on this site.

the line: SamplePlay(snd+10); at the end of the above code has the number 10 in it. this needs to be the number BEFORE the first lifebar sound sample. in the code below, the first lifebar sample is sample number 11, so the number in the above line needs to be 10.

=================================================

in sound.gs:


#def FX_LIFEBAR1 11
#def FX_LIFEBAR2 12
#def FX_LIFEBAR3 13
#def FX_LIFEBAR4 14
#def FX_LIFEBAR5 15
#def FX_LIFEBAR6 16
#def FX_LIFEBAR7 17
#def FX_LIFEBAR8 18
#def FX_LIFEBAR9 19
#def FX_LIFEBAR10 20
#def FX_LIFEBAR11 21
#def FX_LIFEBAR12 22
#def FX_LIFEBAR13 23
#def FX_LIFEBAR14 24
#def FX_LIFEBAR15 25
#def FX_LIFEBAR16 26
#def FX_LIFEBAR17 27
#def FX_LIFEBAR18 28
#def FX_LIFEBAR19 29
#def FX_LIFEBAR20 30
#def FX_LIFEBAR21 31
#def FX_LIFEBAR22 32
#def FX_LIFEBAR23 33
#def FX_LIFEBAR24 34
#def FX_LIFEBAR25 35
#def FX_LIFEBAR26 36
#def FX_LIFEBAR27 37
#def FX_LIFEBAR28 38
#def FX_LIFEBAR29 39
#def FX_LIFEBAR30 40
#def FX_LIFEBAR31 41
#def FX_LIFEBAR32 42
#def FX_LIFEBAR33 43


=================================================

in the function PlayerRespawn() in player.gs, replace the following:


PlayerSet(P_LIFE, 100);


with:


PlayerSet(P_LIFE,1);
PlayerSet(P_LIFEBAR,61);


=================================================

in the function PlayerHurt() in player.gs, replace:


SamplePlay(FX_HURT);
life = PlayerGet(P_LIFE) - damage;


with


life = PlayerGet(P_LIFE) - damage;
PlayLifeBarFX(life);


=================================================

in the function PlayerUpdateWaterPlay() in player.gs, change the '2' to a '1' as highlighted in blue, and add the code highlighted in red:


PlayerSet(P_EMOTION, EMOTION_NOAIR3);
if(PlayerGet(P_LIFE) > 0)
{
PlayerSet(P_LIFE,PlayerGet(P_LIFE)-1);
PlayerSet(P_LIFEBARDEDUCT,1);
if(PlayerGet(P_LIFE) < =0) PlayerSet(P_DEATH,0); // set cause of death if needed
}


=================================================

in the function HandlerGameUpdate() in handlers.gs, put the following at the bottom:


PlayerLifeBar();


=================================================

in the function HandlerDrawHUD() in handlers.gs, replace:


PlayerGet(P_LIFE)/100;


with


PlayerGet(P_LIFE)/62;


=================================================

in function MainMenu() in menus.gs, insert the code highlighted in red:


GameSet(G_PAUSE,0);
PlayerSetPos(PLAYER_MAINMENUX,PLAYER_MAINMENUY);
PlayerSet(P_LIFE,62);
GameSet(G_COVER,1);
MusicStop();
MusicFade(0,0);


=================================================

in function BeginNewGame() in game.gs, insert the code highlighted in red:


GameSet(G_PAUSE,0);
PlayerSet(P_DISABLE,0);
PlayerSetPos(PLAYER_BEGINX,PLAYER_BEGINY);
MusicFade(0,1);
MusicPlay(MUSIC_DEFAULT);
PlayerSet(P_LIFE,1);
PlayerSet(P_LIFEBAR,61);


=================================================

if you are going to have dizzy eat something to replenish his health, then in function DoPickupObject() in action.gs, replace the following:


count = 0;
while(life < 100 || count < 10)
{
PlayerPlayAnimFrames(PTILE_EAT, {0,1} );
life+=10; if(life > 100) life=100;
PlayerSet(P_LIFE,life);
count++;
}


with:


life = PlayerGet(P_LIFE);
newlife=life+10;
while(life < newlife)
{
PlayerPlayAnimFrames(PTILE_EAT, {0,1} );
life+=2;
if(life > =newlife) life=newlife;
if(life > =62) life=62;
if(life==62) break;
PlayerSet(P_LIFE,life);
PlayerSet(P_LIFEBAR,2);
}

note that on the second line, the number 10 in newlife=life+10; is the amount that dizzys health is increased by (0 being none, and 62 being full life bar)

=================================================

There is no longer any need to change anything in files.gs

Colin
03-11-10, 09:19 PM
Jamie, i've just been installing this into my game. had a problem getting it to run though. I kept getting errors in the action.gs part. I ended up cutting it out of TTD. I think it's the spaces between > = in the 'if' checks

delta
03-11-10, 09:21 PM
Jamie, i've just been installing this into my game. had a problem getting it to run though. I kept getting errors in the action.gs part. I ended up cutting it out of TTD. I think it's the spaces between > = in the 'if' checks

yeah you need to remove the spaces, but I had to put them in there otherwise the forum cut the code out of the post.

Colin
03-11-10, 09:23 PM
oh, that explains it. thanks jamie