Jump to content
The Dark Mod Forums

Healing the player slowly over time (Regeneration)


kingsal

Recommended Posts

Hello everyone,

 

 

I am looking for some help with a script that slowly heals the player over time. Similar to a regeneration effect.

 

For example: The player picks up a holy item that constantly regenerates life over time. As long as its in their inventory, its healing them slowly back to full health.

 

Any ideas on how to do this?

Edited by kingsal
Link to comment
Share on other sites

Health is a spawnarg on the player object, so you could just have a script under the 'void main' heading that raises its value with SetKey(); maybe every 10 seconds or so (a loop with wait(); set for 10 seconds of time at the bottom) when the player has the object in their inventory (look up inventory script commands in the wiki) & health is less than the maximum (an 'if' or 'while' conditional at the top of the loop).

What do you see when you turn out the light? I can't tell you but I know that it's mine.

Link to comment
Share on other sites

Hmm so we would increase the value of that spawnarg over time if the player can be healed?

 

I apologize Dema. I'm novice at scripting, but this is what I could scratch together looking at the health potion script.

void autoHeal(entity userEntity)
{
	float healed = userEntity.heal(getKey("def_heal"), 1.0);

	if (healed != 0) 
		{
		userEntity.setKey("health", "1");
		}

}
Link to comment
Share on other sites

For reference this is the health potion script I was able to find.

void playertools_healthpotion::inventoryUse(entity userEntity, entity frobbedEntity, float buttonState)
{
	
	// Heal the entity using the second argument as healDefName
	float healed = userEntity.heal(getKey("def_heal"), 1.0);

	// If the entity could be healed (returnvalue != 0), play the sound, if there is one
	if (healed != 0) {
		// Do we have a non-empty soundshader string specified
		string soundShader = getKey("snd_swallow");
		if (soundShader != "") {
			sys.cacheSoundShader(soundShader);

			// If the soundchannel argument is empty
			userEntity.startSoundShader(soundShader, SND_CHANNEL_VOICE);
		}

		// Callback to decrease the inventory stack count
		userEntity.changeInvItemCount(getKey("inv_name"), getKey("inv_category"), -1);
	}
}
Link to comment
Share on other sites

Here is Obsttorte script for diving helmet (it regenerate breath bar, you equip / unequip it from inventory), you can try to modify it:

#ifndef DIVING
#define DIVING
object divinghelmet : player_tools
{
  void init();
  void inventoryUse(entity userEntity, entity frobbedEntity, float buttonState);
  void toggle();
  void updateLoop();
  float inUse;
  vector black;
  float overlayHandle;
  float processing;

};
void divinghelmet::init()
{
  inUse = 0;
  black = '0 0 0';
  processing = 0;
  thread updateLoop();
}
void divinghelmet::updateLoop()
{
  while(1)
  {
    if(inUse)
    {
      $player1.heal("breath_potion", 3);
                sys.trigger($helmet_breath);
    }
    wait(8);
  }
}
void divinghelmet::toggle()
{
  if (processing) return;
  processing = 1;
  if (inUse)
  {
    $player1.destroyOverlay(overlayHandle);
    inUse = 0;
    sys.fadeTo(black, 0.0, 1.0);
           sys.trigger($air_valve);
    sys.wait(1.0);
  }
  else
  {
    sys.fadeTo(black, 1.0, 0.5);
           sys.trigger($air_valve);
    wait(0.5);
    overlayHandle = $player1.createOverlay("guis/helmet.gui", -1);
    inUse = 1;
  }

  processing=0;

}
void divinghelmet::inventoryUse(entity userEntity, entity frobbedEntity, float buttonState)
{
  thread toggle();
}
#endif
Edited by ERH+
  • Like 1

S2wtMNl.gif

Link to comment
Share on other sites

It's telling you there's a script command just for healing.

 

Edit. Sorry, I get it now (looking at Obs's script). Heal increments a spawnarg property the value of the second argument. (That is, it does the same job as += and setKey with one function, so much more efficient. So drop the setKey strategy.)

 

Incidently, you can look up all the darkmod script commands. There's a list on the wiki somewhere with some usage info.

 

So to do it with heal.

The player's entity name first off is $player1.

And using heal

$player1.heal(health, 1);
Will be each click of healing.

Do you know about conditionals and loops in coding?

Obs example is useful. You'd want a "while gizmo is in inventory(1) & health<(whatever its max value is)" variant.

But if you still need guidance then we have to get more basic & I'll probably need my laptop & I'll write more when I go to a cafe for wifi, since it's hard to type code on my phone right now.

  • Like 1

What do you see when you turn out the light? I can't tell you but I know that it's mine.

Link to comment
Share on other sites

This is all really helpful!

 

I am very new to scripting/coding so I don't know about conditionals and loops, but I can sort of infer their meaning.

I don't think I will be able to get something totally workable right off the bat, but I'll take what you have here and do some trial and error.

 

Edit: To be more specific, I am just getting to the point where I can read the code and sort of pick out whats going on.

Edited by kingsal
Link to comment
Share on other sites

Okay so I plugged in Obs's script, but when I use it from the inventory it turns the screen black and doesn't seem to work.

 

This is the error I get:

WARNING:maps\test_map.script(131): Thread 'divinghelmet::toggle': Entity not fo
und for event 'trigger'. Terminating thread.

Is there something I'm missing in the def file?

entityDef atdm:diving_helmet 
{

	"inherit"				"atdm:playertool_stackable"
	"editor_usage"				"Diving helmet"
	"model"					"models/darkmod/wearables/headgear/elitecitywatch_helmet.lwo"
	"clipmodel" "models/darkmod/misc/clipmodels/elitecitywatch_helmet_cm.lwo"
	"inv_icon"				"guis/assets/hud/inventory_icons/holywater_icon"
	"inv_name"				"Diving helmet" 
	"inv_category"				"#str_02393"
	"scriptobject"				"divinghelmet"

}
Edited by kingsal
Link to comment
Share on other sites

.def should contain this:

entityDef atdm:er_sub_divinghelmet2
{
    "inherit"             "func_static"
    "editor_usage"        "er_sub_divinghelmet2"
    "model"               "models/er_sub_divinghelmet2.ase"  
}
entityDef	atdm:diving_helmet
{
	"inherit"			"atdm:playertool"	
	"inv_name"			"diving helmet"
	"model"			"models/er_sub_divinghelmet2.ase"
	"inv_icon"			"guis/assets/divinghelmet.tga"
	"scriptobject"		"divinghelmet"
	"used_action_script"	"frob_trigger"
}
entityDef fadeOut
{
	"inherit"			"trigger_fade"
}
entityDef fadeIn
{
	"inherit"			"trigger_fade"
	"fade_color"		"0 0 0 0"
}
Edited by ERH+

S2wtMNl.gif

Link to comment
Share on other sites

ERH- I updated the .def to match yours, but I'm still getting the same error when I use the item.

The screen fades to black, but nothing happens. I also can't toggle back out of the black screen.

WARNING:maps\test_map.script(131): Thread 'divinghelmet::toggle': Entity not fo
und for event 'trigger'. Terminating thread.
Link to comment
Share on other sites

You need his helmet entity in the models folder. If you want to see it working, run Obs FM which has it. All it does is add 3 breath every 8 seconds.

But I understood you want your gizmo to work just by being in the inventory, not inv-frobbing it. That's an easier setup. There are different ways depending on if you can still drop it afterwards (if not, just have the original frob turn the script on). If so, you need to either toggle it going in and out of inv, or you make an 'gizmo in inv is true' check each round.

Here's Inventory in the wiki. There should be a script function to return true if a thing is in the inv (there's one for loot), but I don't see it in this list so either it doesn't list them all or you need to be creative to get 'true' when the gizmo is in the inv. http://wiki.thedarkmod.com/index.php?title=Inventory

What do you see when you turn out the light? I can't tell you but I know that it's mine.

Link to comment
Share on other sites

Ah okay I didn't know it was in an FM.

I don't remember this in Old Habits, which FM should I look at?

 

I'll read through the wiki and give this another shot tomorrow.

Thanks for the help!

Link to comment
Share on other sites

There is a lot of additional stuff going on in the script which was specific for erh's purpose, and which is not needed by you.

#ifndef HEALER
#define HEALER
object healer : player_tools
{
  void init();
  void updateLoop();
};
void healer::init()
{
  thread updateLoop();
}
void healer::updateLoop()
{
  while(1)
  {
    $player1.heal("heal_potion", 3);    
    wait(8);
  }
}

#endif

FM's: Builder Roads, Old Habits, Old Habits Rebuild

Mapping and Scripting: Apples and Peaches

Sculptris Models and Tutorials: Obsttortes Models

My wiki articles: Obstipedia

Texture Blending in DR: DR ASE Blend Exporter

Link to comment
Share on other sites

I don't know if "player_tools" does anything, but that doesn't have any visible conditional, so short of something I don't know, it's just going to start healing from the start.

He wants the conditional that it heals while his gizmo is in the player's inventory. How do you add that?

Well anyway, kingsal, that's the piece you need to add to what Obs just posted to make it work, in between the while & the heal, assuming something about player_tools doesn't already handle that part.

...
while(1)
{
if [number of gizmos in inventory is > 0] // there may be multiple ways to make this check
   {
    $player1.heal("heal_potion", 3);
    wait(8);
   }
}
...

What do you see when you turn out the light? I can't tell you but I know that it's mine.

Link to comment
Share on other sites

Thanks Obs and ERH, I tested the script out and it works pretty well. The diving helmet is a brilliant idea, btw.

 

I found a strange bug. If I pick up and activate the healer item then reload the map it keeps running the heal script without the item being in the inventory.

 

I imagine this has something do with what Dema is saying, it needs to do an additional check to make sure the item is in the inventory.

 

EDIT:

 

I added back in the inUse uhh.. condition? And it works as expected.

I wonder if there is something like inInventory that can be checked.

#ifndef HEALER
#define HEALER
object healer : player_tools
{
	void init();
	void inventoryUse(entity userEntity, entity frobbedEntity, float buttonState);
	void toggle();
	void updateLoop();
	float inUse;
	float processing;

};
void healer::init()
{
	inUse = 0;
	processing = 0;
	thread updateLoop();
}
void healer::updateLoop()
{
	while(1)
	{
		if(inUse)
		{
			$player1.heal("heal_potion", 3); 
		}
		wait(8);
	}
}
void healer::toggle()
{
	if (processing) return;
	processing = 1;
	if (inUse)
		{
			inUse = 0;
		}
		else
		{
			inUse = 1;
		}
	
	processing=0;	

}
void healer::inventoryUse(entity userEntity, entity frobbedEntity, float buttonState)
{
	thread toggle();
}
#endif
Edited by kingsal
Link to comment
Share on other sites

Another way to go about it is with a hidden objective. There's an objective for having an object in your inventory, and the objective system lets you call a script or trigger things when it succeeds. You could have its satisfaction set the heal condition, and its failure end the condition, or some variation of that.

What do you see when you turn out the light? I can't tell you but I know that it's mine.

Link to comment
Share on other sites

Doing it with objectives is a good solution.

 

I don't necessarily need do everything with the script, but it would make it more versatile / useful if I can figure out how to do the inventory item check. I tried to dig something out of the objectives code, but didn't have any luck there.

 

So far this is definitely enough to get me started!

Edited by kingsal
Link to comment
Share on other sites

The objectives system can call a script. That script that it calls can set your condition directly, for example with a global variable or putting a value on a dummy spawnarg on an object that your healing script can read.

What do you see when you turn out the light? I can't tell you but I know that it's mine.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 3 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
    • The Black Arrow

      I wanna play Doom 3, but fhDoom has much better features than dhewm3, yet fhDoom is old, outdated and probably not supported. Damn!
      Makes me think that TDM engine for Doom 3 itself would actually be perfect.
      · 6 replies
    • Petike the Taffer

      Maybe a bit of advice ? In the FM series I'm preparing, the two main characters have the given names Toby and Agnes (it's the protagonist and deuteragonist, respectively), I've been toying with the idea of giving them family names as well, since many of the FM series have named protagonists who have surnames. Toby's from a family who were usually farriers, though he eventually wound up working as a cobbler (this serves as a daylight "front" for his night time thieving). Would it make sense if the man's popularly accepted family name was Farrier ? It's an existing, though less common English surname, and it directly refers to the profession practiced by his relatives. Your suggestions ?
      · 9 replies
    • nbohr1more

      Looks like the "Reverse April Fools" releases were too well hidden. Darkfate still hasn't acknowledge all the new releases. Did you play any of the new April Fools missions?
      · 5 replies
×
×
  • Create New...