Results 1 to 3 of 3

Thread: Problem with ;heal

  1. #1
    Join Date
    May 2007
    Location
    The sphincter of hell.
    Posts
    5

    Default Problem with ;heal

    >;hea XXX
    --- Lich: heal active.
    [heal]>appraise XXX
    You take a quick appraisal of XXXXXX and find that he/she has minor cuts and bruises on his/her abdominal area.
    He/She has old battle scars on his/her right leg, terrible, permanent mutilation of his/her abdominal muscles, a black-and-blue left eye, and developed slurred speech.
    >
    [heal]>transfer XXXXXX abdomen
    You meditate over XXXXXX.
    XXXXXX's abdomen damage is transferred to you.
    >
    [heal]>prep 1101
    You focus your thoughts while chanting the mystical phrase for Heal...
    Your spell is ready.
    >
    [heal]>cure
    You concentrate.
    You're already at full health!
    Cast Roundtime 3 seconds.
    (Forcing stance down to guarded)
    >
    You've gained 1 physical training point.
    (To use these new points, type GOALS and adjust your skills.)
    >
    [heal]>prep 1101
    You focus your thoughts while chanting the mystical phrase for Heal...
    Your spell is ready.
    >
    [heal]>cure
    You concentrate.
    You're already at full health!
    Cast Roundtime 3 seconds.
    >;kill hea
    --- Lich: heal stopped.


    So, it's been doing this for about a month now. I'm tired of it doing that, and I'm wondering if there's a way to stop it or fix it?
    Making accusations one day at a time

  2. #2

    Default

    Post the source code, plz.
    Razzle them. Dazzle them. Razzle dazzle them.

  3. #3
    Join Date
    Nov 2004
    Location
    Upstate NY
    Posts
    428

    Default

    Weird... dunno what's up with that. Here, you can copy/paste this if you want... all I did was comment out the part that deals with health (lines 150 to 190).


    Code:
    # REQUIRED: Lich v2.88+ if you use Wizard, or Lich v3.37+ if you use StormFront
    # Script for empaths to heal a target, then themselves. Basically, it clones the infamous JSE script (I think it works exactly the same, anyway... I've never used JSE, have never been an empath, and wrote it by request to suit the guy who asked for it, so who knows).
    
    # This is the level of wound you want the script to stop at... 1 would be a minor wound (rank 1). If you'd like it to go all the way to fully healed, just change the line so that the number is 0 instead of 1.
    stop_at = 1
    
    # The command 'quiet_exit' just tells Lich that it shouldn't clutter your game window when the script ends by informing you it exited.
    #quiet_exit
    
    # This checks to make sure the user gave us a name of a target to act on ('script.vars' is an array of the words the user entered after the script name, and calling the 'empty?' method of an array asks if the array is empty or not).
    if script.vars.empty?
        respond("You didn't supply a target! You need to tell me who to heal.")
        exit
    end
    
    # This sounds a whole lot more complicated than it really is, but the following defines a 'procedure object' -- what it does is wrap up everything in the block (the 'block' is what's between the opening squiggly '{' and the closing one '}'). Once you've defined a procedure object, you can call the object and execute it at anytime, as many times as you want, by just calling the 'call' method of procedures. So basically, 'healdown = proc' means, 'make a variable called healdown, and put the following procedure object into it'. Once that's done, you can execute the procedure with the command 'healdown.call' (for anyone familiar with JSE, I *believe*, but am not positive, there's a JSE function named 'callsub' -- the name sounds like it's doing the same thing as this, which is more or less executing a subroutine; if it helps, think of this as declaring the label for 'callsub' to execute [I think JSE works that way?]).
    healdown = proc { |area|
        if area =~ /head|neck/
            spell = 1104
            if Wounds.neck > 1 then cost = 9 else cost = 4 end
        elsif area =~ /hand|arm|leg/
            spell = 1102
            if Wounds.limbs > 1 then cost = 7 else cost = 2 end
        elsif area =~ /eye|ab|chest|back/
            spell = 1105
            if Wounds.torso > 1 then cost = 10 else cost = 5 end
        elsif area =~ /nerve/
            spell = 1103
            if Wounds.nerves > 1 then cost = 8 else cost = 3 end
        end
        unless mana?(cost)
            respond("Insufficient mana, will continue when you have enough...")
            until mana?(cost)
                sleep 1
            end
        end
        fput "prep #{spell}"
        fput "cure #{area}"
        sleep 3
        waitrt?
    }
    
    # Another procedure object that will be called later on in the script. I'm a big fan of the 'DRY' principle (Don't Repeat Yourself), so I like to write things just once and then repeat them with a single line instead of having to write them over & over again anytime I want to do the same thing.
    translate_wound = proc { |wound|
        wound = wound.split.join(' ')
        if wound =~ /(l|r)(?:eft|ight) (arm|hand|leg|eye)/
            Wounds.send("#{$1}#{$2}")
        elsif wound =~ /abdom/
            Wounds.send("abs")
        elsif wound =~ /nerve/
            Wounds.send('nerves')
        elsif wound =~ /(head|neck)/
            Wounds.send($1)
        elsif wound =~ /(chest|back)/
            Wounds.send($1)
        end
    }
    
    script.vars.shift
    until script.vars.empty?
    # This puts the name the user entered into a variable named 'target' (script.vars is the array of words the user gave us, and [1] means word 1; 'script.vars[2]' would ask for the second word the user gave the script, and so on).
    target = script.vars.shift
    fput "appraise #{target}"
    
    # Now we wait for the result of the 'appraise (person)' command by using 'waitfor', which takes as many lines to wait for as you want (there's no limit to how many). When it finds a line that contains one of the strings (a string is just text... this comment, for instance, is a 'string') you gave it, it returns the entire matching game line. So 'wound_line = waitfor' waits for a matching line, and then sticks the matching line into the 'wound_line' variable.
    wound_line = waitfor("Appraise what", "You take a quick appraisal of ")
    
    # The 'waitfor' command does it for you automatically, but if you want to test if a string has a certain snippet inside it or not (like 'hi there' contains the snippet 'there', etc.), the easiest way is to use a regular expression match -- there's a hundred useful ways to use regular expressions, but if you don't want to get complicated, you can just ignore them all (see the comments in 'spell-list.txt' in your Lich scripts directory for more info on regular expressions). In Lich, anything inbetween two '/' characters is made a regular expression, and you can match by using the '=~' operator. So that's what this next line is about... it literally means "if the line in the 'wound_line' variable contains 'Appraise what' somewhere in it" -- if you want to, you can also do the same thing by using labels and 'match' lines the way Wizard scripts do it instead of using the method seen here.
    if wound_line =~ /Appraise what/
        respond("Couldn't find the target! Are you sure '#{target}' is here...?")
        exit
    end
    
    # Here we exploit a feature of regular expressions, which is automatically setting certain variables based on a succesful regular expression match -- for instance, enclosing something in parentheses is a quick and easy way of 'slicing' out whatever is between the opening '(' and the closing ')'. Each one gets put into a matching '$1' or '$2' or however many you have (in the following, if we added a second set of characters inside parentheses, whatever was in that part of the sentence would be in '$2' for example). All this does is extract the person's full name and use that as the target, instead of the (probably abbreviated) name the user entered.
    if wound_line =~ /You take a quick appraisal of (\w+)/
        target = $1.dup
    end
    
    if wound_line.include?(',')
        wound_array = wound_line.split(/You take a quick appraisal of|,/)
    else
        wound_array = wound_line.scan(/a (?:blinded|swollen|bruised) (?:left|right) eye|deep lacerations across (?:his|her) \w+|deep gashes and serious bleeding (?:on|from|across) (?:his|her) \w+|minor cuts and bruises on (?:his|her) (?:left|right) (?:hand|arm|leg)|a (?:fractured and bleeding|completely severed) (?:left|right) (?:hand|arm|leg)|moderate bleeding from (?:his|her) neck|snapped bones and serious bleeding from the neck|minor bruises on (?:his|her) neck|minor (?:bruises|lacerations) about the head|minor cuts and bruises on (?:his|her) (?:chest|back|abdominal area)|severe head trauma and bleeding from the ears|strange case of muscle twitching|case of (?:sporadic|uncontrollable) convulsions/)
    end
    
    # This creates a new, empty array and puts it into the 'wounds' variable
    wounds = Array.new
    
    # This takes the line containing all the person's wounds that we've '.split' up into an array, and for '.each' value in the array, executes the entire block (as mentioned above, a 'block' is the code inside the squiggly brackets). We have to know how to refer to each value of the array uniquely, but we want to do the same exact thing for every one -- so when we declare the opening of the block with the squiggly '{' we also declare that inside the block, we want the current value to be in the variable 'wound'. That's what '|wound|' does.
    wound_array.each { |wound|
        if wound =~ /(a blinded|a swollen|a bruised|deep lacerations across his|deep lacerations across her|cuts and bruises on his|cuts and bruises on her|fractured and bleeding|completely severed|deep gashes and serious bleeding on his|deep gashes and serious bleeding on her|deep gashes and serious bleeding from his|deep gashes and serious bleeding from her) (\w+)( \w+)?/
            bodypart = "#{$2.dup} #{$3.dup}"
        elsif wound =~ /moderate bleeding from (his|her) neck|snapped bones and serious bleeding from the neck|minor bruises on (his|her) neck/
            bodypart = "neck"
        elsif wound =~ /minor bruises about the head|minor lacerations about the head|severe head trauma and bleeding from the ears/
            bodypart = "head"
        elsif wound =~ /strange case of muscle twitching|case of sporadic convulsions|case of uncontrollable convulsions/
            bodypart = "nerves"
        else
    # If this particular value in the array doesn't match any of the regular expressions above (again, see 'spell-list.txt' for details on regular expressions), then we don't know what wound it is and have no idea what to do with it -- so to avoid it being part of our finished wound stack (the 'wounds' array), we use the 'next' command, which skips anything else left inside a block and moves on to the next iteration (an 'iteration' is the name for each time the code inside a block is executed -- so skipping the rest of the code and moving to the next 'iteration', in this case, means just keep going and repeat the code block for the next value in the array).
            next
        end
    
    # Now that we've identified which wound we're dealing with (that's what the 'if/elsif' stuff above is about), we '.push' the result on to our 'wounds' array
        wounds.push(bodypart)
    }
    
    
    # Since the previous code block is pretty advanced compared to Wizard scripts, let me try to clarify: at this point in the script (when Lich has gotten to the line that this comment is on), the above code block has been executed for every value in the 'wound_array' variable. The 'wound_array' variable is, as the name suggests, an 'array' of values, and each value happens to be the description of a given wound ('a fractured and bleeding right leg', for instance). So for every one of those lines, the code block was executed, and each time the 'wound' variable was replaced with the current value. So if the wound_array was an array containing the strings, 'cuts and bruises on his left leg', and 'a fractured and bleeding right arm', the 'wound' variable would contain the string 'cuts and bruises on his left leg' the first time the block was executed, then the second time it was executed, the 'wound' variable would contain 'a fractured and bleeding right arm'. I hope that helps clear up what it did.
    
    # If the 'wound_array' variable was an empty array, or if none of the strings it contained could be identified as meaning a person had a certain wound, then our 'wounds' variable will be an empty array (because the 'wounds.push(bodypart)' line from the above code block never got to be executed). This just checks to make sure there's something inside 'wounds' for us to be working on.
    
    # This just creates yet another empty array, and sticks it into another variable (here we use 'to_heal'). If you haven't stumbled on the info yet, in Lich, you can create a variable with any name you want by doing this, and make it equal anything you want (just make sure you don't try to make a variable with the same name as a command, otherwise you're going to get cryptic-sounding errors about 'no method for =' and so forth).
    to_heal = Array.new
    
    # Now we again call '.each', but this time, we want to use the 'wounds' array. We again use the 'wound' variable for each value of the array, but we could make up any variable name we wanted -- 'thingiemajig', 'myvariable', 'you_suck', whatever name you want the variable to have, just as long as it's one word.
    wounds.each { |wound|
        wound = wound.split.join(' ')
        if wound =~ /(l|r)(?:eft|ight) (arm|hand|leg|eye)/
            to_heal.push(wound)
            if Wounds.send("#{$1}#{$2}") == 3
                healdown.call(wound)
            end
            fput "transfer #{target} #{wound}"
        elsif wound =~ /abdom/
            to_heal.push('abdomen')
            if Wounds.send("abs") == 3
                healdown.call('abdomen')
            end
            fput "transfer #{target} abdomen"
        elsif wound =~ /nerve/
            to_heal.push('nerves')
            if Wounds.send('nerves') == 3
                healdown.call('nerves')
            end
            fput "transfer #{target} nerves"
        elsif wound =~ /(head|neck)/
            to_heal.push($1)
            if Wounds.send($1) == 3
                healdown.call($1)
            end
            fput "transfer #{target} #{$1}"
        elsif wound =~ /(chest|back)/
            to_heal.push($1)
            if Wounds.send($1) == 3
                healdown.call($1)
            end
            fput "transfer #{target} #{$1}"
        end
    }
    =begin
    # Now we make a new variable called 'bloodline' and put an empty 'string' in it.
    bloodline = String.new
    
    # This is the same kind of concept as 'array.each' -- except 'until' keeps repeating code over & over again, without any limit to how many times, 'until' something is true. In this case, we ask it to repeat the code until the value of 'bloodline' is a string containing 'Nothing happens' or 'all', OR the value of 'health?' is less than or equal to 75 ('health?' is a Lich command which means your current health).
    until bloodline =~ /Nothing happens|all|want/
        if health? <= 75 or percenthealth < 51
            if mana?((maxhealth - health?) / 10)
                fput "prep 1101"
                fput "cure"
                sleep 3
                waitrt?
                next
            else
                respond("You have insufficient health to safely continue, and insufficient mana to heal yourself... please handle the situation manually.")
                break
            end
        end
    #    if health? <= 75
    #        respond("You have insufficient health to safely continue, and insufficient mana to heal yourself... please handle the situation manually.")
    #        break
    #    end
        fput "transfer #{target}"
        bloodline = waitfor "Nothing happens", "You take some", "You take all", "want"
    end
    
    # 'percenthealth' is another Lich command, and it's just the percentage of your current health. So now we say, "until we have 100% health, keep doing this over & over".
    while (health?.to_i != 0) and (health?.to_i < maxhealth.to_i)
        cost = (maxhealth - health?) / 10
        unless mana?(cost)
            respond("Insufficient mana, will continue when you have enough...")
            until mana?(cost)
                sleep 1
            end
        end
        fput "prep 1101"
        fput "cure"
        sleep 3
        waitrt?
    end
    end
    =end
    # And yet another 'array.each' section (as you might guess from how often I use it, it's *incredibly* handy -- it's also very easy for Lich to do, so it's *extremely* fast & *extremely* efficient, as well). Now this is where we really stick to that DRY concept (again, just stands for "Don't Repeat Yourself," which is a silly way of saying 'why write the same thing over & over when you could just write it once and reuse it?'). We keep calling those 'procedure objects' we defined above over & over, and giving them the current value of 'wound'.
    to_heal.each { |wound|
        until translate_wound.call(wound) == stop_at or translate_wound.call(wound) == 0
            healdown.call(wound)
        end
    }
    
    # And now we're done, so just point out to the user "hey, you there -- I'm finished. So, g'bye"
    respond "#{target} is fully healed."
    I visualize a time when we will be to robots what dogs are to humans, and I'm rooting for the machines. -- Claude Shannon

Similar Threads

  1. 5x/day Heal II
    By BriarFox in forum Flat Priced Sales
    Replies: 3
    Last Post: 04-10-2017, 03:58 PM
  2. Heal token
    By gs4-relvar in forum Wanted
    Replies: 0
    Last Post: 05-20-2011, 01:43 AM
  3. Heal down script.
    By silversurfer in forum Empath
    Replies: 4
    Last Post: 05-30-2006, 05:58 AM
  4. Self Mana Heal 2
    By bubbauno in forum GSIV Merchant's Market
    Replies: 12
    Last Post: 12-11-2005, 09:49 AM
  5. Heal an' run
    By 4a6c1 in forum General Gemstone
    Replies: 6
    Last Post: 09-17-2004, 10:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •