hp trigger

Posted by Hattrick on Sat 04 Oct 2003 08:15 AM — 9 posts, 30,954 views.

#0
how would i be able to create a trigger which makes me "rub oil" (salve) whenever my hp drops below 100.

the syntax is
hp: 220|sp: 167|mp: 290 >
and this is displayed in EVERY round of combat and every time i change rooms. the oil takes about 4 seconds to take affect while each combat round is about 2s. so if my hp, drops below 100, a standard trigger will send rub oil twice (since a round goes by after rub oil is sent and this inturn triggers rub oil again since my hp is still below 100).

how can i write a script to rub oil and also to have about a 3 second delay if the trigger after fired once so i dont waste oil?

thanks in advance
Greece #1
Make the trigger a regular expression, and put this in the "match" box:
hp: \d\d|sp: .*|mp: .* >

then, make it send to scripting, and write that in the send box:

DoAfter 4, "rub oil"

It should work.
Canada #2
No, that won't work. You'll just stack multiple doafter's with each health bar that is received.

I would do something along the lines of:

If SalveTimer exists, do nothing,
else create 4 second SalveTimer and apply the salve.

Another option would be to set a boolean variable:

If NOT ApplyingSalve then
ApplyingSalve = True,
Send the line to apply salve

...but this requires a second trigger on the line where you actually apply the salve, to set ApplyingSalve = False.
USA #3
How about you have the trigger disable itself, with a Doafter to reenable it?

(ie, triggers have a built in boolean, its the enabled flag)

Err, Apparently Doafter doesnt get parsed (the next thread told me!) So, just use Createtimer.
Amended on Sat 04 Oct 2003 07:52 PM by Flannel
Greece #4
Ah, right, missed that, sorry. You should be able to disable it and create a timer to reenable it after a few seconds from within the trigger...
Russia #5
I prefer using what I call "scripted timers" for that sort of thing. This means measuring the time between trigger calls of the script routine to figure out if a certain time period has elapsed. I find that to be more convenient than adding/deleting mushclient timers all the time, especially if you want to queue several jobs like that. The template for a "scripted timer" involves:

1. A trigger subroutine
2. A "balance" variable - this is a flag which defines whether you can or not perform a certain queued task.
3. A "time stamp" variable - this stores the exact time when the balance variable was set to false (the task was performed) last.
4. A "time setting" subroutine - sets the value of the time stamp variable (3); is called everytime the balance variable (2) is set to false - the corresponding task is performed
5. A "time check" function - subtracts the time stamp from the time of the current call, then compares the result to the specified time period for a specific balance variable. Returns vbTrue if the time period has elapsed, vbFalse - if it's still too early to perform the task again.

The entire setup makes sure you perform a specific task no more often than over a specific interval of time, which is what is achieved with MC timers. However, I find this approach to be a lot cleaner than fiddling around with multiple MC timers, and com calls associated with them. It is also very simple to expand to add new tasks - you just have to add new balance/time-stamp variable pairs for each task and include them in your subs and function.

Here's an example script in vbs:


'This is the balance/time-stamp pair for the "oil" task
dim oilBalance, oilTimestamp
oilBalance = vbTrue

'This is the sub called by your prompt trigger
'
sub CheckPrompt(name, output, wildcs)
 'code to extract and store the values from the prompt goes
 'somewhere around here

 'and here's the timer-related code
 if oilBalance then
  world.send "rub oil"
  SetTimeStamp "oil"
  oilBalance = vbFalse
 else
  if TimingExpired("oil") then
   world.send "rub oil"
   SetTimeStamp "oil"
   oilBalance = vbFalse
  end if 
 end if 
end sub




'This sets the time stamp
'
sub SetTimeStamp(task)
 select case task
  case "oil"
   oilTimeStamp = Timer
 end select
end sub

'This checks if the timing for a certain task has expired
'
function TimingExpired(task)
dim timeNow, timeDiff
timeNow = Timer
  select case task
   case "oil"
    timeDiff = timeNow - oilTimestamp
    if (timeDiff < 0) then
     timeDiff = timeNow + (86400 - oilTimestamp)
    end if
    if (timeDiff < 4.0) then  'here 4.0 denotes the delay between oil rubs
     TimingExpired = vbFalse
    else
     oilBalance = vbTrue
     TimingExpired = vbTrue
    end if
  end select
end function


For fool-proofness' sake you can add a 1 sec timer to the prompt trigger to check for the expiration of the balance time - that offers enough protection against lag, from my experience.
Amended on Wed 08 Oct 2003 12:48 PM by Ked
Greece #6
I prefer to just send a command to the mud that doesn't give you lag and that won't be seen by other players, such as "Dgdsgdf", which produces "Huh?". That way i can match on Huh and i don't need timers, and i also know exactly when the previous action finished.
Australia Forum Administrator #7
So, if the MUD logs mis-typed commands (as some do) then the admins will say to themselves, "there goes Poremenos, trying that "Dgdsgdf" command again - he never seems to get it right.".

:)
Greece #8
lol, didn't know they logged that... Anyway, the mud i'm in allows triggers, so it's a nice way to do it :)