Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Draxx
Beginner


Joined: 24 Jan 2011
Posts: 11

PostPosted: Mon Jan 25, 2021 2:35 pm   

Need help with a script to monitor # of fails
 
To start with, lets say I have a skill which gives 2 messages:
Success : You manage to craft <an item>.
Fail : You mangle up the materials.

I need a script that will do a few things :

1) Keep a track of the # of failures (so I know when I will reach 20 failures).
2) In case the skill fails, I want it to wait 50 mins before it can add to the # of failures (Any failures within that time limit do not count/add to skill improvement), and show me a message saying : Your number of fails for this skill are <so many number>.
3) In case the skill fails within the 50 mins, I want it to show me something like : Your timer for this skill hasn't expired yet, you still need to wait <so many> minutes, so far you have failed this skill <so many number> of times.
4) At the end of 50 mins, I want it to send me a message saying : The timer has expired, you can re-attempt this skill.
5) Every time I log out and back into CMUD, I want the timer for the skill to be reset to 50 mins.
6) When I hit 20 failures, I want a message to pop up saying : You have reached 20 fails on this skill and can advance.

I will greatly appreciate it if someone can advise me how to script this.

Thanks in advance,
Draxx
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Mon Jan 25, 2021 9:11 pm   
 
Easy enough.

Presumably, there is more than one thing you can craft with the same fail/success messages?

First, you need a variable to track what you are making.

#ONINPUT {craft (*)} {crafting=%1}

Since we only really care about the failures, next we need a variable to track those.
We also need a variable to track how much time is left in your countdown.
I would suggest database variables.

Code:
#TR {You mangle up the materials.} {#IF (%db(@timers, @crafting)) {
  #PRINT {Your timer for this skill hasn't expired yet, you still need to wait %db(@timers, @crafting) minutes, so far you have failed this skill %db(@failures, @crafting) times.}
} {
  #ADDKEY timers @crafting 51
  $fails=%db(@failures, @crafting)
  $fails=($fails+1)
  #ADDKEY failures @crafting $fails
  #IF ($fails>19) {#PRINT {You have reached 20 fails on this skill and can advance @crafting.}} {#PRINT {Your number of fails for this skill are %db(@failures, @crafting).}}
}}


I padded your minute count by one, just in case your countdown alarm fires immediately after we set the time.
Speaking of, you need a countdown alarm.

Code:
#ALARM "countDown" -1:00 {#FORALL %dbkeys(@timers) {
  $time=%db(@timers, %i)
  $time=($time-1)
  #IF ($time>0) {#ADDKEY timers %i $time} {
    #DELKEY timers %i
    #PRINT {The timer for %i has expired, you can re-attempt this skill.}
  }
}}


You need to clear out the fail count when you do advance.

#TR {You advance in skill.} {#DELKEY failures @crafting}

And then the login reset is best handled with an event:

#EVENT onConnect {#FORALL %dbkeys(@timers) {#ADDKEY timers %i 51}}

This code is designed to be entered from the command line.
_________________
Discord: Shalimarwildcat
Reply with quote
Draxx
Beginner


Joined: 24 Jan 2011
Posts: 11

PostPosted: Tue Jan 26, 2021 9:20 am   
 
Thank you Shalimar, this works perfectly!
Reply with quote
Draxx
Beginner


Joined: 24 Jan 2011
Posts: 11

PostPosted: Thu Jan 28, 2021 8:56 am   
 
Hi Shalimar,

The solution you suggested SEEMED to work perfectly, to begin with. So far I've set up the trigger to monitor fails on 5 different crafting skills (and labelled them appropriately).

But yesterday when I logged into the MUD, I tried one of the skills - I got a fail - and the message I got was "you still need to wait 38 mins to re-attempt this skill".

It should have reset all timers to 51 mins at the onConnect EVENT, but didnt.

A little more digging showed that the timers for all 5 skills were set at 38 mins (i.e. none of the timers were reset to 51 mins).

Furthermore, since the timers weren't reset, CMud assumed that the timer was still on for all the skills - so it's counting down from 38 mins for all the skills, even though I just triggered one of the skills on this log-in.

So, I manually ran the onConnect event - it reset all the timers to 51 mins, BUT, it's already counting down the timers for all the 5 skills, without waiting for a failure trigger to start the timer.

I suspect the DELKEY timers need to first be deleted onConnect, and then set to 51 mins.

Do you think you can suggest some solution for this?


Thank you
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Thu Jan 28, 2021 5:44 pm   
 
It sounds like that is the behavior you wanted to begin with.
Anything that exists in the @timers database will always be counting down, as a result of the alarm.
You can always disable the alarm if you don't want them to count down, though I can't think of why you would want to do that.

Members of @timers self delete when they reach 0.
You wanted them to reset to 51 (all of them), on relogging, which it sounds like is working as intended.
There should be no need to delete and then recreate, the way it is set up you cannot have duplicate entries, assigning a new value is the same as deleting and recreating.

I would assume you had been logged in for about 13 minutes when you attempted to craft, and since that isn't the full 51 minutes, it assumes you still had to wait from the attempts during your last session.
I don't see what the problem is as you explain it.
_________________
Discord: Shalimarwildcat
Reply with quote
Draxx
Beginner


Joined: 24 Jan 2011
Posts: 11

PostPosted: Mon Feb 01, 2021 2:04 pm   
 
One last question on this script @Shalimar :

Is there a way to have all active timers show up in a separate window (floating preferably) - such that they show the crafting skill name and time left - and they disappear (or set to to Zero) when the timers run out?

Thanks
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Mon Feb 01, 2021 2:41 pm   
 
Possible, but it is hard to keep floating windows on top when another window has focus.

Just add something like this to the bottom of the alarm:

Code:
#EXECWIN windowName {
   #CLR
   #SHOWDB @timers
}
_________________
Discord: Shalimarwildcat
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net