View Full Version : sonic sword script need help
Eliseen
01-01-2021, 05:58 PM
As a Bard we get an animated sword, one of the issues is stopping in the middle of a hunt to execute a command. The commands are pretty basic but I wanted to make using the Singing Sword a bit more controllable. for instance if you walk into a room and other players are there It should CEASE it's attack, If it gets stuck somewhere to have it RETURN. Also a Bard may be singing a bunch of songs so a check to see if mana was low. I tried using strormfront scripts but saw Lich had some handles that would do this easily. So I tried to convert my script to Lich and here is my result:
## Singing sword utility script
## var variable is weapon type or hard code in weapon type in line 6
## If weapon is hard coded, change weapon type in Missing subroutine line 26
## Ver 1.0 usable in WL Gaveyard against Pookas and Spectral miners
## Start Singing Sword
fPut Prep 1025
@variable[1] = 'value'
fPut SING variable[1]
#Main loop
Start
If GameObj.npcs.find { |npc| (npc.status !~ /dead/) && (npc.type =~ /aggressive/) }= Spectral Miner then fput TELL WEAPON TO ATTACK Spectral miner
If GameObj.npcs.find { |npc| (npc.status !~ /dead/) && (npc.type =~ /aggressive/) }= Ghostly pooka then fput TELL WEAPON TO ATTACK Ghostly Pooka
if GameObj.pcs == 1 Occupied
match Missing Animated variable[1]
match traveling Lich: go2 active.
if upstream_get =”exit” end
matchwait
goto start
# If Sword not present
Missing:
if checkspell "Singing Sword" fput TELL WEAPON TO RETURN else goto sing
goto start
# Song not being sung
sing:
fPut Prep 1025
fPut SING variable[1]
goto start
# if room is occupied
Occupied:
If GameObj.pcs == 0 fput TELL WEAPON TO CEASE else NEXTROOM
goto start
# Check mana level
Mana:
put mana
if checkmana <=50 fput Stop 1025
echo not enough Mana avalable.
wait_until { mana(90} goto start
goto start
# Go2 Traveling
traveling:
fput TELL WEAPON TO CEASE
wait_until Lich: go2 has exited.
Goto start
Well as you can see it doesn't even get to singing the song before it errors out. Would one of you all take a look and help me correct my errors?
Thanks
Tgo01
01-01-2021, 07:03 PM
I think this will do what you're looking for:
current_room = Room.current.id
target_id = nil
loop{
if checkmana <= 50
fput "stop 1025"
echo "Running low on mana."
wait_until { checkmana(90) }
end
Spell[1025].cast(script.vars[1]) if !Spell[1025].active? && checkmana(90)
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 =~ /miner|pooka/i }
if target
if target_id != target.id
fput "tell weapon to attack #{target}"
target_id = target.id
end
end
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
}
You're gonna have to play around with it a bit to be sure because I didn't test everything.
You can start it like:
;sonic lance
For example if you want to use a sonic lance.
Or:
;sonic broadsword
For a broadsword and etc etc.
Eliseen
01-01-2021, 08:08 PM
Except for trying to cast 1025 continuously it works. My programming was all in basic, I can follow your structure. I think the problem is that casting the spell is inside the primary loop. So to correct this put the statement Spell[1025].cast(script.vars[1]) outside the primary loop and just do an if-then statement but I've no idea the correct format for that type of statement in Ruby.
Tgo01
01-01-2021, 08:30 PM
It should only cast 1025 if 1025 is not active which is kept track by ;magic.
Do you have a custom prep message or something for 1025 that would make it so Lich wouldn’t recognize it being cast?
Eliseen
01-01-2021, 08:58 PM
the actual terms are prep 1025 (obviously) and Sing weapon type. Using cast works the sword appears, but every time the loop repeats it tries to prep the song again.
Tgo01
01-01-2021, 09:02 PM
Yeah Spell[1025].cast does all of that and Lich should track that the spell is active unless you have a custom spell message when casting it or something because Lich looks for the standard cast line to see if the spell was cast.
Eliseen
01-01-2021, 09:10 PM
the actual terms are prep 1025 (obviously) and Sing weapon type. Here is a capture of the spell veing cast:
prepare 1025
You begin your musical chant for Singing Sword Song...
Your spellsong is ready.
>
[sss]>cast longsword
You sing a melody.
An animated longsword appears and hovers near you.
Sing Roundtime 3 Seconds.
Tgo01
01-01-2021, 09:14 PM
Yeah that's the standard messaging.
With 1025 going does it show up when you do ;magic?
Eliseen
01-01-2021, 09:17 PM
You'll love this:
>;magic?
- Minor Spirit:
101: Spirit Warding I - 0:41:01
104: Disease Resistance - 0:40:21
105: Poison Resistance - 0:40:23
107: Spirit Warding II - 0:46:18
112: Water Walking - 0:46:20
- Minor Elemental:
401: Elemental Defense I - 0:44:21
406: Elemental Defense II - 0:44:23
414: Elemental Defense III - 0:38:54
- Major Elemental:
503: Thurfel's Ward - 0:41:52
509: Strength - 0:41:54
- Ranger:
601: Natural Colors - 0:38:55
602: Resist Elements - 0:40:59
618: Mobility - 0:41:04
- Wizard:
911: Mass Blur - 0:38:58
- Minor Mental:
1204: Foresight - 0:39:42
1208: Mindward - 0:39:43
- Armor Specialization:
9504: Armor Support - 0:31:18
Eliseen
01-01-2021, 09:18 PM
And I do have a sonic sword following me around.
Tgo01
01-01-2021, 09:19 PM
This should fix it so ;magic recognizes when 1025 is active, if not then I don't know what's going on:
current_room = Room.current.id
target_id = nil
loop{
if checkmana <= 50
fput "stop 1025"
echo "Running low on mana."
wait_until { checkmana(90) }
end
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 =~ /miner|pooka/i }
if target
if target_id != target.id
fput "tell weapon to attack #{target}"
target_id = target.id
end
end
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
}
Eliseen
01-01-2021, 09:34 PM
Ok, so when I ran it I didn't get the problem as before, it does two spell active commands the first before the song is sang and after it's sang. The only difference is this line:
Singing Sword Song ................. 0:06:22 and it lists all the spells I'm currently using.
Eliseen
01-01-2021, 09:59 PM
does it make any difference what the sword is in the room description? for instance if I "sing longsword" I will see "an animated longsword" if I "sing mace" I see "An animated mace" appears and hovers near you. and it's reflected in the room description.
Tgo01
01-01-2021, 10:12 PM
does it make any difference what the sword is in the room description? for instance if I "sing longsword" I will see "an animated longsword" if I "sing mace" I see "An animated mace" appears and hovers near you. and it's reflected in the room description.
The script checks for however you started the script. So if you started it with ;sonic mace it should check the room for a mace.
If you mean for ;magic it shouldn’t matter, the spell is called singing sword and always shows up as that no matter what you sing.
Eliseen
01-02-2021, 09:58 AM
So I went hunting with the script you prepared (the second one) and it performed excellently. When I traveled by go2 and the sword got lost the script would do as followqs:
>tell weapon to return
You project your command for your animated longsword to return. The air beside you begins to distort, rapidly forming into an animated longsword.
When a critter came in the sword would respond immediately with:
>tell weapon to attack pooka
You project your wish for harm to the ghostly pooka, and your animated longsword begins to respond.
If I entered an area where there were other folks I'd get:
>tell weapon to cease
You project to your animated longsword your desire that it cease its current endeavor.
The script would occasionally spit out the >spell active Command but that was few and far between. I only made one change and it was in this line:
if !Spell[1025].active? && checkmana>(90)
I added the greater than symbol as my mana would usually stay above 90 mana. The one think I think it needs is an embedded command to stop the script. I'm not sure if the upstream_get? command would be the one to use or something else.
Eliseen
01-02-2021, 04:51 PM
So these are the parts I'm going to add:
###Makes sure you are standing before continuing.
def this_script_stand_me
until standing?
waitrt?
fput "stand"
end
###Code to stop spell song and exit script.
toggle_upstream
command = upstream_get
if (command =~ /\b(say goodby sword?)i \b$/)fput “Stop 1025”
break
end
Also change this line
target = GameObj.targets.find{|i| i.name =~ /miner|pooka/i }
to
target = GameObj.targets.find{|i| i.name =~ /script.vars[2]|script.vars[3]/i }
and add to the beginning
###Instrunction Var1=weapon, var2=primary critter, var3=secondary critter
This would allow critters to be defined when starting the script
Look this over and let me know if there's anything I missed. Thanx
Tgo01
01-02-2021, 05:02 PM
If you're calling the this_script_stand_me method within the loop then it should work.
The easiest way to exit the script is to do ;k sonic (or whatever you named your script.) You could use before_dying to have the script do stuff before it exits.
For example before the loop add:
before_dying{
waitrt?
fput "say goodbye sword"
fput "stop 1025
}
That way when you do ;k sonic it will still have your character say "goodbye sword" and then do "stop 1025"
You would want to do target = GameObj.targets.find{|i| i.name =~ /#{script.vars[2]}|#{script.vars[3]}/i }
Eliseen
01-02-2021, 05:20 PM
I liked your idea with ;k ssword (that's it's name) soI incorporated it. So here it is in all it's glory. I'll test it this afternoon after I get spelled up and let you know how it ran.
current_room = Room.current.id
target_id = nil
### Singing sword utility Ver 1.0
### Many thanks to Tgo01 who was instrumental in writing this script as I know nothing about Ruby
### Instructions comand 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
### 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.
before_dying{
waitrt?
fput "say goodbye sword"
fput "stop 1025
}
loop{
if checkmana <= 50
fput "stop 1025"
echo "Running low on mana."
wait_until { checkmana(90) }
end
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
if target_id != target.id
fput "tell weapon to attack #{target}"
target_id = target.id
end
end
def this_script_stand_me
until standing?
waitrt?
fput "stand"
end
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
}
Thank you....
Eliseen
01-02-2021, 06:00 PM
Ok so I'm getting some errors. They look like syntax to me:
--- Lich: error: ssword:33: syntax error, unexpected keyword_end, expecting '}'
end
^~~
ssword:51: syntax error, unexpected '}', expecting keyword_end
C:/Users/Desktop/lich/lich.rbw:2526:in `eval'
C:/Users/Desktop/lich/lich.rbw:2526:in `block (2 levels) in <class:Script>'
I counted and matched all parenthesis {} & () and removed the extra "if target" from the above script and the extra "end" that sectioon now reads:
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 }
end
if target_id != target.id
fput "tell weapon to attack #{target}"
target_id = target.id
def this_script_stand_me
until standing?
waitrt?
fput "stand"
end
Let me know what else I should be looking for
Tgo01
01-02-2021, 06:26 PM
current_room = Room.current.id
target_id = nil
### Singing sword utility Ver 1.0
### Many thanks to Tgo01 who was instrumental in writing this script as I know nothing about Ruby
### Instructions comand 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
### 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.
before_dying{
waitrt?
fput "say goodbye sword"
fput "stop 1025
}
def this_script_stand_me
until standing?
waitrt?
fput "stand"
end
end
loop{
if checkmana <= 50
fput "stop 1025"
echo "Running low on mana."
wait_until { checkmana(90) }
end
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
if target_id != target.id
fput "tell weapon to attack #{target}"
target_id = target.id
end
this_script_stand_me
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
}
Eliseen
01-02-2021, 07:22 PM
first run through..... Creates weapon of choice.
Second test.... I lay down to see if script killer(?) worked. entering command ;k ssword did evoke the proper response.
First issue, I tried to restart the script again right after killing it and got this:
;ssword longsword pooka miner
--- Lich: ssword active.
[ssword]>tell weapon to return
You don't even have one!
>
[ssword]>tell weapon to return
You don't even have one!
The one thing I noticed was that I had just a few moments ago dismissed the sword. Even though it wasn't in the room Uberspells showed a few minutes left on the song. Did a kill again and got the message the script wasn't running, ran a few checks:
>;list
--- Lich: narost, dreavening, uberbounty
>;listall
--- Lich: narost, dreavening, uberbounty, infomon, lnet, keepalive, uberbar, uberspells, sexual-favors, inspectweight, group_ajar, sorter
>spell active
You currently have the following active spells:
No spells found.
But was still showing up on uberspells. Waited for the counter to go away and tried again and script ran properly.
I don't know if you get knocked down and laying down are the same thing....I also ran the script and standing drank some death rum (which stuns you and you fall over). I was never pulled to a standing position.
I ran a quick test to see if it performed correctly in the field and saw a strange exchange:
[go2]>west
[Lower Dragonsclaw, Forest]
The underbrush is quite thick here near the forest's edge, forcing you to slow your steps as you maneuver through the trees. You also see a rolton, a vine-covered arch and a briar patch.
Obvious paths: north, east, southwest, west
Your animated longsword followed.
>
[go2]>southwest
[ssword]>tell weapon to return
Should there be an "end" at the end of this line? fput "tell weapon to return" if Spell[1025].active? && !GameObj.npcs.find{ |i| i.name =~ /#{script.vars[1]}/}
Eliseen
01-02-2021, 07:24 PM
first run through..... Creates weapon of choice.
Second test.... I lay down to see if script killer(?) worked. entering command ;k ssword did evoke the proper response.
First issue, I tried to restart the script again right after killing it and got this:
;ssword longsword pooka miner
--- Lich: ssword active.
[ssword]>tell weapon to return
You don't even have one!
>
[ssword]>tell weapon to return
You don't even have one!
The one thing I noticed was that I had just a few moments ago dismissed the sword. Even though it wasn't in the room Uberspells showed a few minutes left on the song. Did a kill again and got the message the script wasn't running, ran a few checks:
>;list
--- Lich: narost, dreavening, uberbounty
>;listall
--- Lich: narost, dreavening, uberbounty, infomon, lnet, keepalive, uberbar, uberspells, sexual-favors, inspectweight, group_ajar, sorter
>spell active
You currently have the following active spells:
No spells found.
But was still showing up on uberspells. Waited for the counter to go away and tried again and script ran properly.
I don't know if you get knocked down and laying down are the same thing....I also ran the script and standing drank some death rum (which stuns you and you fall over). I was never pulled to a standing position.
I ran a quick test to see if it performed correctly in the field and saw a strange exchange:
[go2]>west
[Lower Dragonsclaw, Forest]
The underbrush is quite thick here near the forest's edge, forcing you to slow your steps as you maneuver through the trees. You also see a rolton, a vine-covered arch and a briar patch.
Obvious paths: north, east, southwest, west
Your animated longsword followed.
>
[go2]>southwest
[ssword]>tell weapon to return
Should there be an "end" at the end of this line? fput "tell weapon to return" if Spell[1025].active? && !GameObj.npcs.find{ |i| i.name =~ /#{script.vars[1]}/}
With the test of restarting the script right after killing it, I started and stopped the script that I used earlier today and under the same conditions started the script. It did the same thing as the complete script. I also saw the following:
Also here: Averlee
Obvious exits: none
Your animated longsword followed.
>
[ssword]>tell weapon to return
Your animated longsword bobs in the air next to you.
I didn't get the message that the sword was ceasing attacking anything. Perhaps it has to attack something first...
Tgo01
01-03-2021, 12:54 AM
[ssword]>tell weapon to return
You don't even have one!
You could add this line before the loop:
fput "spell active"
I'm not sure why ;magic isn't picking up on whether or not you have 1025 running but spell active fixes it.
Should there be an "end" at the end of this line? fput "tell weapon to return" if Spell[1025].active? && !GameObj.npcs.find{ |i| i.name =~ /#{script.vars[1]}/}
An end isn't needed for this line.
I didn't get the message that the sword was ceasing attacking anything. Perhaps it has to attack something first...
Did you start the script with the person already in the room with you? The script as written wouldn't tell the sword to cease in that case.
Eliseen
01-03-2021, 01:17 AM
In line 34 there is the fput"spell active".
so out hunting: mana ws low so it did kill 1025.
>
[ssword]>stop 1025
[ssword: Running low on mana.]
[ Song of Mirrors: +0:06:07, 0:06:07 remaining. ]
Your animated longsword dissipates in a shower of sparkling motes of light.
You stop singing Singing Sword Song.
so I went and set down to wait to see what happened while I waited on mana:
You sit down.
s>
[ssword]>tell weapon to return
You don't even have one!
s>
started to scroll a lot finally did this:
s>
[ssword]>tell weapon to return
You don't even have one!
s>
[ssword]>spell active
You currently have the following active spells: listed all my spells
then did this:
s>
[ssword]>prepare 1025
You change your tune slightly, adding the element for Singing Sword Song to your song...
Your spellsong is ready.
s>
[ssword]>cast longsword
You weave another verse into your harmony.
An animated longsword appears and hovers near you.
Sing Roundtime 3 Seconds.
s>
[ssword]>spell active
You currently have the following active spells:
also I did hunt some pookas, this was the command I executed before hunting: ;ssword longsword pooka miner
Strangly the sword did not attack any critters (yes pookas)
Tgo01
01-03-2021, 01:26 AM
In line 34 there is the fput"spell active".
But that's only called if 1025 isn't active and since your ;magic thinks 1025 is active even when it isn't you would need to do a spell active outside of the loop so the script starts out knowing whether or not 1025 is active.
Eliseen
01-03-2021, 01:26 PM
I put the command before the loop and it still does weird things. I wonder if there is a bug in singing sword.
by the way is this correct?
if target
if target_id != target.id
fput "tell weapon to attack #{target}"
target_id = target.id
end
Tgo01
01-03-2021, 05:14 PM
I put the command before the loop and it still does weird things. I wonder if there is a bug in singing sword.
by the way is this correct?
if target
if target_id != target.id
fput "tell weapon to attack #{target}"
target_id = target.id
end
Looks correct.
Eliseen
01-03-2021, 08:39 PM
I just wish I knew Ruby scripting. Some of the syntax really is strange != == #
I mean what the heck does this mean =~ /#
I'm used to Unix a bit of linx HTML Basic (used to know machine language) but the use of symbols is maddening.
I've been wondering if a singing sword is coded similarly to a familiar. is if an NPC/obj/fam. is there a command like a one liner that I could run to verify what is in the room with me?
Tgo01
01-03-2021, 09:08 PM
Some of the syntax really is strange != == #
Typically when you see an ! within Ruby it means the opposite or negates what you're doing.
For example if you wanted to see if two values were the same you would do:
fput "wave" if number1 == number2
But if you wanted to see if two values were NOT the same you would do:
fput "wave" if number1 != number2
== is making a comparison between two values, similar to what I did above.
So for example if you set the variable number to equal the number 4 you would do:
number = 4
If you then wanted to see if two values were the same you would do:
fput "wave" if number == 4
I mean what the heck does this mean =~ /#
Doing something like
if line =~ /text entered here/
Is called a Regular Expression, or Regex. It's used when you don't want an exact match.
For example if you did:
if line == "text entered here"
Then it would only be a match if the line were exactly "text entered here", no more and no less.
If you used:
if line =~ /text entered here/
Then this text could appear anywhere within the line and it would be a match. It also allows you to do other things such as:
if line =~ /text .* entered here/
Where . is a wildcard and * means 0 or more matches, that way if you're not sure if there is anything between the words "text" and "entered" it can match it.
Typically when you're using a variable within quotes or regex you use a # sign and put {} around it.
So if you're using a variable named person you would do:
fput "wave at #{person}"
Same if you're trying to match a variable within a regex.
fput "wave" if line =~ /#{person}/
Eliseen
01-05-2021, 09:51 AM
It's me again. I've muddled through the script and so far I've gotten positive results.
Sings the weapon of your choice. and puts goodbye (what ever your choice was)
When entering a room occupied it ceases activity.
While script is running stands you back up if your knocked down. (forgot to put the stand command in the loop)
It no longer tries to recall the sword while wall walking around or during the go2 script.
I still need more testing in the attack department and will keep you updated.
By the way, as you know armor hindrance can cause a song not to be sung, is there a line that can be added to resing if it fails on armor hindrance?
Tgo01
01-05-2021, 05:10 PM
Using Spell[1025].cast automatically checks for spell failures and will recast.
Eliseen
01-05-2021, 06:53 PM
Ok, figured something else out, forgot to add weapon type so only had two variables.
That's why the script started to try and recast.
Would this work:
If script.vars[3]=="" then fput "You need 3 variables!" break
added just after the line: target_id = nil and just before the comments?
Tgo01
01-05-2021, 11:07 PM
If you want to see if a variable doesn't have a value you can use nil.
So you could do:
if script.vars[3].nil?
echo "You need 3 variables."
exit
end
Eliseen
01-05-2021, 11:21 PM
Thanks, I'm slowly getting the hang of this. I was wanting to try the script out walking around town. So not to attack anyone's pets or familiars or such chose bats and balls as the critters. Forgot to add in a weapon, singing sword does not recognize bats as a weapon. It failed to cast twice (armor hindrance it said rolled a 7 and a 1) finally pulled up a broadsword as default.
I figure if you do like I did and forgot to enter a weapon you would only have 2 variables # 3 would be nil, If you forgot all variables again #3 would be nil. Sort of a catch all. So I got all spelled up this evening so first thing in the morning I'm going to try it out. I think I may have all the bugs worked out, at least I hope so. Darn near ver 1.1.
Again much thanks.
Eliseen
01-11-2021, 04:49 PM
Ok found a little glitch. If you die well it sort of goes off the deep end. How's this look
if checkdead.nil?
echo "program exiting."
exit
end
And that would be in the main loop correct?
Eliseen
01-11-2021, 04:50 PM
Ok found a little glitch. If you die well it sort of goes off the deep end. How's this look
if checkdead.nil?
echo "program exiting."
exit
end
And that would be in the main loop correct?
Tgo01
01-11-2021, 05:50 PM
Yeah just do:
exit if dead?
Eliseen
01-19-2021, 03:54 PM
I've sent you a copy of the sonic sword script for your review. All parts seem to work (I haven't died to test that part out {yet}) If you can look it over and if you see where any improvements can be made or alterations or scripting errors. I've got all of them out. let me know if you think it's ready to share.
Eliseen
Tgo01
01-19-2021, 05:48 PM
I've sent you a copy of the sonic sword script for your review. All parts seem to work (I haven't died to test that part out {yet}) If you can look it over and if you see where any improvements can be made or alterations or scripting errors. I've got all of them out. let me know if you think it's ready to share.
Eliseen
Looks good to me.
Eliseen
01-19-2021, 07:25 PM
I'm trying to understand the main attack sequence this is my English translation of the first line:
fput "tell weapon to return" if Spell[1025].active? && !GameObj.npcs.find{ |i| i.name =~ /#{script.vars[1]}/ }
send command "tell weapon etc" if spell 1025 is active and gameobj.npcs.find {|I| (looks to see if i.name appears somewhere in #{variable (script.vars[1]}
I'm not sure what the vertical pipe is for |i| or the final / at the end are for
Wait are /text/ the same as "text"
Tgo01
01-19-2021, 10:18 PM
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.
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."
Eliseen
01-20-2021, 02:59 PM
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
Tgo01
01-20-2021, 06:32 PM
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.
Eliseen
01-21-2021, 11:28 AM
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?
Eliseen
01-22-2021, 12:32 PM
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.
Eliseen
01-22-2021, 02:02 PM
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
}
Eliseen
01-22-2021, 05:36 PM
ssword.lic uploaded to repo
Tgo01
01-22-2021, 06:22 PM
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.
Eliseen
01-22-2021, 09:48 PM
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?
Tgo01
01-22-2021, 09:49 PM
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.
Eliseen
01-23-2021, 12:18 PM
Over on discord I was given this link:
https://discordapp.com/channels/226045346399256576/387286877327065108/796113798443565056
I went and did like the instructions said and then Rem'ed out the fput "spell active" commands. The script seems to work with out them now.
Tgo01
01-23-2021, 06:36 PM
Over on discord I was given this link:
https://discordapp.com/channels/226045346399256576/387286877327065108/796113798443565056
I went and did like the instructions said and then Rem'ed out the fput "spell active" commands. The script seems to work with out them now.
That’s awesome.
Eliseen
01-23-2021, 11:10 PM
I did find out something today. I think it might be a probelm with my ISP, lag was real bad and it seemed to mess up the script. I need to study that more in depth.
Eliseen
01-26-2021, 12:28 PM
so if you put a sleep .1 how long is that 1 second?
Tgo01
01-26-2021, 06:15 PM
so if you put a sleep .1 how long is that 1 second?
Sleep 0.1 is .1 seconds.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.