![](templates/Classic/images/spacer.gif) |
Neo2121 Beginner
Joined: 28 Dec 2006 Posts: 12
|
Posted: Mon Oct 08, 2007 1:23 pm
Capturing text based on ANSI color |
The mud i'm playing on, Achaea, doesn't use any linebreak between the room description and the items/people inside it. It does however color them differently
What I'm trying to do is make a script that detects where the items/people part of the room starts, separate players from items or objects ( they all have different colors ) and display them in a window that you can just hit a button and update.
The problem is how do i get zMud to recognise where the different coloured text starts and ends...
Here's a sample from the mud output:
Dockhand Square.
The stars twinkle in the clear night sky. Sailors stand about the large square looking for ships that need crew members. Several of them are tying intricate knots to sell at the marketplace as jewellery or household decorations. A mosaic of a giant sailing ship has been built into the stones of the square. The grand ship, a blue schooner, is riding a giant wave sending its bow high into the sky. Its masts are full and blowing out with a huge gust of wind. A storm breaks overhead with spears of lightning threatening the tallest of the schooners masts. A beautiful mermaid, in exquisite detail, adorns the bow of the ship. She has flowing green hair and a bright red tail. There are detailed depictions of the ships crew trying to keep the boat upright on the vicious wave. No two sailors on the schooner are alike. The mosaic is so large that one almost has to be high above it to actually see the whole picture at one time. The slums of the city of Ashtan, Martin's Sorrow are to the far east, on the other side of Caspian's Walk. The homes of the middle class are directly to the south while the famous marketplace of Ashtan is even further south. Ships of every description are tied up along the docks to the north. The Ratman stands here quietly. A sewer grate looms darkly beneath your feet. A cute little humgii is sitting here placidly, attached to a leash. There are 17 War Witches here. A runic totem is planted solidly in the ground. There are 3 Knights of the Illuminati here. An elegant white letter is in danger of being soiled here. A canvas backpack lies face-down here. Deshi Henso is here, sprawled on the floor.
(i just need to figure out how 2 grab just the dark blue part) |
|
|
![](templates/Classic/images/spacer.gif) |
Fang Xianfu GURU
![](images/avatars/1763170544a2093e7e85da.gif)
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Oct 08, 2007 2:13 pm |
Take a look at this by Larkin - it uses ANSI colour to detect the room parts and build a proper description.
The basic principle is that you use an ANSI trigger that fires on the ANSI codes the MUD is sending. For that, you need to know the exact code the MUD is sending ("blue" isn't specific enough). Use the #debug command to create a human-readable log of a room and post that, and we'll be able to help more. You can also create a trigger using the settings editor GUI, check the ANSI trigger option, and then paste the description into the pattern box. This'll create the %e[whatever codes for you.
This problem'll also be much easier if you have wordwrap 0 set. I assume from your posted text that you do, but if you don't, turn it on. Then the trigger'll be as simple as:
#trig {%e[35m*%e[34m(*)$} {#var RoomContents {%1}}
Though the numbers will be different depending on the codes the MUD sends. |
|
|
![](templates/Classic/images/spacer.gif) |
Neo2121 Beginner
Joined: 28 Dec 2006 Posts: 12
|
Posted: Mon Oct 08, 2007 3:13 pm |
Thank you for your very detaliled reply I'll give it a shot and post back if i have any problems.
|
|
|
![](templates/Classic/images/spacer.gif) |
Neo2121 Beginner
Joined: 28 Dec 2006 Posts: 12
|
Posted: Mon Oct 08, 2007 9:10 pm |
Gah.. can't seem to get it to match properly.. The mud has wordwrapping OFF, but i do have it turned on in zMud from preferences, my guess is it doesn't affect it (or at least i hope it doesn't). In any case, here's a raw room description from the mud. I just can't seem 2 get around all the symbols required to make it work properly, and when i do capture something in the variable it takes the whole line, not just the part i need
Code: |
[33mDockhand Square.
[37m[36mThe bright sun shines down, blanketing you with its life-giving warmth.[37m Sailors stand about the large square looking for ships that need crew
members. Several of them are tying intricate knots to sell at the marketplace as jewellery or household decorations. A mosaic of a giant sailing ship has been
built into the stones of the square. The grand ship, a blue schooner, is riding a giant wave sending its bow high into the sky. Its masts are full and blowing out
with a huge gust of wind. A storm breaks overhead with spears of lightning threatening the tallest of the schooners masts. A beautiful mermaid, in exquisite
detail, adorns the bow of the ship. She has flowing green hair and a bright red tail. There are detailed depictions of the ships crew trying to keep the boat
upright on the vicious wave. No two sailors on the schooner are alike. The mosaic is so large that one almost has to be high above it to actually see the whole
picture at one time. The slums of the city of Ashtan, Martin's Sorrow are to the far east, on the other side of Caspian's Walk. The homes of the middle class are
directly to the south while the famous marketplace of Ashtan is even further south. Ships of every description are tied up along the docks to the north.[36m The
Ratman stands here quietly.[37m[36m A sewer grate looms darkly beneath your feet.[37m[36m A cute little humgii is sitting here placidly, attached to a
leash.[37m[36m There are 17 War Witches here.[37m[36m A runic totem is planted solidly in the ground.[37m[36m There are 3 Knights of the Illuminati
here.[37m
[1;34mYou see exits leading[0;37m[1;34m north, northeast (open door), east, southeast (open door), south (open door), southwest, west, northwest, and in (open
door).
|
EDIT: silly forum won't display it properly, I upped it here in a txt file too: http://www.nio.as.ro/test.txt |
|
|
![](templates/Classic/images/spacer.gif) |
Fang Xianfu GURU
![](images/avatars/1763170544a2093e7e85da.gif)
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Oct 08, 2007 9:16 pm |
Pasting the line into an ANSI trigger is more reliable because CMUD's ANSI triggers don't fire on exactly the codes that're sent from the MUD, but on a simplified version, since ANSI codes can be inserted by the MUD anywhere, but be invisible to the client. Some MUDs used to add random codes to throw off triggers. You're probably looking for a pattern like %e[37m*%e[36m(*).
|
|
|
![](templates/Classic/images/spacer.gif) |
Vijilante SubAdmin
![](images/avatars/7230815434153eca6be3ad.gif)
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Oct 08, 2007 11:31 pm |
This is just the trigger I use to make the capture from my full mapping script. It is about 50 times more complex then what you need, but you chould be able to play around with it without any trouble since all of its visual outputs go to a child window. Everything else is created off into variables. I used a different coloration for my room name, hence the CFS check in there; I have adjusted the color code in the trigger for you though.
Code: |
#REGEX "PrettyCapture" {(?:In the trees above|)(?PrettyCaptured:\033\[33m.*)$} {#IF (%pos("offers with higher prices have not been shown.",%line)) {#STATE PrettyCapture 0} {PlayersPresent=0;PrettyFinal=0}} "" {color}
#COND {^(?PCap:.*)} {#IF (@PrettyFinal) {PrettyBak=@PrettyCaptured;PrettyCaptured=%replace(@PrettyCaptured,%concat(%char(27),"[0m "),%concat(%char(27),"[32m"));PrettyCaptured=%replace(%replace(@PrettyCaptured,%char(34),"`"),".`","`.");PrettyCaptured=%replace(%replace(@PrettyCaptured,"!`","`!"),"?`","`?");PrettyCaptured=%replace(%replace(@PrettyCaptured,"____"," ")," "," ");PrettyCaptured=%replace(@PrettyCaptured,%concat(%char(27),"[0m",""),"");#STATE PrettyCapture 0;#T- AwaitingStep;#IF (%regex(@PrettyCaptured,"(\033\[31m.*?\.)",RoomName)=0) {RoomName=""} {PCap=%pos(@RoomName,@PrettyCaptured);#IF (@PCap) {PCap=%copy(@PrettyCaptured,1,%eval(@PCap-1));PrettyCaptured=%remove(@PCap,@PrettyCaptured);#IF (%pos(".",@PCap)) {PCap=%concat(%replace(@PCap,".",%concat(".",%crlf)),%crlf)}};PrettyCaptured=%remove(@RoomName,@PrettyCaptured);#NOOP "[37m Some graffiti has been scrawled [0m[37mhere. It reads, '[1;35mOr a Saltyweenie![0;37m'";#IF (%regex(@PrettyCaptured,"((?:\033\[(?:0;|)37m|)Some ?(?:\033\[(?:0;|)37m|) ?graffiti ?(?:\033\[(?:0;|)37m|) ?has.*?`.*?\033\[(?:0;|)37m`)",PCap)) {PrettyCaptured=%replace(@PrettyCaptured,@PCap,%concat(%char(27),"[35m",%replace(%subchar(%stripansi(@PCap),"!?.",""),"here It","here, it"),"."))};#IF (%regex(@PrettyCaptured,"(\033\[37m ?This ?(\033\[37m)?area ?(\033\[37m)?is ?(\033\[37m)?unnaturally ?(\033\[37m)?flooded ?(\033\[37m)?with ?(\033\[37m)?water\.)",PCap)) {PrettyCaptured=%replace(@PrettyCaptured,@PCap,%concat(%char(27),"[1;33m",%stripansi(@PCap)))};#IF (%regex(@PrettyCaptured,"(\033\[(?:0\;|)37m.*?)(?:\033\[(?:1;|)(?:31|32|33|34|35|36)m|$)",RoomDesc)=0) {RoomDesc=""} {PrettyCaptured=%remove(@RoomDesc,@PrettyCaptured);RoomDesc=%trim(%replace(%subchar(%stripansi(@RoomDesc),%concat(%char(34),"'"),"``")," "," "))};:Room:#CLR;#IF (@RoomName) {#WINDOW Room {%replace(@RoomName,"[3","[1;3")}};#IF (@RoomDesc) {#WINDOW Room {%ansi(white)@RoomDesc}};#IF (@RoomExit) {#WINDOW Room {Obvious exits: %expanddb(@RoomExit," ","=")}};RoomName=%trim(%stripansi(@RoomName))};#IF (@PrettyCaptured) {PrettyCaptured=%trim(%replace(@PrettyCaptured,%concat(%char(27),"[0m"),""));PrettyCaptured=%replace(@PrettyCaptured," "," ");#WHILE (%regex(@PrettyCaptured,"(\033\[\d+(?:\;\d+|)m (?:\033\[\d+(?:\;\d+|)|\a))",PCap)) {PrettyCaptured=%replace(@PrettyCaptured,@PCap,%replace(@PCap," ",""))};#WHILE (%regex(@PrettyCaptured,"(\033\[1\;36m[A-Za-z ,.'-]+?\. (?:She|He))",PCap)) {PrettyCaptured=%replace(@PrettyCaptured,@PCap,%replace(@PCap,". He",", he"));PrettyCaptured=%replace(@PrettyCaptured,@PCap,%replace(@PCap,". She",", she"))};PrettyCaptured=%replace(@PrettyCaptured,".",%concat(".",%crlf));PrettyCaptured=%replace(@PrettyCaptured,"!",%concat("!",%crlf));PrettyCaptured=%replace(@PrettyCaptured,"?",%concat("?",%crlf));PrettyCaptured=%replace(@PrettyCaptured,%concat(%crlf," "),%crlf);PrettyCaptured=%replace(@PrettyCaptured,%concat(%crlf," "),%crlf);#IF (@PrettyCaptured) {#IF (%regex(@PrettyCaptured,"\033\[1;36m")) {PlayersPresent=1};#WINDOW Room {%delete(@PrettyCaptured,%eval(%len(@PrettyCaptured)-1),2)}}};:Room:PerformUpdate;PrettyFinal=0} {#IF ((%match(%line,"You see {a single exit|exits} leading"))|(%match(%trim(%line),"{@DescBlocked}"))|(%match(%line,"There are no obvious exits"))) {PrettyFinal=1;RoomExit="";#IF (%begins(%line,"You see")) {PCap=%subchar(%replace(%word(%line,2,"leading ")," and ","|"),",(). ","|=");#DELITEM PCap {};#ADDKEY RoomExit {@PCap}}} {PrettyCaptured=%concat(@PrettyCaptured,"____",%replace(@PCap,%char(126),""))}}} {looppat|param=99|prompt|notrig|color|regex} |
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
![](templates/Classic/images/spacer.gif) |
Neo2121 Beginner
Joined: 28 Dec 2006 Posts: 12
|
Posted: Tue Oct 09, 2007 7:38 am |
WOOT! I can finally get to work, thanks people, works great, i'll post back with my finished script :)
|
|
|
![](templates/Classic/images/spacer.gif) |
|
|
|
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
|
|