Page 8 of 9

Re: createpath + getid + getpos together

Posted: Tue Dec 03, 2013 1:36 am
by rock5
It's probably not necessary. Probably the only differences are those few I've already made for the language support.

The problem with getting on with the language support is I was really hoping I'd get some feedback from my post and I could use them to make sure I didn't miss anything and to guage the effects of any changes I made. But I haven't had any yet.

Re: createpath + getid + getpos together

Posted: Tue Dec 03, 2013 1:53 am
by Bill D Cat
Alas, I use an English client here in the States, so any other language support isn't a priority for me. I'm just doing my best to make createpath as language independent as possible with the latest set of changes we've added.

Oh, and congratulations on the 10K post milestone.

Re: createpath + getid + getpos together

Posted: Tue Dec 03, 2013 2:28 am
by rock5
I didn't notice. Thanks.

Re: createpath + getid + getpos together

Posted: Tue Dec 24, 2013 1:54 pm
by Bill D Cat
Just tried to use createpath and found that the byname getInput() function isn't working correctly right now. The prompt to enter the option is displayed, but no matter what key is pressed it doesn't accept the input.

I've tried all the other options and they seem to work fine. Even the input for Numpad-0 is working correctly, so it appears to only be the single character input that is used by the byname option that is having issues.

Re: createpath + getid + getpos together

Posted: Wed Dec 25, 2013 11:09 am
by rock5
Works for me. Try adding some print messages along the way to see what's happening.

Re: createpath + getid + getpos together

Posted: Wed Dec 25, 2013 11:30 am
by Bill D Cat
createpath.lua starting at line 395

Code: Select all

		repeat
			local ks = keyboardState()
			local stillpressed
			for k,v in pairs(ks) do
				if v then stillpressed = true print(v) end
			end
			yrest(50)
			print(stillpressed)
		until not stillpressed
As soon as I use the Numpad-6 key, stillpressed always equals true and so this loop never exits. Pressing any other key will not change the value. And print(v) always outputs true as well. If I change that to print(k) then the output alternates between 255 (no key pressed) and the key value that was pressed.

System info: Windows 8.1, MicroMacro 1.04.132, RoMBot version 3.29 Revision 769. Only files that are conflicted are addresses.lua (expected) and skills.xml (to include the missing Mage/Rogue elite "Shadow Protection").

Re: createpath + getid + getpos together

Posted: Wed Dec 25, 2013 12:15 pm
by rock5
My first idea is maybe your numkey 6 is sticking but I just did a test while repeating a key and I did not see 255 come up as true. I'd say the problem is with that 255 key but I don't know what would cause it. It's also wrong that the key pressed still shows as being pressed even when you have released it. I don't know. It could be a keyboard issue, a driver issue or a Windows issue.

Re: createpath + getid + getpos together

Posted: Wed Dec 25, 2013 12:51 pm
by Bill D Cat
Looks like the last Windows Update messed with my keyboard drivers or something. Did a rollback, applied the update again and reboot and now it is working fine.

Re: createpath + getid + getpos together

Posted: Sat Nov 29, 2014 11:58 am
by freemw
1. Maybe we should always add the header in files created by createpath.lua:
<onLoad>
</onLoad>

2. For the Russian game client. in order to properly selected menu correctly was recorded in files created by createpath.lua require a patch to file createpath.lua. start from line 669:
local name, typ, index = getChoice(tmp.com)
-- for russian
name=utf82oem_russian(name)
-- for russian
if name == nil then
tmp.wp_type = nil
hf_type = "<Invalid Option>"


2.1. Or right so:
local name, typ, index = getChoice(tmp.com)
if( bot.ClientLanguage == "RU" ) then
name=utf82oem_russian(name) -- language conversations for Russian Client
end
if name == nil then
tmp.wp_type = nil
hf_type = "<Invalid Option>"

Re: createpath + getid + getpos together

Posted: Sat Nov 29, 2014 12:21 pm
by rock5
1. I'm not sure I agree.

2. I guess I could add Russian support. I'll do some testing tomorrow.

Re: createpath + getid + getpos together

Posted: Sun Nov 30, 2014 10:01 am
by Bill D Cat
While adding the <onload> section at the top of each file is easy to implement in the createpath file, I don't think it is necessary. My reason is, not all waypoint files will need it, and those that do will have all the included code entered manually. So adding to more lines is not that much more work, and the command itself isn't that difficult to remember the format for.

So if you want the support added for your particular createpaths file we can give you a section of code to add to the file, but I don't think it will make it into the official repository release any time soon.

Re: createpath + getid + getpos together

Posted: Sun Nov 30, 2014 10:42 am
by rock5
Looks like I can't test Russian but I tested with the umlauts function in German

Code: Select all

name = utf8ToAscii_umlauts(name)
It didn't work.

Are you sure the above fix you wrote works and without it it doesn't?

Re: createpath + getid + getpos together

Posted: Fri Dec 05, 2014 1:06 pm
by freemw
My file. For Russian Client works perfectly
I have not enough knowledge to make it versatile for different languages, but with my patch all works well for the Russian version. Hope you can make it universal for all languages
(In Russian language:
У меня нехватает знаний сделать это универсальным для разных языков, но с моими исправлениями все хорошо работает для русской версии. Надеюсь вы сможете сделать это универсальным для всех языков
)

Re: createpath + getid + getpos together

Posted: Fri Dec 05, 2014 9:47 pm
by rock5
freemw wrote:I have not enough knowledge to make it versatile for different languages
What do you mean? You came up with a perfectly good versatile solution with this

Code: Select all

if( bot.ClientLanguage == "RU" ) then
name=utf82oem_russian(name) -- language conversations for Russian Client
end
I'll probably use that. I'll include it in my next commit.

Re: createpath + getid + getpos together

Posted: Sat May 16, 2015 12:49 pm
by Bill D Cat
I was trying to add a waypoint to one of my Sascilia Steppes files where I just want to talk to Snoop at Ayren Caravan to activate that transport portal. I targeted him with NUMPAD 5, then selected NUMPAD 6 for the ChoiceOptionByName and selected option 4 "Leave conversation" and createpath crashes with an error.

Code: Select all

12:38am - scripts\rom/createpath.lua:737: attempt to concatenate local 'index' (a nil value)
The relevant sections of code in createpath.lua are:

Starting at line 668:

Code: Select all

						tmp.com = getInput(true, language[507]);	-- Choose option
						local name, typ, index = getChoice(tmp.com) 			<-- This getChoice() call ...
Starting at line 730:

Code: Select all

						else
							tmp.wp_type = "COBYNAME"
							name = string.match(name,"^[> ]*(.-)[< ]*$") -- Filter >> and << added by addons.
							tmp.text = name
							hf_type = sprintf("ChoiceOptionByName \'%s\'",name)
							message(prefix..sprintf(language[516], "\'"..name.."\'" ) ); -- ChoiceOptionByName
							tmp.keystring = getKeyStrings(name, true)--, "SC_", "SP")
							RoMCode("ChoiceOption("..index..")")  			<-- Causes the crash here
						end
Not sure why this is crashing the script, but I've just worked around it by using RoMScript("CloseAllWindows()") for now. My thought was adding the lines in the function below might work to fix this, but I don't know if it would break something else.

Code: Select all

local function getChoice(num)
	local text, typ, index = RoMCode("n="..num.." c=0 for k,v in pairs(g_SpeakFrameData.option) do if v.objtype~=1 then c=c+1 if c==n then a={v.title,v.type,v.id} break end end end")
	-- Fix title
	if text ~= nil then
		text = string.gsub(text,"|c%x*","") -- Remove color info
		text = string.gsub(text,"%[.*%]","") -- Remove added info in square brackets
		text = string.gsub(text,"%(.*%)","") -- Remove added info in normal brackets
		local acceptQuest = getTEXT("SYS_ACCEPT_QUEST")
		if string.find(string.lower(text),string.lower(acceptQuest)) then
			text = string.sub(text,#acceptQuest+2) -- Remove "Accept quest: "
		end
		text = trim(text) -- Trim leading and trailing spaces
	end
	if index == nil then			<-- Would this fix things?
		index = num
	end

	return text, typ, index
end

Re: createpath + getid + getpos together

Posted: Sat May 16, 2015 5:51 pm
by Bill D Cat
Well it kinda fixed things, and kinda didn't. Adding that check kept createpath from crashing, but the resulting command fails when executed.

Code: Select all

<?xml version="1.0" encoding="utf-8"?><waypoints>
	<!-- #  1 --><waypoint x="-38729" z="1555" y="2">
			player:target_NPC(111256) -- Snoop the Stubborn
			ChoiceOptionByName(getTEXT("HOUSE_MAID_LEAVE_TALK")) -- 'Leave conversation'
			error("Done",0)
	</waypoint>
</waypoints>

Code: Select all

We use the normal waypoint path test.xml now.
Clearing target.
Moving to waypoint #1, (-38730, 1553)
We try to find NPC 111256:
We successfully target NPC Snoop the Stubborn and try to open the dialog window.

Option "Leave conversation" not found.
The game client did not crash.
5:47pm - Done
So even though createpath found a matching text string, the bot failed to make a match at run time in the ChoiceOptionByName() function.

Re: createpath + getid + getpos together

Posted: Sat May 16, 2015 6:51 pm
by Bill D Cat
Okay, I got it figured out now. Adding the fix in createpath to the getChoice() function fixes the first issue. And making the following change to the functions.lua file for the ChoiceOptionByName() function fixes the bot at runtime.

Code: Select all

function ChoiceOptionByName(optiontext)
------------------------------------------------
-- Select Option By Name
-- optiontext = option text or part of
-- NPC option dialog should already be open
------------------------------------------------
	if not RoMScript("SpeakFrame:IsVisible()") then
		printf("Please open a dialog before using \"ChoiceOptionByName\".\n")
		return
	end

    local counter = 1
	local option
    repeat
		option = RoMScript("GetSpeakOption("..counter..")")
		if option and FindNormalisedString(option,optiontext) then
			-- First try "ChoiceOption"
            RoMCode("ChoiceOption("..counter..");"); yrest(1000);

			-- If SpeakFrame is still open and option is still there then try "SpeakFrame_ListDialogOption"
			option = RoMScript("GetSpeakOption("..counter..")")
			if option and FindNormalisedString(option,optiontext) and RoMScript("SpeakFrame:IsVisible()") then
				RoMCode("SpeakFrame_ListDialogOption(1,"..counter..");"); yrest(1000);
			end
            return true
        end
		if option == nil and optiontext == getTEXT("HOUSE_MAID_LEAVE_TALK") then -- Should be the "Leave conversation" option
			RoMCode("CloseAllWindows()"); yrest(1000);
			return true
		end
        counter = counter + 1
    until not option
	printf("Option \"%s\" not found.\n",optiontext)
    return false
end

Re: createpath + getid + getpos together

Posted: Sun May 17, 2015 6:06 am
by rock5
Firstly, the problem with the "Leave conversion" option is that it has no "index"/"id" number. If you look at the getChoice function in createpaths you'll see that it iterates through the in-game table g_SpeakFrameData.option. If you print that in-game

Code: Select all

/pr g_SpeakFrameData.option
You'll see that the "Leave Conversion" option is the only one that doesn't have an 'id' value. Consequently you can't use GetChoiceOption or ChoiceOption functions on it. I think I never handled it because I assumed no one would bother selecting that option to close the dialog. It's usually not necessary after all.
Bill D Cat wrote:

Code: Select all

   if index == nil then         <-- Would this fix things?
      index = num
   end
This is incorrect for 2 reasons. Firstly if you select "Leave conversion" then there is no point in giving it a number because it can't use it for the above reasons. Secondly the logic is wrong because index is not necessarily the same as num. For instance if you have a dialog with 2 quests and 1 normal dialog option then the dialog option will have a num value of 3 but an index of 1 (because it's the first 'choice' option).

I'm pretty sure the "Leave Conversation" option is the only one that has no index so the best way to deal with it is to just deal with it separatly, eg.

Code: Select all

if index == nil then
   -- add command to close the dialog box
end
On second thought it's probably best to fix ChoiceOptionByName to be able to handle it and then just use ChoiceOptionByName on line 737 of createpath.

In regards to fixing ChoiceOptionByName, if optiontext == getTEXT("HOUSE_MAID_LEAVE_TALK") then it will equal it from the beginning of the function. No need to check it in each loop, just check it at the start of the function.

Then with that working the easiest fix for createpath is to change line 737 from

Code: Select all

							RoMCode("ChoiceOption("..index..")")
to

Code: Select all

							RoMCode("ChoiceOptionByName("..name..")")
I followed the game code and it looks like it uses SpeakFrame_Hide() when you click the "Leave Conversation" option so that's what I would use instead of CloseAllWindows.

Hope that's helpful.

Re: createpath + getid + getpos together

Posted: Sun May 17, 2015 9:43 am
by Bill D Cat
Nope, that doesn't work either. I get this error message from createpath when I make the change on line 737 as you suggested.

Code: Select all

9:41am - IGF:\} ChoiceOptionByName(Leave conversation) if type(a)~="table" then a={a} end z={\:IGF Error in command sent to IGF.

Re: createpath + getid + getpos together

Posted: Sun May 17, 2015 10:44 am
by rock5
Well.. it was untested.

So I take it you can't see how to fix it? :P

Hint: ChoiceOptionByName is not an in game function.