Page 1 of 1

This may be a dumb question

Posted: Sat Apr 24, 2004 12:06 am
by NobodyImportant
Well, this may be a dumb question, but I cant find the answer, and since I dont know the answer Im not sure what to look for, ok, now for the problem, the idea is to able able to cast any spell VIA chat, this is how the old code looked

Code: Select all


/if "$left(5,"@Param2")"=="buff:" {
  /if "$char(book,"$right($int($strlen("@Param2")-5),"@Param2")")"=="NULL" {
  /1 You ASS, i have no such spell.
  /return
  }
  /target @Param1
  /call cast "$right($int($strlen("@Param2")-5),"@Param2")"
/if "$return"=="CAST_toopower" /1 The spell you want me to cast on the intended Target is to powerful, pick a lower level spell.
/return
}

/if "$left(5,"@Param2")"=="cast:" {
  /if "$char(book,"$right($int($strlen("@Param2")-5),"@Param2")")"=="NULL" {
  /1 You ASS, i have no such spell.
  /return
  }
/targ @Param1
  /assist @Param1
/delay 5
  /call cast "$right($int($strlen("@Param2")-5),"@Param2")"
/if "$return"=="CAST_toopower" /1 The spell you want me to cast on the intended Target is to powerful, pick a lower level spell.
/return
}

I realize its a bit sloppy, and of course it requires editing spellcast.inc a little bit to get the correct $Return, but this code worked successfully with MQ2Parm, now here is the code converted to MQ2Data as best as i could

Code: Select all


/if (${String[@ChatText].Left[5].Equal[buff:]}) {
  /if ("${Me.Book[${String["@ChatText"].Right[${Math.Calc[${String[@ChatText].Length}-5]}]}]}"=="NULL") {
  /1 You ASS, i have no such spell.
  /return
  }
  /target @Sender
  /call cast "${String[@ChatText].Right[${Math.Calc[${String[@ChatText].Length}-5]}]})"
  /if (${Macro.Return.Equal["CAST_toopower"]}) /1 The spell you want me to cast on the intended Target is to powerful, pick a lower level spell.
/return
}

/if (${String[@ChatText].Left[5].Equal[Cast:]}) {
 /if ("${Me.Book[${String[@ChatText].Right[${Math.Calc[${String[@ChatText].Length}-5]}]}]}"=="NULL") {
  /1 You ASS, i have no such spell.
  /return
  }
/targ @Sender
  /assist @Sender
/delay 5
  /call cast "${String[@ChatText].Right[${Math.Calc[${String["@ChatText"].Length}-5]}]})"
  /if (${Macro.Return.Equal[CAST_toopower]}) /1 The spell you want me to cast on the intended Target is to powerful, pick a lower level spell.
/return
}

Now, after i've converted it and realize the problem, i run accross Lax's post here: http://macroquest2.com/phpBB2/viewtopic ... =eventchat

The problem is that CALCULATE can only handle NUMBERS. How do you calculate "gfdlkgjdlfgkldfglkdf" The answer is you dont
So, the ultimate problem is how I get everything out of a String except the 1st 5 characters in a string that has an unspecified number of characters, without using a ${Math.Calc[]}

Posted: Sat Apr 24, 2004 12:15 am
by Lax
You can actually do it with Mid. Use a number for the length portion that's higher than the actual length, and it will just get you the rest of the string:

${String[@ChatText].Mid[5,9999]}

:)

I can also make members to get all but the left/right n characters

Posted: Sat Apr 24, 2004 12:27 am
by ml2517
This should do the trick:

Code: Select all

/if (${String[@ChatText].Left[5].Equal[buff:]}) { 
  /if (!${Me.Book[${String["@ChatText"].Right[${Math.Calc[${String[@ChatText].Length}-5]}]}]}) { 
  /1 You ASS, i have no such spell. 
  /return 
  } 
  /target @Sender 
  /call cast "${String[@ChatText].Right[${Math.Calc[${String[@ChatText].Length}-5]}]}"
  /if (${Macro.Return.Equal["CAST_toopower"]}) /1 The spell you want me to cast on the intended Target is to powerful, pick a lower level spell. 
/return 
} 

/if (${String[@ChatText].Left[5].Equal[Cast:]}) { 
/if (!${Me.Book[${String[@ChatText].Right[${Math.Calc[${String[@ChatText].Length}-5]}]}]}) { 
  /1 You ASS, i have no such spell. 
  /return 
  } 
/target @Sender 
  /assist @Sender 
/delay 5 
  /call cast "${String[@ChatText].Right[${Math.Calc[${String["@ChatText"].Length}-5]}]}" 
  /if (${Macro.Return.Equal[CAST_toopower]}) /1 The spell you want me to cast on the intended Target is to powerful, pick a lower level spell. 
/return 
} 

Posted: Sat Apr 24, 2004 12:33 am
by Lax
I added functionality to string.Left and string.Right for next zip.

string string.Left[-length]: The left ("all but" length) of the string.. Left[-1] of "Left" will be "Lef"
string string.Right[-length]: The right ("all but" length) of the string.. Right[-1] of "Left" will be "eft"

Posted: Sat Apr 24, 2004 12:35 am
by ml2517
Very nice. That will make things alot easier.