Page 1 of 1

Health level trigger

Posted: 28 Feb 2019 21:50
by Arsonist
I am just introducing myself to this javascript stuff so I apologies if my question is a really simple answer.

I was wondering how to make a trigger that recognizes when you are at a set health, like the "wimpy trigger" but only it activates a command of my choosing.

Re: Health level trigger

Posted: 01 Mar 2019 18:59
by Shanoga
Good question! This would be using a GMCP trigger and checking the gmcp.data.character.vitals.health value. I haven't really tested to see EXACTLY what needs to be set up - maybe someone else has some experience using this kind of trigger? I might have some time to test this out today.

Re: Health level trigger

Posted: 01 Mar 2019 19:42
by Shanoga
Alright, so I figured out something that could be done...

You can create a trigger of the GMCP style with the trigger pattern being:

Code: Select all

char.vitals
so that every time the vitals gmcp package is received, the webclient will run your trigger.

Beware, though....this can get VERY spammy and you have to build in some really explicit triggers or you can spam yourself. An example:

Code: Select all

Pattern:
  char.vitals

Script:
  if (gwc.gmcp.data.character.vitals.health == 'feeling very well')
  {
    gwc.connection.send('say I am healthy!');
  }

Result:
  > say I am healthy!
  say I am healthy!
  say I am healthy!
  say I am healthy!
  say I am healthy!
  say I am healthy!
  You say: I am healthy!
  > 
  You say: I am healthy!
  > 
  You say: I am healthy!
  > 
  You say: I am healthy!
  > 
  You say: I am healthy!
  > 
  You say: I am healthy!
  >
So this can be done, but generally the vitals package has several different components, but when I tried using

Code: Select all

char.vitals.health
for the pattern, nothing happened. It might be worth using the

Code: Select all

gwc.trigger.disable
function to disable the trigger once it fires, then re-enable it a few seconds later after a timeout of a few seconds (or even a minute, depending on the action you are triggering).

A couple of things are happening here. I don't have a complete understanding of how this gmcp trigger is working (which is at least part of the issue), plus a lot of the more complicated code/trigger/script people use something other than the official webclient.

Anyway, I am always glad to try and troubleshoot! Feel free to respond here or hop on over to the most popular Discord server (https://discord.gg/UBVbBrY)and check out the #code-stuff channel where you can get faster responses from a variety of helpful players.

Re: Health level trigger

Posted: 01 Mar 2019 20:00
by Lionel
Not familiar with this client. Can you use variables?
If so, something like that:

if (currentHealth != gwc.gmcp.data.character.vitals.health) {
if (gwc.gmcp.data.character.vitals.health == 'feeling very well') {
// do stuff
}
}

currentHealth = gwc.gmcp.data.character.vitals.health;

would let you do the thing you want once, when currentHealth changes from any other value to 'feeling very well',
and not spam if it stays at 'feeling very well'

Re: Health level trigger

Posted: 01 Mar 2019 20:42
by Shanoga
That problem is that the GMCP package is sent multiple times at each health level, so it is sending 4 packages at "feeling very well" even if it is rapidly changing.