Page 5 of 6 FirstFirst ... 3456 LastLast
Results 41 to 50 of 55

Thread: sonic sword script need help

  1. #41

    Default

    Quote Originally Posted by Eliseen View Post
    I'm not sure what the vertical pipe is for |i| or the final / at the end are for
    When you're going through an array or hash (in this case GameObj.npcs array) you refer to each element of the array as something, in this case I chose i, but you can use whatever you want really.

    So you tell the script that for this block of code (everything within the {} brackets) that you will be referring to each element of the array as whatever is within the || symbols, in this case i.

    Now the script is going through each element of the array and referring to it as i and it's checking to see if i has the same name as what you specified in the first command line variable.

    What's being used here is a Regular Expression, or regex for short. You can use an exact match, for example if you watched to match "short sword" exactly you could do i.name == "short sword", so if the weapon name were "broad sword" it wouldn't match because it's not an exact match for "short sword".

    A regex lets you match things in a way that isn't an exact match. So you could do a regex for a match of "sword" and it would match both a "short sword" and a "broad sword." To do a regex you do something like

    if i.name =~ /sword/

    There's a lot more to regexes than this but that's the general gist of it.

    Quote Originally Posted by Eliseen View Post
    Wait are /text/ the same as "text"
    You would use two equal signs and quotes if you want an exact match:

    if example_variable == "text"

    Would mean you're checking if the variable example_variable were an exact match for "text."

    A regex would be written as:

    if example_variable =~ /text/

    Would mean as long as example_variable contained the letters "text" in that exact order anywhere then it would be a match.

    So if example_variable were set to "this is a whole lotta text!"

    Then using the examples above it would not be an exact match via using == because "this is a whole lotta text!" doesn't match "text" exactly.

    However if you were using the regex it would be a match because the word "text" appears somewhere in the variable. You have to be careful with regexes because it might match something you're not even thinking about. For example if you were looking for "text" but the variable had the word "context" in it then it would still match because "text" appears in the word "context."

  2. #42

    Default

    Hi there, I've a better understanding of of regex's A lot different than HTML, Basic or even SF scripting. Everything seems to work except enemy recognition. Sometimes you have to manually execute an attack command. I'm studying the code to see if I put something in the wrong order. at first I thought it might be "ghostly pooka" then I tried with "pooka" and of course "Pooka" as you said it's not case sensitive. (I use pookas as test base for the code.)

    Anyway, I'll let you know if I find anything, but any suggestions would be helpful.

    Eliseen

  3. #43

    Default

    Quote Originally Posted by Eliseen View Post
    at first I thought it might be "ghostly pooka" then I tried with "pooka" and of course "Pooka" as you said it's not case sensitive.
    By default regexes are case sensitive.

    However if you do:

    if example_variable =~ /text/i

    Notice the i at the very end there, then it's not case sensitive.

  4. #44

    Default

    So let me know if this sounds correct.

    In the forth regex where it stops attacking if someone is already in the room, where (or when) is checkpcs cleared or nulled?

  5. #45

    Default

    Well the last two bugs I can't figure out, I've tried rearranging the coding blocks and checked spelling, syntax (as best I can) and still can't get it to work right. It still won't target the entered critters and when it stops due to travel or entering an already occupied room won't reengage (call it maverik). I'm about to let folks try it out and see if anyone can figure out why it's not performing as I planned. Thanks for your help Tgo01.

    With a little help from Tysong a bit of tweeking and it works like a champ now. Have at it bards.
    Last edited by Eliseen; 01-22-2021 at 03:38 PM.

  6. #46

    Default

    So here it is. I named it ssword.

    current_room = Room.current.id
    target_id = nil
    =begin
    ### Singing Sword utility Ver 1.0 Eliseen Starfriend
    ### Many thanks to Tgo01 who was instrumental in writing this script as I know nothing about Ruby
    ### Instructions command format Ssword Var1 var2 var3
    ### Var1 is then name of the item you wish to create.
    ### Var2 is the name of a primary critter that you may be hunting
    ### Var3 is the name of a secondary critter you may encounter in your hunt
    ### This script will cease attacking if entering a room all ready occupied.
    ### If you Sonic weapon this script will recall it to your location.
    ### Use ;K ssword to exit properly.
    ### Caution this script when activated will emulate the commands you may use manually while you hunt.
    ### Remember the rules no AFK while using this script.

    ### Singing Sword Utility Ver 1.1
    ### This script will stand you up if knocked down.
    ### Added section to end script if you die.
    ### Will ensure correct number of variables.
    =end

    if script.vars[3].nil?
    echo "You need 3 variables."
    exit
    end

    before_dying{
    waitrt?
    fput "say goodbye #{script.vars[1]}"
    fput "stop 1025"
    }

    def stand()
    until (standing?)
    waitrt?
    fput "stand"
    end
    end
    fput "spell active"
    loop{
    if checkmana <= 50
    fput "stop 1025"
    echo "Running low on mana."
    wait_until { checkmana(90) }
    end
    stand
    if !Spell[1025].active? && checkmana>(90)
    fput "spell active"
    sleep 1
    Spell[1025].cast(script.vars[1]) if !Spell[1025].active?
    end

    fput "tell weapon to return" if Spell[1025].active? && !GameObj.npcs.find{ |i| i.name =~ /#{script.vars[1]}/ }
    target = GameObj.targets.find{|i| i.name =~ /#{script.vars[2]}|#{script.vars[3]}/i }
    if target_id != target.id
    fput "tell weapon to attack #{target}"
    target_id = target.id
    end
    exit if dead?
    if Room.current.id != current_room
    current_room = Room.current.id
    fput "tell weapon to cease" if checkpcs
    end

    if running? "go2"
    fput "tell weapon to cease"
    wait_while{ running? "go2" }
    end

    sleep 0.5
    }
    Last edited by Eliseen; 01-22-2021 at 03:39 PM.

  7. #47

    Default

    ssword.lic uploaded to repo

  8. #48

    Default

    Quote Originally Posted by Eliseen View Post
    So let me know if this sounds correct.

    In the forth regex where it stops attacking if someone is already in the room, where (or when) is checkpcs cleared or nulled?
    checkpcs is a built in Lich array that is constantly updated.

  9. #49

    Default

    I tried using parenthesis around both variables and having the # (only one) inside the parenthesis. I was close. Now if I can figure out why it's not seeing the song correctly and not have to do spell active. A little at a time eh?

  10. #50

    Default

    Quote Originally Posted by Eliseen View Post
    I tried using parenthesis around both variables and having the # (only one) inside the parenthesis. I was close. Now if I can figure out why it's not seeing the song correctly and not have to do spell active. A little at a time eh?
    Yeah I’m not sure what it’s doing that. Very weird.

Similar Threads

  1. Replies: 1
    Last Post: 12-25-2018, 04:16 PM
  2. Replies: 5
    Last Post: 10-06-2015, 08:57 PM
  3. 7x Two Handed Sword & 7x Heimer Script Staff
    By vamosj in forum High-End Valuables
    Replies: 5
    Last Post: 08-21-2013, 12:49 PM
  4. Sonic Armor question & sonic alteration...
    By nocturnix in forum Bard
    Replies: 28
    Last Post: 02-25-2013, 07:18 PM
  5. Sonic Alterations
    By Danical in forum Bard
    Replies: 34
    Last Post: 04-29-2009, 11:13 PM

Tags for this Thread

Posting Permissions

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