Problem with targeting script

If you have searched the other User Creations subforums and an answer to your question has not been found, please post here!

Moderators: dorpond, trevor, Azhrei, Gamerdude

Post Reply
imB_YipMan
Kobold
Posts: 15
Joined: Mon Oct 23, 2017 8:56 am

Problem with targeting script

Post by imB_YipMan »

Hello all, and thanks to all the guys dedicated time to help out us new guys here.

I have spent my time creating "turn based" game in map tool coverting Mount & Blade Warband into a 2D Turn based strategy.
As I have spent 8 weeks working my donkey off to learn how to script - i have actually gotten a good prototype of the game in a almost playable state:
All except this one script:

Code: Select all

[h:TokExposed	= json.sort(json.intersection(getTokenNames("json",'{layer:["TOKEN"]}'), getExposedTokenNames("json")))]


[H: tokenList=TokExposed]
[H: imgList = tokenList]
[H: Num = listCount(imgList)]
 
[h,COUNT(Num),CODE:
{
[h:tokenName=listGet(imgList,roll.count)]
[h,token(tokenName): image=getTokenImage()]
[h:imgList=listReplace(imgList,roll.count,tokenName+" "+image)]
}]

[h:status=input(
		"Target|"+imgList+"|Select Target|LIST|SELECT=0 ICON=TRUE ICONSIZE=30")]
[h:abort(status)]

[h:targetName = listGet(tokenList,Target)]
 
  
[h:switchToken(targetName)]

PROBLEM:
If I select the first or the last Target on the list i get this:
-------------------------
First on list: The script returns: Error executing "switchToken": the token name or id "["AE_Anchor"" is unknown
Last on list: Error executing "switchToken": the token name or id "ImB_Yipman"" is unknown.
--------------------------
The rest of the targets are responding just fine.

I wish to note that the first Token returns the wrong image.

I would REALLY appreciate if someone could help me out on this one!

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Problem with targeting script

Post by aliasmask »

Looks like you're mixing a string list with a json array. If you want to convert a json to a string then use Wiki: json.toList().

Here's another way of doing it:

Code: Select all

[h:TokExposed = json.sort(json.intersection(getTokenNames("json",'{layer:["TOKEN"]}'), getExposedTokenNames("json")))]
[H: targetList = ""]

<!-- this will break if token name has a comma in it -->
[H, foreach(tokenName,tokExposed), code: {
   [H: switchToken(tokenName)]   
   [H: tokenImage = getTokenImage()]
   [H: targetList = listAppend(targetList,strformat("%{tokenImage} %{tokenName}"))]   
}]

[H: abort(input(strformat("Target|%{targetList}|Select Target|LIST|SELECT=0 ICON=TRUE ICONSIZE=30")))]

[H: targetName = json.get(tokExposed,Target)]
 

imB_YipMan
Kobold
Posts: 15
Joined: Mon Oct 23, 2017 8:56 am

Re: Problem with targeting script

Post by imB_YipMan »

Wow, I am really impressed with your help here! <3 <3 <3

imB_YipMan
Kobold
Posts: 15
Joined: Mon Oct 23, 2017 8:56 am

Re: Problem with targeting script

Post by imB_YipMan »

Thank you so much for helping out!!

There is still some problem:

This time no names are displayed on the list - only the images! (There are no comma's in the names) - but there are underscores.

I'm so looking forward to get this working! :D

imB_YipMan
Kobold
Posts: 15
Joined: Mon Oct 23, 2017 8:56 am

Re: Problem with targeting script

Post by imB_YipMan »

Thank you so much for helping out!!

Your code has removed the [" and ", but now there is no names in the target list.

Any ideas?

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Problem with targeting script

Post by aliasmask »

Try switching the image and name in the output.

Code: Select all

[H: targetList = listAppend(targetList,strformat("%{tokenName} %{tokenImage}"))]
edit: Just tested and that was it. FYI, here's an old post with similar targeting. The way an image can be shown in input() function has changed since them so the code may need tweaking: http://forums.rptools.net/viewtopic.php ... 49#p203749

Just tested that code and it works fine. If you want to switch to names just change the last line to getName(currentToken). Also, this example code limits the range to 5 cells. I would either remove that limit or change it to "feet" by changing the metric to range: {upto:25, distancePerCell:1} or to whatever values you think is good.

imB_YipMan
Kobold
Posts: 15
Joined: Mon Oct 23, 2017 8:56 am

Re: Problem with targeting script

Post by imB_YipMan »

Forgive me for being noobish here:

I Have 2 questions here (That is a part of the same code):

QUESTION ONE: "NAME NOT ID":

I got everything to work, except for understanding how to extract the NAME of the target instead of the idea.
You told me to change the last line , but failed my INT check, so to speak.

Would it be much work for you to show exactly how the code should look like from this point of reference?

Code: Select all


[h: cond = '{ range: {upto:4, distancePerCell:2}, pc:1, visible:1, unsetStates:["Dead"] }']
[h: ids = getTokens("json", cond)]
[H: filtered = "[]"]
[H: inputList = "[]"]
[H: source = currentToken()]
[H, foreach(id,ids), code: {
   [H: canSee = canSeeToken(id,source)]
   [H, token(id), if(! json.isEmpty(canSee)), code: {
      [H: name = getName()]
      [H: distance = getDistance(id,1,source)]
      [H: filtered = json.append(filtered,id)]
      [H: inputList = json.append(inputList,strformat('<html><table><tr><td width="10px"> </td><td><img src="%s" height="40" width="40" /></td><td style="text-align:center"><b>Distance</b><h1>%{distance}</h1></td></tr><tr><td> </td><td colspan="2" style="color:yellow;background-color:blue;text-align:center"><b>%s</b></td></tr></table></html>',getImage(name),replace(getName(),",",",")))]
   };{}]   
}]
[H: ids = filtered]
[H, if(json.length(ids)), code: {
   [h: hasInput = input("index|"+json.toList(inputList)+"|<html><b>Target enemy</b></html>|LIST") ]
   [h, if(hasInput): currentTarget = json.get(ids, index); currentTarget = "" ]
};{
   [dialog("No Target"): {<b>No Visible targets</b>}]
   [H: currentTarget = ""]
}]
[H: macro.return = currentTarget]

   [H: switchToken(currentTarget)]   

<MY PSUDOCODE HERE>
[ATTACKER NAME NOT ID] smashes [TARGETNAME & NOT ID] in the head with a [NotimportantAttackersSelectedWeapon] for [NotimportantAttackersSelectedWeaponDamage]


QUESTION 2: "CHECK FOR TOKEN ANGLE":

Is it possible for the script to also contain the FACING of the target to be included in the script?

Optimally I would like the shield of the unit to be covering an arc about 60 degrees.
If an archer is firing outside that arc, it would increase the chance of hitting drastically.
This makes flanking and setting up crossfire sensible in the game.
Last edited by imB_YipMan on Wed Oct 25, 2017 6:56 am, edited 1 time in total.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Problem with targeting script

Post by aliasmask »

Instead of:

Code: Select all

[H: macro.return = currentTarget]

[H: switchToken(currentTarget)]   
Use:

Code: Select all

[H: attackerName = getName(source)]
[H: targetName = getName(currentTarget)]

imB_YipMan
Kobold
Posts: 15
Joined: Mon Oct 23, 2017 8:56 am

Re: Problem with targeting script

Post by imB_YipMan »

Thanks a lot :)

Its all working fine <3

Post Reply

Return to “Requests for HELLLLP!”