Bad argument #1 to getkeyname

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Message
Author
Suffering
Posts: 34
Joined: Wed Aug 19, 2009 9:14 pm

Bad argument #1 to getkeyname

#1 Post by Suffering » Wed Aug 19, 2009 9:24 pm

Error:

Code: Select all

The macro is currently not running. Press the start key <Delete> to begin.
You may use <End> key to stop/pause the script.
Resumed.
RoM Bot Version 2.45
Attempt to read playerAddress
self.Address: 0x287E400
X: -1070.00, Y:35.85, Z: -5370.16
XU: -0.38, YU:0.88, ZU: 0.29
mousePawn: 0x0
playerAddr: 0x1F670400
playerTarget: 0x0
RoM windows size is 0x0, uppder left corner at -3200, -32000
...rs/*****/Desktop/micromacro/scripts/rom/settings.lua:91: bad argument #1 to 'getKeyName' <<null>>

Please enter the script name to run.
Type in 'exit' <without quotes> to exit.
Script>
Settings.lua:

Code: Select all

settings_default = {
	hotkeys = {
		MOVE_FORWARD = {key = _G.key.VK_W, modifier = nil},
		MOVE_BACKWARD = {key = _G.key.VK_S, modifier = nil},
		ROTATE_LEFT = {key = _G.key.VK_A, modifier = nil},
		ROTATE_RIGHT = {key = _G.key.VK_D, modifier = nil},
		STRAFF_LEFT = {key = _G.key.VK_Q, modifier = nil},
		STRAFF_RIGHT = {key = _G.key.VK_E, modifier = nil},
		JUMP = {key = _G.key.VK_SPACE, modifier = nil},
		TARGET = {key = _G.key.VK_TAB, modifier = nil},
		TARGET_FRIEND = {key = _G.key.J, modifier = nil},
		START_BOT = {key = _G.key.VK_DELETE, modifier = nil},
		STOP_BOT = {key = _G.key.VK_END, modifier = nil}
	},
	options = {
		ENABLE_FIGHT_SLOW_TURN = false,
		MELEE_DISTANCE = 45,
		LANGUAGE = "english",
		DEBUG_ASSERT = false,
	},
	profile = {
		options = {
			-- common options
			HP_LOW = 85,
			MP_LOW_POTION = 50,
			HP_LOW_POTION = 40,
			COMBAT_TYPE = "melee",
			COMBAT_RANGED_PULL = "true",	-- only for melee classes 
			COMBAT_DISTANCE = 200,
			ANTI_KS = true,
			WAYPOINTS = "myWaypoints.xml",
			RETURNPATH = nil,
			PATH_TYPE = "waypoints",
			WANDER_RADIUS = 500,
			WAYPOINT_DEVIATION = 0,
			LOOT = true,
			LOOT_TIME = 2000,
			LOOT_IN_COMBAT = true,
			LOOT_DISTANCE = nil,
			LOOT_PAUSE_AFTER = 10,	-- probability for short pause after loot to look more human
			POTION_COOLDOWN = 15,
			MAX_FIGHT_TIME = 12,
			DOT_PERCENT = 90,
			LOGOUT_TIME = 0,
			LOGOUT_SHUTDOWN = false,
			LOGOUT_WHEN_STUCK = true,
			MAX_UNSTICK_TRIALS = 10,
			TARGET_LEVELDIF_BELOW = 99,
			TARGET_LEVELDIF_ABOVE = 99,
			QUICK_TURN = false,
			MP_REST = 15,
			HP_REST = 15,
			RES_AUTOMATIC_AFTER_DEATH = false,	-- automatic resurrect after death true | false,

			
			-- expert options
			WAYPOINTS_REVERSE = false,	-- use the waypoint file in reverse order
			MAX_DEATHS = 10,		-- maximal death if automatic resurrect befor logout
			WAIT_TIME_AFTER_RES = 8000,	-- time to wait after resurrection, needs more on slow PCs
			RETURNPATH_SUFFIX = "_return",	-- suffix for default naming of returnpath
			HARVEST_SCAN_WIDTH = 10,	-- steps horizontal
			HARVEST_SCAN_HEIGHT = 8,	-- steps vertical
			HARVEST_SCAN_STEPSIZE = 35,	-- wide of every step
			HARVEST_SCAN_TOPDOWN = true,	-- true = top->down  false = botton->up
			HARVEST_SCAN_XMULTIPLIER = 1.0,	-- multiplier for scan width
			HARVEST_SCAN_YMULTIPLIER = 1.1,	-- multiplier for scan line height
			HARVEST_SCAN_YREST = 10,	-- scanspeed
			USE_SLEEP_AFTER_RESUME = false, -- enter sleep mode afer pressing pause key
			
		}, hotkeys = {}, skills = {}, friends = {},
		events = {
			onDeath = function () pauseOnDeath(); end,
			onLeaveCombat = nil,
			onSkillCast = nil,
		}
	},
};

settings = settings_default;


-- check if keys are double assigned or empty
check_keys = { };
function check_double_key_settings( _name, _key, _modifier )

	for i,v in pairs(check_keys) do
		if( v.key      == _key  and
		    v.modifier == _modifier ) then
				local modname, keyname;
				if( v.modifier ) then modname = getKeyName(v.modifier); end;
				if( v.key ) then keyname = getKeyName(v.modifier); end;

				local errstr = sprintf("Error: You assigned the key \'%s %s\' double: for \'%s\' and for \'%s\'.\n",
					tostring(modname), tostring(keyname), v.name, _name) .. "Please check your settings!";
				error(errstr, 0);
		if( _key == nil) then
			cprintf(cli.yellow, "Error: The key for \'%s\' is empty!\n", _name);
			error("Please check your settings!", 0);
		end

		end
	end;
	
	-- check the using of modifiers
	if( _modifier ~= nil) then
		cprintf(cli.yellow, "Due to technical reasons, we don't support "..
		   "modifiers like CTRL/ALT/SHIFT for hotkeys at the moment. "..
		   "Please change your hotkey %s-%s for \'%s\'\n", getKeyName(_modifier), getKeyName(_key), _name);
		   
		   -- only a warning for TARGET_FRIEND / else an error
		   if(_name == "TARGET_FRIEND") then
		   	cprintf(cli.yellow, "You can't use the player:target_NPC() function until changed!\n");
		   else
		   	error("Please check your settings!", 0);
		   end
	end

	
	local tmp = {};
	tmp.name = _name;
	tmp.key  = _key;
	tmp.modifier  = _modifier;	
	table.insert(check_keys, tmp);	

end

function settings.load()
	local filename = getExecutionPath() .. "/settings.xml";
	local root = xml.open(filename);
	local elements = root:getElements();

	-- Specific to loading the hotkeys section of the file
	local loadHotkeys = function (node)
		local elements = node:getElements();
		for i,v in pairs(elements) do
			-- If the hotkey doesn't exist, create it.
			settings.hotkeys[ v:getAttribute("description") ] = { };
			settings.hotkeys[ v:getAttribute("description") ].key = key[v:getAttribute("key")];
			settings.hotkeys[ v:getAttribute("description") ].modifier = key[v:getAttribute("modifier")];

			if( key[v:getAttribute("key")] == nil ) then
				local err = sprintf("settings.xml error: %s does not have a valid hotkey!", v:getAttribute("description"));
				error(err, 0);
			end
			check_double_key_settings( v:getAttribute("description"), v:getAttribute("key"), v:getAttribute("modifier") );
		end
	end

	local loadOptions = function (node)
		local elements = node:getElements();
		for i,v in pairs(elements) do
			settings.options[ v:getAttribute("name") ] = v:getAttribute("value");
		end
	end

	-- load RoM keyboard bindings.txt file
	local function load_RoM_bindings_txt()
		
		local filename, file;
		
		local userprofilePath = os.getenv("USERPROFILE");
		local documentPaths = {
			userprofilePath .. "\\My Documents\\", -- English
			userprofilePath .. "\\Eigene Dateien\\", -- German
			userprofilePath .. "\\Mes Documents\\", -- French
			userprofilePath .. "\\Omat tiedostot\\", -- Finish
			userprofilePath .. "\\Belgelerim\\", -- Turkish
			userprofilePath .. "\\Mina Dokument\\", -- Swedish
			userprofilePath .. "\\Dokumenter\\", -- Danish
			userprofilePath .. "\\Documenti\\", -- Italian
			userprofilePath .. "\\Mijn documenten\\", -- Dutch
			userprofilePath .. "\\Moje dokumenty\\", -- Polish
			userprofilePath .. "\\Mis documentos\\", -- Spanish
--			"F:\\privat\\",
		};

		-- Select the first path that exists
		for i,v in pairs(documentPaths) do
			local filename = v .. "Runes of Magic\\bindings.txt"
			if( fileExists(filename) ) then
				file = io.open(filename, "r");
				cprintf(cli.green, "We read the hotkey settings from your "..
				   "bindings.txt file %s instead of using the settings.lua file.\n", filename)
			end
		end

		-- If we wern't able to locate a document path, return.
		if( file == nil ) then
			return;
		end


		-- Load bindings.txt into own table structure
		bindings = { name = { } };
		-- read the lines in table 'lines'
		for line in file:lines() do
			for name, key1, key2 in string.gfind(line, "(%w*)%s([%w+]*)%s*([%w+]*)") do
				bindings[name] = {};
				bindings[name].key1 = key1;
				bindings[name].key2 = key2;

				--settings.hotkeys[name].key = 
			end
		end

		local function bindHotkey(bindingName)
			local links = { -- Links forward binding names to hotkey names
				MOVEFORWARD = "MOVE_FORWARD",
				MOVEBACKWARD = "MOVE_BACKWARD",
				TURNLEFT = "ROTATE_LEFT",
				TURNRIGHT = "ROTATE_RIGHT",
				STRAFELEFT = "STRAFF_LEFT",
				STRAFERIGHT = "STRAFF_RIGHT",
				TARGETNEARESTENEMY = "TARGET",
				TARGETNEARESTFRIEND = "TARGET_FRIEND",	
			};

			local hotkeyName = bindingName;
			if(links[bindingName] ~= nil) then
				hotkeyName = links[bindingName];
			end;


			if( bindings[bindingName] ~= nil ) then
				if( bindings[bindingName].key1 ~= nil ) then
					-- Fix key names
					bindings[bindingName].key1 = string.gsub(bindings[bindingName].key1, "CTRL", "CONTROL");

					if( string.find(bindings[bindingName].key1, '+') ) then
						local parts = explode(bindings[bindingName].key1, '+');
						-- parts[1] = modifier
						-- parts[2] = key

						settings.hotkeys[hotkeyName].key = key["VK_" .. parts[2]];
						settings.hotkeys[hotkeyName].modifier = key["VK_" .. parts[1]];
					else
						settings.hotkeys[hotkeyName].key = key["VK_" .. bindings[bindingName].key1];
					end
					
					check_double_key_settings( hotkeyName, settings.hotkeys[hotkeyName].key, 
					  settings.hotkeys[hotkeyName].modifier );
				end
			end
		end

		bindHotkey("MOVEFORWARD");
		bindHotkey("MOVEBACKWARD");
		bindHotkey("TURNLEFT");
		bindHotkey("TURNRIGHT");
		bindHotkey("STRAFELEFT");
		bindHotkey("STRAFERIGHT");
		bindHotkey("JUMP");
		bindHotkey("TARGETNEARESTENEMY");
		bindHotkey("TARGETNEARESTFRIEND");
	end

	-- check ingame settings
	-- only if we can find the bindings.txt file
	local function check_ingame_settings( _name, _ingame_key)
		
		if( not bindings ) then		-- no bindings.txt file loaded
			return
		end;
		
		if( settings.hotkeys[_name].key ~= key["VK_"..bindings[_ingame_key].key1] and
		    settings.hotkeys[_name].key ~= key["VK_"..bindings[_ingame_key].key2] ) then
			cprintf(cli.yellow, "Your bot settings for hotkey \'%s\' in settings.xml "..
			   "don't match your RoM ingame keyboard settings.\n",
			        _name);
			error("Please check your settings!", 0);
		end
	end


	function checkHotkeys(_name, _ingame_key)
		if( not settings.hotkeys[_name] ) then
			error("ERROR: Global hotkey not set: " .. _name, 0);
		end
		
		-- check if settings.lua hotkeys match the RoM ingame settings
		-- check_ingame_settings( _name, _ingame_key);
	end


	for i,v in pairs(elements) do
		local name = v:getName();

		if( string.lower(name) == "hotkeys" ) then
			loadHotkeys(v);
		elseif( string.lower(name) == "options" ) then
			loadOptions(v);
		end
	end


	load_RoM_bindings_txt();	-- read bindings.txt from RoM user folder
	
	-- Check to make sure everything important is set
	--           bot hotkey name    RoM ingame key name         
	checkHotkeys("MOVE_FORWARD",   "MOVEFORWARD");
	checkHotkeys("MOVE_BACKWARD",  "MOVEBACKWARD");
	checkHotkeys("ROTATE_LEFT",    "TURNLEFT");
	checkHotkeys("ROTATE_RIGHT",   "TURNRIGHT");
	checkHotkeys("STRAFF_LEFT",    "STRAFELEFT");
	checkHotkeys("STRAFF_RIGHT",   "STRAFERIGHT");
	checkHotkeys("JUMP",           "JUMP");
	checkHotkeys("TARGET",         "TARGETNEARESTENEMY");
	checkHotkeys("TARGET_FRIEND",  "TARGETNEARESTFRIEND");
	
end


function settings.loadProfile(_name)
	-- Delete old profile settings (if they even exist), restore defaults
	settings.profile = settings_default.profile;

	local filename = getExecutionPath() .. "/profiles/" .. _name .. ".xml";
	local root = xml.open(filename);
	local elements = root:getElements();

	local loadOptions = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			settings.profile.options[v:getAttribute("name")] = v:getAttribute("value");
		end
	end

	local loadHotkeys = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			settings.profile.hotkeys[v:getAttribute("name")] = {};
			settings.profile.hotkeys[v:getAttribute("name")].key = key[v:getAttribute("key")];
			settings.profile.hotkeys[v:getAttribute("name")].modifier = key[v:getAttribute("modifier")];

			if( key[v:getAttribute("key")] == nil ) then
				local err = sprintf("Profile error: Please set a valid key for "..
				  "hotkey %s in your profile file \'%s.xml\'.", tostring(v:getAttribute("name")), name );
				error(err, 0);
			end
			check_double_key_settings( v:getAttribute("name"), v:getAttribute("key"), v:getAttribute("modifier") );
		end
	end

	local loadOnDeathEvent = function(node)
		local luaCode = tostring(node:getValue());

		if( string.len(luaCode) > 0 and string.find(luaCode, "%w") ) then
			settings.profile.events.onDeath = loadstring(luaCode);
			if( type(settings.profile.events.onDeath) ~= "function" ) then
				settings.profile.events.onDeath = nil;
			end;
		end
	end

	local loadOnLeaveCombatEvent = function(node)
		local luaCode = tostring(node:getValue());

		if( string.len(luaCode) > 0 and string.find(luaCode, "%w") ) then
			settings.profile.events.onLeaveCombat = loadstring(luaCode);
			if( type(settings.profile.events.onLeaveCombat) ~= "function" ) then
				settings.profile.events.onLeaveCombat = nil;
			end;
		end
	end

	local loadOnSkillCastEvent = function(node)
		local luaCode = tostring(node:getValue());

		if( string.len(luaCode) > 0 and string.find(luaCode, "%w") ) then
			settings.profile.events.onSkillCast = loadstring(luaCode);
			if( type(settings.profile.events.onSkillCast) ~= "function" ) then
				settings.profile.events.onSkillCast = nil;
			end;
		end
	end


	local skillSort = function(tab1, tab2)
		if( tab2.priority < tab1.priority ) then
			return true;
		end;

		return false;
	end

	local loadSkills = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			local name, hotkey, modifier, level;
			name = v:getAttribute("name");
			hotkey = key[v:getAttribute("hotkey")];
			modifier = key[v:getAttribute("modifier")];
			level = v:getAttribute("level");

			check_double_key_settings( v:getAttribute("name"), v:getAttribute("hotkey") );

			-- Over-ride attributes
			local priority, maxhpper, inbattle, pullonly, maxuse
			priority = v:getAttribute("priority");
			maxhpper = tonumber(v:getAttribute("hpper"));
			inbattle = v:getAttribute("inbattle");
			pullonly = v:getAttribute("pullonly");
			maxuse = tonumber(v:getAttribute("maxuse"));

			-- check if 'wrong' options are set
			if( v:getAttribute("mana")      or
			    v:getAttribute("manainc")   or
			    v:getAttribute("rage")      or
			    v:getAttribute("energy")    or
			    v:getAttribute("concentration")      or
			    v:getAttribute("range")     or
			    v:getAttribute("cooldown")  or
			    v:getAttribute("minrange")  or
			    v:getAttribute("type")      or
			    v:getAttribute("target")    or
			    v:getAttribute("casttime") ) then
			    	cprintf(cli.yellow, "The options \'mana\', \'manainc\', \'rage\', "..
			    	   "\'energy\', \'concentration\', \'range\', "..
			    	   "\'cooldown\', \'minrange\', \'type\', \'target\' and \'casttime\' "..
			    	   "are no valid options for your skill \'%s\' in your profile \'%s.xml\'. "..
			    	   "Please delete them and restart!\n", name, _name);
			    	   error("Bot finished due of errors above.\n", 0);
			end;
			if( v:getAttribute("modifier") ) then
			    	cprintf(cli.yellow, "The options \'modifier\' "..
			    	  "for your skill \'%s\' in your profile \'%s.xml\' "..
			    	  "is not supported at the moment. "..
			    	  "Please delete it and restart!\n", name, _name);
				error("Bot finished due of errors above.\n", 0);
			end;

			if( name == nil) then
			    	cprintf(cli.yellow, "You defined an \'empty\' skill name in "..
			    	  "your profile \'%s.xml\'. Please delete or correct "..
			    	  "that line!\n", _name);
				error("Bot finished due of errors above.\n", 0);
			end;

			if( inbattle ~= nil ) then
				if( inbattle == "true" or 
				    inbattle == true ) then
					inbattle = true;
				elseif( inbattle == "false"  or
					inbattle == false ) then
					inbattle = false;
				else
						cprintf(cli.yellow, "You defined an wrong option inbattle=\'%s\' at skill %s in "..
						  "your profile \'%s.xml\'. Please delete or correct "..
						  "that line!\n", inbattle, name, _name);
					error("Bot finished due of errors above.\n", 0);
				end;
			end

			if( pullonly ~= nil ) then
				if( pullonly == "true" or
					pullonly == true ) then
					pullonly = true;
				else
						cprintf(cli.yellow, "You defined an wrong option pullonly=\'%s\' at skill %s in "..
						  "your profile \'%s.xml\'. Only \'true\' is possible. Please delete or correct "..
						  "that line!\n", pullonly, name, _name);
					error("Bot finished due of errors above.\n", 0);
				end;
			end

			if( level == nil or level < 1 ) then
				level = 1;
			end

			local baseskill = database.skills[name];
			if( not baseskill ) then
				local err = sprintf("ERROR: \'%s\' is not defined in the database!", name);
				error(err, 0);
			end

			local tmp = CSkill(database.skills[name]);
			tmp.hotkey = hotkey;
			tmp.modifier = modifier;
			tmp.Level = level;

			if( toggleable ) then tmp.Toggleable = toggleable; end;
			if( priority ) then tmp.priority = priority; end
			if( maxhpper ) then tmp.MaxHpPer = maxhpper; end;
			if( inbattle ~= nil ) then tmp.InBattle = inbattle; end;
			if( pullonly == true ) then tmp.pullonly = pullonly; end;
			if( maxuse ) then tmp.maxuse = maxuse; end;

			table.insert(settings.profile.skills, tmp);
		end

		table.sort(settings.profile.skills, skillSort);

	end

	local loadFriends = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			local name = v:getAttribute("name");
			table.insert(settings.profile.friends, name);
		end
	end

	local hf_temp = _name;	-- remember profile name shortly

	for i,v in pairs(elements) do
		local name = v:getName();

		if( string.lower(name) == "options" ) then
			loadOptions(v);
		elseif( string.lower(name) == "hotkeys" ) then
			loadHotkeys(v);
		elseif( string.lower(name) == "skills" ) then
			loadSkills(v);
		elseif( string.lower(name) == "friends" ) then
			loadFriends(v);
		elseif( string.lower(name) == "ondeath" ) then
			loadOnDeathEvent(v);
		elseif( string.lower(name) == "onleavecombat" ) then
			loadOnLeaveCombatEvent(v);
		elseif( string.lower(name) == "onskillcast" ) then
			loadOnSkillCastEvent(v);
		elseif( string.lower(name) == "skills_warrior"  and
		        player.Class1 == CLASS_WARRIOR ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_scout"  and
		        player.Class1 == CLASS_SCOUT ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_rogue"  and
		        player.Class1 == CLASS_ROGUE ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_mage"  and
		        player.Class1 == CLASS_MAGE ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_priest"  and
		        player.Class1 == CLASS_PRIEST ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_knight"  and
		        player.Class1 == CLASS_KNIGHT ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_runedancer"  and
		        player.Class1 == CLASS_RUNEDANCER ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_druid"  and
		        player.Class1 == CLASS_DRUID ) then
			loadSkills(v);
		else		-- warning for other stuff and misspellings
			if ( string.lower(name) ~= "skills_warrior"     and
			     string.lower(name) ~= "skills_scout"       and
		 	     string.lower(name) ~= "skills_rogue"       and
	 		     string.lower(name) ~= "skills_mage"        and
			     string.lower(name) ~= "skills_priest"      and
			     string.lower(name) ~= "skills_knight"      and
			     string.lower(name) ~= "skills_runedancer"  and
			     string.lower(name) ~= "skills_druid" )     then
				cprintf(cli.yellow, tostring(language[60]), string.lower(tostring(name)),
					tostring(hf_temp));
			end;
		end
	end


	function checkProfileHotkeys(name)
		if( not settings.profile.hotkeys[name] ) then
			error("ERROR: Hotkey not set for this profile: " ..name, 0);
		end
	end

	-- Check to make sure everything important is set
	checkProfileHotkeys("ATTACK");

	-- default combat type if not in profile defined
	if( settings.profile.options.COMBAT_TYPE ~= "ranged" and 
	    settings.profile.options.COMBAT_TYPE ~= "melee" ) then
		if( player.Class1 == CLASS_WARRIOR or
		    player.Class1 == CLASS_ROGUE   or
--		    player.Class1 == CLASS_RUNEDANCER  or
		    player.Class1 == CLASS_KNIGHT  ) then
			settings.profile.options.COMBAT_TYPE  = "melee";
		elseif(
		    player.Class1 == CLASS_PRIEST  or
		    player.Class1 == CLASS_SCOUT   or
--		    player.Class1 == CLASS_DRUID   or
		    player.Class1 == CLASS_MAGE    ) then
			settings.profile.options.COMBAT_TYPE  = "ranged";
		else
			error("undefined player.Class1 in settings.lua", 0);
		end;
	end

end
Profile:

Code: Select all

<profile>
	<options>
		<!-- Try the bot with a new char mage or priest         -->
		<!-- At the pioneer village. Use demo.xml waypoint file -->
		<option name="HP_LOW"        value="85" />
		<option name="MP_LOW_POTION" value="50" />
		<option name="HP_LOW_POTION" value="40" />
		<option name="POTION_COOLDOWN"    value="15" />

		<!-- Combat options -->
		<option name="COMBAT_TYPE"        value="ranged" />	<!-- Choose ranged/melee if not using class default -->
		<option name="COMBAT_RANGED_PULL" value="false" /> <!-- only important for melees -->
		<option name="COMBAT_DISTANCE"    value="500" />
		<option name="MAX_FIGHT_TIME"     value="15" />	<!-- Max time without damage before break -->
		<option name="DOT_PERCENT"        value="90" />
		<option name="ANTI_KS"            value="true" />

		<!-- Waypoint and movement settings -->
		<option name="WAYPOINTS"		value="bigharvest.xml" />
		<option name="RETURNPATH"		value="bigharvest.xml" />
		<option name="PATH_TYPE"		value="waypoints" />	<!-- waypoints | wander -->
		<option name="WANDER_RADIUS"		value="500" />
		<option name="WAYPOINT_DEVIATION"	value="0" />
		<option name="QUICK_TURN" 		value="false" />

		<!-- Attack monsters 3 levels above or 10 below your level -->
		<option name="TARGET_LEVELDIF_ABOVE" value="3" />
		<option name="TARGET_LEVELDIF_BELOW" value="10" />
		
		<!-- Loot settings -->
		<option name="LOOT"               value="true" />
		<option name="LOOT_IN_COMBAT"     value="true" />
		<option name="LOOT_DISTANCE"      value="100" />
		<option name="LOOT_PAUSE_AFTER"   value="10" />		<!-- probability in % for a short rest -->

		<!-- Rest if HP or Mana is below that level -->
		<option name="HP_REST" value="15" />
		<option name="MP_REST" value="15" />

		<!-- Log out and resurrect settings -->
		<option name="LOGOUT_TIME" value="0" />			<!-- in minutes, 0 = timer disabled -->
		<option name="LOGOUT_SHUTDOWN" value="false" />
		<option name="LOGOUT_WHEN_STUCK" value="true" />
		<option name="RES_AUTOMATIC_AFTER_DEATH" value="true" />
	</options>

	<friends>
		<!-- names of friends we help fighting or enemys we don't want to attack -->
		<friend name="MyOtherCharacter1" />
		<friend name="MyOtherCharacter2" />
		<friend name="Elite_Mob_Name1" />
		<friend name="Elite_Mob_Name2" />
	</friends>

	<hotkeys>
		<hotkey name="HP_POTION"    key="VK_MINUS" />
		<hotkey name="MP_POTION"    key="VK_PLUS" />
		<hotkey name="ATTACK"       key="VK_0" />
		<hotkey name="RES_MACRO"    key="VK_9" />
		<hotkey name="LOGOUT_MACRO" key="VK_9" />
	</hotkeys>

	<!-- define your skills depending from your actual primary class -->
	<!-- see the example for a priest/mage respectively mage/priest  -->
	<!-- delete skills you don't have or don't want to use.          -->
	<!-- For more skills to use see /database/skills.xml             -->
	<!-- demo skills for LvL 1 character for all classes             -->
	<skills_priest> 
	        <skill name="PRIEST_SOUL_SOURCE"   hotkey="VK_4" priority="110" inbattle="true" hpper="15" />
	        <skill name="PRIEST_HOLY_AURA"     hotkey="VK_7" priority="100" inbattle="true" hpper="24" />
	        <skill name="PRIEST_URGENT_HEAL"   hotkey="VK_2" priority="100" hpper="30"  />
	        <skill name="PRIEST_REGENERATE"    hotkey="VK_6" priority="90" />
		<skill name="PRIEST_RISING_TIDE"   hotkey="VK_3" priority="80" />
	        <skill name="MAGE_FIREBALL"        hotkey="VK_8" priority="70" />
	        <skill name="PRIEST_WAVE_ARMOR"    hotkey="VK_5" priority="40"  inbattle="true" />
	        <!--skill name="PRIEST_SOUL_BOND"     hotkey="VK_T" priority="30" /> -->
	        <!--skill name="PRIEST_MAGIC_BARRIER" hotkey="VK_F" priority="20" /> -->
	</skills_priest>   
	<skills_warrior> 
		<skill name="WARRIOR_SLASH"          hotkey="VK_2" priority="90" />
		<skill name="WARRIOR_PROBING_ATTACK" hotkey="VK_4" priority="80" />
		<skill name="WARRIOR_OPEN_FLANK"     hotkey="VK_5" priority="70" />		
	</skills_warrior>
	<skills_scout> 
		<skill name="SCOUT_SHOT"        hotkey="VK_2" priority="90" />
		<skill name="SCOUT_AUTOSHOT"    hotkey="VK_4" priority="80" />
		<skill name="SCOUT_WIND_ARROWS" hotkey="VK_5" priority="70" />	
	</skills_scout>
	<skills_rogue> 
		<skill name="ROGUE_SHADOWSTAB"  hotkey="VK_2" priority="90" />
		<skill name="ROGUE_LOW_BLOW"    hotkey="VK_4" priority="80" />
	</skills_rogue>
	<skills_mage>
	        <skill name="PRIEST_HOLY_AURA"      hotkey="VK_7" priority="110" hpper="30" inbattle="true" />
	        <skill name="PRIEST_URGENT_HEAL"    hotkey="VK_2" priority="100" hpper="30"  />
	        <skill name="MAGE_PLASMA_ARROW"     hotkey="VK_4" priority="90" />
	        <skill name="MAGE_FLAME"            hotkey="VK_1" priority="80" />
	        <skill name="PRIEST_REGENERATE"     hotkey="VK_6" priority="70" />
	        <skill name="MAGE_ESSENCE_OF_MAGIC" hotkey="VK_8" priority="60" />
	        <!--skill name="PRIEST_MAGIC_BARRIER"  hotkey="VK_F" priority="50" /> -->     
	</skills_mage>     
	<skills_knight>
		<skill name="KNIGHT_HOLY_STRIKE"  hotkey="VK_3" priority="90" />
		<skill name="KNIGHT_HOLY_SHIELD"  hotkey="VK_4" priority="80"  inbattle="true" hpper="15" />
		<skill name="KNIGHT_HOLY_SEAL"    hotkey="VK_5" priority="70" />
		<skill name="KNIGHT_PUNISHMENT"   hotkey="VK_2" priority="60" />
	</skills_knight>
	<skills_runedancer> 
	</skills_runedancer>
	<skills_druid> 
	</skills_druid>

	<onDeath>
		-- Additional Lua code to execute on death
		-- pauseOnDeath(); -- Stop the script
	</onDeath>

	<onLeaveCombat>
		-- Additional Lua code to execute after killing an enemy
	</onLeaveCombat>

	<onSkillCast>
		-- Additional Lua code to execute when casting a skill
		-- Note: arg1 contains the skill being used.
		-- i.e. arg1.Name will be the name of the skill being cast.
	</onSkillCast>
</profile>
Help,I cant get the damn bot to farm for more than 1 hour,then it gets a memory reading error.When i do rom/update.lua and i SVN update it,i get all sorts of problems.I have the newest SVN Version and I ran the rom\update.lua.

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Bad argument #1 to getkeyname

#2 Post by Administrator » Wed Aug 19, 2009 10:51 pm

Help,I cant get the damn bot to farm for more than 1 hour,then it gets a memory reading error.
What error?
When i do rom/update.lua and i SVN update it,i get all sorts of problems.
What problems?
I have the newest SVN Version and I ran the rom\update.lua.
If you had problems with the SVN update, you do not have the latest version. The error you mentioned earlier has already been fixed.

Suffering
Posts: 34
Joined: Wed Aug 19, 2009 9:14 pm

Re: Bad argument #1 to getkeyname

#3 Post by Suffering » Thu Aug 20, 2009 4:41 pm

Administrator wrote:
Help,I cant get the damn bot to farm for more than 1 hour,then it gets a memory reading error.
What error?
When i do rom/update.lua and i SVN update it,i get all sorts of problems.
What problems?
I have the newest SVN Version and I ran the rom\update.lua.
If you had problems with the SVN update, you do not have the latest version. The error you mentioned earlier has already been fixed.
It obviously hasen't been fixed, I don't know what causing it,but i just checked a second ago that my bot was FULLY updated to svn revision 165.I also ran rom/update.lua.I'v tried deleting everything from the folder,and re-installing the bot.That doesn't work either.Im getting this Bad argument #1 to 'getKeyName' <<null>> error.

Oh and edit:I was having memory reading problems when I ran the bot for more than an hour on the non-updated version of the bot.

d003232
Posts: 1252
Joined: Wed Jun 03, 2009 4:27 pm

Re: Bad argument #1 to getkeyname

#4 Post by d003232 » Thu Aug 20, 2009 4:55 pm

Suffering wrote: I have the newest SVN Version and I ran the rom\update.lua.
If you had problems with the SVN update, you do not have the latest version. The error you mentioned earlier has already been fixed.[/quote]
It obviously hasen't been fixed, I don't know what causing it,but i just checked a second ago that my bot was FULLY updated to svn revision 165.I also ran rom/update.lua.I'v tried deleting everything from the folder,and re-installing the bot.That doesn't work either.Im getting this Bad argument #1 to 'getKeyName' <<null>> error.

Oh and edit:I was having memory reading problems when I ran the bot for more than an hour on the non-updated version of the bot.[/quote]Perhaps the reason is your name :-)

I just see in your profile

Code: Select all

      <hotkey name="RES_MACRO"    key="VK_9" />
      <hotkey name="LOGOUT_MACRO" key="VK_9" />
a double key problem. You should correct that.

We will look deeper for that settings.lua 91 problem. And could you post your micromacro log and MM window content for that memory error? Have you been afk or in front whilte that happens? You will get an memory error, if your client lost the connection, or if you use a teleport or something (happens to me sometimes while I'm botting in the background and writes something in another window, because ingame CTRL+G is some port ... and when I hold CTRL while the bot press G ... :-( ) while botting.
The RoM Bot Online Wiki needs your help!

d003232
Posts: 1252
Joined: Wed Jun 03, 2009 4:27 pm

Re: Bad argument #1 to getkeyname

#5 Post by d003232 » Thu Aug 20, 2009 5:03 pm

And please check your settings.lua line 91. It should be

Code: Select all

	for i,v in pairs(check_keys) do
		if( v.key      == _key  and
		    v.modifier == _modifier ) then
				local modname, keyname;            -- <<<<<<<<<< LINE 91
				if( v.modifier ) then modname = getKeyName(v.modifier); end;
				if( v.key ) then keyname = getKeyName(v.key); end;

				local errstr = sprintf("Error: You assigned the key \'%s %s\' double: for \'%s\' and for \'%s\'.\n",
					tostring(modname), tostring(keyname), v.name, _name) .. "Please check your settings!";
				error(errstr, 0);
		if( _key == nil) then
			cprintf(cli.yellow, "Error: The key for \'%s\' is empty!\n", _name);
			error("Please check your settings!", 0);
I suppose also you are not at SVN 165. Pls post that part of your settings.lua.
The RoM Bot Online Wiki needs your help!

Suffering
Posts: 34
Joined: Wed Aug 19, 2009 9:14 pm

Re: Bad argument #1 to getkeyname

#6 Post by Suffering » Thu Aug 20, 2009 5:04 pm

d003232 wrote:And please check your settings.lua line 91. It should be

Code: Select all

	for i,v in pairs(check_keys) do
		if( v.key      == _key  and
		    v.modifier == _modifier ) then
				local modname, keyname;            -- <<<<<<<<<< LINE 91
				if( v.modifier ) then modname = getKeyName(v.modifier); end;
				if( v.key ) then keyname = getKeyName(v.key); end;

				local errstr = sprintf("Error: You assigned the key \'%s %s\' double: for \'%s\' and for \'%s\'.\n",
					tostring(modname), tostring(keyname), v.name, _name) .. "Please check your settings!";
				error(errstr, 0);
		if( _key == nil) then
			cprintf(cli.yellow, "Error: The key for \'%s\' is empty!\n", _name);
			error("Please check your settings!", 0);
I suppose also you are not at SVN 165. Pls post that part of your settings.lua.
I posted that last night,That settings file was on the 162 revision i believe

Well,yes i was afk,but i wasn't using an updated version of the bot whenever i got that memory error.
But yeah ill fix that,and here ill post my NEW Settings.lua.

d003232
Posts: 1252
Joined: Wed Jun 03, 2009 4:27 pm

Re: Bad argument #1 to getkeyname

#7 Post by d003232 » Thu Aug 20, 2009 5:06 pm

Suffering wrote:
d003232 wrote:And please check your settings.lua line 91. It should be

Code: Select all

	for i,v in pairs(check_keys) do
		if( v.key      == _key  and
		    v.modifier == _modifier ) then
				local modname, keyname;            -- <<<<<<<<<< LINE 91
				if( v.modifier ) then modname = getKeyName(v.modifier); end;
				if( v.key ) then keyname = getKeyName(v.key); end;

				local errstr = sprintf("Error: You assigned the key \'%s %s\' double: for \'%s\' and for \'%s\'.\n",
					tostring(modname), tostring(keyname), v.name, _name) .. "Please check your settings!";
				error(errstr, 0);
		if( _key == nil) then
			cprintf(cli.yellow, "Error: The key for \'%s\' is empty!\n", _name);
			error("Please check your settings!", 0);
I suppose also you are not at SVN 165. Pls post that part of your settings.lua.
I posted that last night,That settings file was on the 162 revision i believe
ok. I can reproduce the error. :roll:
The RoM Bot Online Wiki needs your help!

Suffering
Posts: 34
Joined: Wed Aug 19, 2009 9:14 pm

Re: Bad argument #1 to getkeyname

#8 Post by Suffering » Thu Aug 20, 2009 5:08 pm

Code: Select all

settings_default = {
	hotkeys = {
		MOVE_FORWARD = {key = _G.key.VK_W, modifier = nil},
		MOVE_BACKWARD = {key = _G.key.VK_S, modifier = nil},
		ROTATE_LEFT = {key = _G.key.VK_A, modifier = nil},
		ROTATE_RIGHT = {key = _G.key.VK_D, modifier = nil},
		STRAFF_LEFT = {key = _G.key.VK_Q, modifier = nil},
		STRAFF_RIGHT = {key = _G.key.VK_E, modifier = nil},
		JUMP = {key = _G.key.VK_SPACE, modifier = nil},
		TARGET = {key = _G.key.VK_TAB, modifier = nil},
		TARGET_FRIEND = {key = _G.key.J, modifier = nil},
		START_BOT = {key = _G.key.VK_DELETE, modifier = nil},
		STOP_BOT = {key = _G.key.VK_END, modifier = nil}
	},
	options = {
		ENABLE_FIGHT_SLOW_TURN = false,
		MELEE_DISTANCE = 45,
		LANGUAGE = "english",
		DEBUG_ASSERT = false,
	},
	profile = {
		options = {
			-- common options
			HP_LOW = 85,
			MP_LOW_POTION = 50,
			HP_LOW_POTION = 40,
			COMBAT_TYPE = "melee",
			COMBAT_RANGED_PULL = "true",	-- only for melee classes 
			COMBAT_DISTANCE = 200,
			ANTI_KS = true,
			WAYPOINTS = "myWaypoints.xml",
			RETURNPATH = nil,
			PATH_TYPE = "waypoints",
			WANDER_RADIUS = 500,
			WAYPOINT_DEVIATION = 0,
			LOOT = true,
			LOOT_TIME = 2000,
			LOOT_IN_COMBAT = true,
			LOOT_DISTANCE = nil,
			LOOT_PAUSE_AFTER = 10,	-- probability for short pause after loot to look more human
			POTION_COOLDOWN = 15,
			MAX_FIGHT_TIME = 12,
			DOT_PERCENT = 90,
			LOGOUT_TIME = 0,
			LOGOUT_SHUTDOWN = false,
			LOGOUT_WHEN_STUCK = true,
			MAX_UNSTICK_TRIALS = 10,
			TARGET_LEVELDIF_BELOW = 99,
			TARGET_LEVELDIF_ABOVE = 99,
			QUICK_TURN = false,
			MP_REST = 15,
			HP_REST = 15,
			RES_AUTOMATIC_AFTER_DEATH = false,	-- automatic resurrect after death true | false,

			
			-- expert options
			WAYPOINTS_REVERSE = false,	-- use the waypoint file in reverse order
			MAX_DEATHS = 10,		-- maximal death if automatic resurrect befor logout
			WAIT_TIME_AFTER_RES = 8000,	-- time to wait after resurrection, needs more on slow PCs
			RETURNPATH_SUFFIX = "_return",	-- suffix for default naming of returnpath
			HARVEST_SCAN_WIDTH = 10,	-- steps horizontal
			HARVEST_SCAN_HEIGHT = 8,	-- steps vertical
			HARVEST_SCAN_STEPSIZE = 35,	-- wide of every step
			HARVEST_SCAN_TOPDOWN = true,	-- true = top->down  false = botton->up
			HARVEST_SCAN_XMULTIPLIER = 1.0,	-- multiplier for scan width
			HARVEST_SCAN_YMULTIPLIER = 1.1,	-- multiplier for scan line height
			HARVEST_SCAN_YREST = 10,	-- scanspeed
			USE_SLEEP_AFTER_RESUME = false, -- enter sleep mode afer pressing pause key
			
		}, hotkeys = {}, skills = {}, friends = {},
		events = {
			onDeath = function () pauseOnDeath(); end,
			onLoad = nil,
			onLeaveCombat = nil,
			onSkillCast = nil,
		}
	},
};

settings = settings_default;


-- check if keys are double assigned or empty
check_keys = { };
function check_double_key_settings( _name, _key, _modifier )
	--if( _modifier == "" ) then _modifier = nil; end;

	for i,v in pairs(check_keys) do
		if( v.key      == _key  and
		    v.modifier == _modifier ) then
				local modname, keyname;
				if( v.modifier ) then modname = getKeyName(v.modifier); end;
				if( v.key ) then keyname = getKeyName(v.key); end;

				local errstr = sprintf("Error: You assigned the key \'%s %s\' double: for \'%s\' and for \'%s\'.\n",
					tostring(modname), tostring(keyname), v.name, _name) .. "Please check your settings!";
				error(errstr, 0);
		if( _key == nil) then
			cprintf(cli.yellow, "Error: The key for \'%s\' is empty!\n", _name);
			error("Please check your settings!", 0);
		end

		end
	end;
	
	-- check the using of modifiers
	if( _modifier ~= nil) then
		local modname, keyname;
		if( _modifier ) then modname = getKeyName(_modifier); end;
		if( _key ) then keyname = getKeyName(_key); end;

		cprintf(cli.yellow, "Due to technical reasons, we don't support "..
		   "modifiers like CTRL/ALT/SHIFT for hotkeys at the moment. "..
		   "Please change your hotkey %s-%s for \'%s\'\n", tostring(modname), tostring(keyname), _name);
		   
		   -- only a warning for TARGET_FRIEND / else an error
		   if(_name == "TARGET_FRIEND") then
		   	cprintf(cli.yellow, "You can't use the player:target_NPC() function until changed!\n");
		   else
		   	error("Please check your settings!", 0);
		   end
	end

	
	local tmp = {};
	tmp.name = _name;
	tmp.key  = _key;
	tmp.modifier  = _modifier;	
	table.insert(check_keys, tmp);	

end

function settings.load()
	local filename = getExecutionPath() .. "/settings.xml";
	local root = xml.open(filename);
	local elements = root:getElements();

	-- Specific to loading the hotkeys section of the file
	local loadHotkeys = function (node)
		local elements = node:getElements();
		for i,v in pairs(elements) do
			-- If the hotkey doesn't exist, create it.
			settings.hotkeys[ v:getAttribute("description") ] = { };
			settings.hotkeys[ v:getAttribute("description") ].key = key[v:getAttribute("key")];
			settings.hotkeys[ v:getAttribute("description") ].modifier = key[v:getAttribute("modifier")];

			if( key[v:getAttribute("key")] == nil ) then
				local err = sprintf("settings.xml error: %s does not have a valid hotkey!", v:getAttribute("description"));
				error(err, 0);
			end

			check_double_key_settings( v:getAttribute("description"), v:getAttribute("key"), v:getAttribute("modifier") );
		end
	end

	local loadOptions = function (node)
		local elements = node:getElements();
		for i,v in pairs(elements) do
			settings.options[ v:getAttribute("name") ] = v:getAttribute("value");
		end
	end

	-- load RoM keyboard bindings.txt file
	local function load_RoM_bindings_txt()
		
		local filename, file;
		
		local userprofilePath = os.getenv("USERPROFILE");
		local documentPaths = {
			userprofilePath .. "\\My Documents\\", -- English
			userprofilePath .. "\\Eigene Dateien\\", -- German
			userprofilePath .. "\\Mes Documents\\", -- French
			userprofilePath .. "\\Omat tiedostot\\", -- Finish
			userprofilePath .. "\\Belgelerim\\", -- Turkish
			userprofilePath .. "\\Mina Dokument\\", -- Swedish
			userprofilePath .. "\\Dokumenter\\", -- Danish
			userprofilePath .. "\\Documenti\\", -- Italian
			userprofilePath .. "\\Mijn documenten\\", -- Dutch
			userprofilePath .. "\\Moje dokumenty\\", -- Polish
			userprofilePath .. "\\Mis documentos\\", -- Spanish
--			"F:\\privat\\",
		};

		-- Select the first path that exists
		for i,v in pairs(documentPaths) do
			local filename = v .. "Runes of Magic\\bindings.txt"
			if( fileExists(filename) ) then
				file = io.open(filename, "r");
				cprintf(cli.green, "We read the hotkey settings from your "..
				   "bindings.txt file %s instead of using the settings.lua file.\n", filename)
			end
		end

		-- If we wern't able to locate a document path, return.
		if( file == nil ) then
			return;
		end


		-- Load bindings.txt into own table structure
		bindings = { name = { } };
		-- read the lines in table 'lines'
		for line in file:lines() do
			for name, key1, key2 in string.gfind(line, "(%w*)%s([%w+]*)%s*([%w+]*)") do
				bindings[name] = {};
				bindings[name].key1 = key1;
				bindings[name].key2 = key2;

				--settings.hotkeys[name].key = 
			end
		end

		local function bindHotkey(bindingName)
			local links = { -- Links forward binding names to hotkey names
				MOVEFORWARD = "MOVE_FORWARD",
				MOVEBACKWARD = "MOVE_BACKWARD",
				TURNLEFT = "ROTATE_LEFT",
				TURNRIGHT = "ROTATE_RIGHT",
				STRAFELEFT = "STRAFF_LEFT",
				STRAFERIGHT = "STRAFF_RIGHT",
				TARGETNEARESTENEMY = "TARGET",
				TARGETNEARESTFRIEND = "TARGET_FRIEND",	
			};

			local hotkeyName = bindingName;
			if(links[bindingName] ~= nil) then
				hotkeyName = links[bindingName];
			end;


			if( bindings[bindingName] ~= nil ) then
				if( bindings[bindingName].key1 ~= nil ) then
					-- Fix key names
					bindings[bindingName].key1 = string.gsub(bindings[bindingName].key1, "CTRL", "CONTROL");

					if( string.find(bindings[bindingName].key1, '+') ) then
						local parts = explode(bindings[bindingName].key1, '+');
						-- parts[1] = modifier
						-- parts[2] = key

						settings.hotkeys[hotkeyName].key = key["VK_" .. parts[2]];
						settings.hotkeys[hotkeyName].modifier = key["VK_" .. parts[1]];
					else
						settings.hotkeys[hotkeyName].key = key["VK_" .. bindings[bindingName].key1];
					end
					
					check_double_key_settings( hotkeyName, settings.hotkeys[hotkeyName].key, 
					  settings.hotkeys[hotkeyName].modifier );
				end
			end
		end

		bindHotkey("MOVEFORWARD");
		bindHotkey("MOVEBACKWARD");
		bindHotkey("TURNLEFT");
		bindHotkey("TURNRIGHT");
		bindHotkey("STRAFELEFT");
		bindHotkey("STRAFERIGHT");
		bindHotkey("JUMP");
		bindHotkey("TARGETNEARESTENEMY");
		bindHotkey("TARGETNEARESTFRIEND");
	end

	-- check ingame settings
	-- only if we can find the bindings.txt file
	local function check_ingame_settings( _name, _ingame_key)
		
		if( not bindings ) then		-- no bindings.txt file loaded
			return
		end;
		
		if( settings.hotkeys[_name].key ~= key["VK_"..bindings[_ingame_key].key1] and
		    settings.hotkeys[_name].key ~= key["VK_"..bindings[_ingame_key].key2] ) then
			cprintf(cli.yellow, "Your bot settings for hotkey \'%s\' in settings.xml "..
			   "don't match your RoM ingame keyboard settings.\n",
			        _name);
			error("Please check your settings!", 0);
		end
	end


	function checkHotkeys(_name, _ingame_key)
		if( not settings.hotkeys[_name] ) then
			error("ERROR: Global hotkey not set: " .. _name, 0);
		end
		
		-- check if settings.lua hotkeys match the RoM ingame settings
		-- check_ingame_settings( _name, _ingame_key);
	end


	for i,v in pairs(elements) do
		local name = v:getName();

		if( string.lower(name) == "hotkeys" ) then
			loadHotkeys(v);
		elseif( string.lower(name) == "options" ) then
			loadOptions(v);
		end
	end


	load_RoM_bindings_txt();	-- read bindings.txt from RoM user folder
	
	-- Check to make sure everything important is set
	--           bot hotkey name    RoM ingame key name         
	checkHotkeys("MOVE_FORWARD",   "MOVEFORWARD");
	checkHotkeys("MOVE_BACKWARD",  "MOVEBACKWARD");
	checkHotkeys("ROTATE_LEFT",    "TURNLEFT");
	checkHotkeys("ROTATE_RIGHT",   "TURNRIGHT");
	checkHotkeys("STRAFF_LEFT",    "STRAFELEFT");
	checkHotkeys("STRAFF_RIGHT",   "STRAFERIGHT");
	checkHotkeys("JUMP",           "JUMP");
	checkHotkeys("TARGET",         "TARGETNEARESTENEMY");
	checkHotkeys("TARGET_FRIEND",  "TARGETNEARESTFRIEND");
	
end


function settings.loadProfile(_name)
	-- Delete old profile settings (if they even exist), restore defaults
	settings.profile = settings_default.profile;

	local filename = getExecutionPath() .. "/profiles/" .. _name .. ".xml";
	local root = xml.open(filename);
	local elements = root:getElements();

	local loadOptions = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			settings.profile.options[v:getAttribute("name")] = v:getAttribute("value");
		end
	end

	local loadHotkeys = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			settings.profile.hotkeys[v:getAttribute("name")] = {};
			settings.profile.hotkeys[v:getAttribute("name")].key = key[v:getAttribute("key")];
			settings.profile.hotkeys[v:getAttribute("name")].modifier = key[v:getAttribute("modifier")];

			if( key[v:getAttribute("key")] == nil ) then
				local err = sprintf("Profile error: Please set a valid key for "..
				  "hotkey %s in your profile file \'%s.xml\'.", tostring(v:getAttribute("name")), name );
				error(err, 0);
			end
			check_double_key_settings( v:getAttribute("name"), v:getAttribute("key"), v:getAttribute("modifier") );
		end
	end

	local loadonLoadEvent = function(node)
		local luaCode = tostring(node:getValue());

		if( string.len(luaCode) > 0 and string.find(luaCode, "%w") ) then
			settings.profile.events.onLoad = loadstring(luaCode);
			if( type(settings.profile.events.onLoad) ~= "function" ) then
				settings.profile.events.onLoad = nil;
			end;
		end
	end

	local loadOnDeathEvent = function(node)
		local luaCode = tostring(node:getValue());

		if( string.len(luaCode) > 0 and string.find(luaCode, "%w") ) then
			settings.profile.events.onDeath = loadstring(luaCode);
			if( type(settings.profile.events.onDeath) ~= "function" ) then
				settings.profile.events.onDeath = nil;
			end;
		end
	end

	local loadOnLeaveCombatEvent = function(node)
		local luaCode = tostring(node:getValue());

		if( string.len(luaCode) > 0 and string.find(luaCode, "%w") ) then
			settings.profile.events.onLeaveCombat = loadstring(luaCode);
			if( type(settings.profile.events.onLeaveCombat) ~= "function" ) then
				settings.profile.events.onLeaveCombat = nil;
			end;
		end
	end

	local loadOnSkillCastEvent = function(node)
		local luaCode = tostring(node:getValue());

		if( string.len(luaCode) > 0 and string.find(luaCode, "%w") ) then
			settings.profile.events.onSkillCast = loadstring(luaCode);
			if( type(settings.profile.events.onSkillCast) ~= "function" ) then
				settings.profile.events.onSkillCast = nil;
			end;
		end
	end


	local skillSort = function(tab1, tab2)
		if( tab2.priority < tab1.priority ) then
			return true;
		end;

		return false;
	end

	local loadSkills = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			local name, hotkey, modifier, level;
			name = v:getAttribute("name");
			hotkey = key[v:getAttribute("hotkey")];
			modifier = key[v:getAttribute("modifier")];
			level = v:getAttribute("level");

			check_double_key_settings( v:getAttribute("name"), v:getAttribute("hotkey") );

			-- Over-ride attributes
			local priority, maxhpper, inbattle, pullonly, maxuse
			priority = v:getAttribute("priority");
			maxhpper = tonumber(v:getAttribute("hpper"));
			inbattle = v:getAttribute("inbattle");
			pullonly = v:getAttribute("pullonly");
			maxuse = tonumber(v:getAttribute("maxuse"));

			-- check if 'wrong' options are set
			if( v:getAttribute("mana")      or
			    v:getAttribute("manainc")   or
			    v:getAttribute("rage")      or
			    v:getAttribute("energy")    or
			    v:getAttribute("concentration")      or
			    v:getAttribute("range")     or
			    v:getAttribute("cooldown")  or
			    v:getAttribute("minrange")  or
			    v:getAttribute("type")      or
			    v:getAttribute("target")    or
			    v:getAttribute("casttime") ) then
			    	cprintf(cli.yellow, "The options \'mana\', \'manainc\', \'rage\', "..
			    	   "\'energy\', \'concentration\', \'range\', "..
			    	   "\'cooldown\', \'minrange\', \'type\', \'target\' and \'casttime\' "..
			    	   "are no valid options for your skill \'%s\' in your profile \'%s.xml\'. "..
			    	   "Please delete them and restart!\n", name, _name);
			    	   error("Bot finished due of errors above.\n", 0);
			end;
			if( v:getAttribute("modifier") ) then
			    	cprintf(cli.yellow, "The options \'modifier\' "..
			    	  "for your skill \'%s\' in your profile \'%s.xml\' "..
			    	  "is not supported at the moment. "..
			    	  "Please delete it and restart!\n", name, _name);
				error("Bot finished due of errors above.\n", 0);
			end;

			if( name == nil) then
			    	cprintf(cli.yellow, "You defined an \'empty\' skill name in "..
			    	  "your profile \'%s.xml\'. Please delete or correct "..
			    	  "that line!\n", _name);
				error("Bot finished due of errors above.\n", 0);
			end;

			if( inbattle ~= nil ) then
				if( inbattle == "true" or 
				    inbattle == true ) then
					inbattle = true;
				elseif( inbattle == "false"  or
					inbattle == false ) then
					inbattle = false;
				else
						cprintf(cli.yellow, "You defined an wrong option inbattle=\'%s\' at skill %s in "..
						  "your profile \'%s.xml\'. Please delete or correct "..
						  "that line!\n", inbattle, name, _name);
					error("Bot finished due of errors above.\n", 0);
				end;
			end

			if( pullonly ~= nil ) then
				if( pullonly == "true" or
					pullonly == true ) then
					pullonly = true;
				else
						cprintf(cli.yellow, "You defined an wrong option pullonly=\'%s\' at skill %s in "..
						  "your profile \'%s.xml\'. Only \'true\' is possible. Please delete or correct "..
						  "that line!\n", pullonly, name, _name);
					error("Bot finished due of errors above.\n", 0);
				end;
			end

			if( level == nil or level < 1 ) then
				level = 1;
			end

			local baseskill = database.skills[name];
			if( not baseskill ) then
				local err = sprintf("ERROR: \'%s\' is not defined in the database!", name);
				error(err, 0);
			end

			local tmp = CSkill(database.skills[name]);
			tmp.hotkey = hotkey;
			tmp.modifier = modifier;
			tmp.Level = level;

			if( toggleable ) then tmp.Toggleable = toggleable; end;
			if( priority ) then tmp.priority = priority; end
			if( maxhpper ) then tmp.MaxHpPer = maxhpper; end;
			if( inbattle ~= nil ) then tmp.InBattle = inbattle; end;
			if( pullonly == true ) then tmp.pullonly = pullonly; end;
			if( maxuse ) then tmp.maxuse = maxuse; end;

			table.insert(settings.profile.skills, tmp);
		end

		table.sort(settings.profile.skills, skillSort);

	end

	local loadFriends = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			local name = v:getAttribute("name");
			table.insert(settings.profile.friends, name);
		end
	end

	local hf_temp = _name;	-- remember profile name shortly

	for i,v in pairs(elements) do
		local name = v:getName();

		if( string.lower(name) == "options" ) then
			loadOptions(v);
		elseif( string.lower(name) == "hotkeys" ) then
			loadHotkeys(v);
		elseif( string.lower(name) == "skills" ) then
			loadSkills(v);
		elseif( string.lower(name) == "friends" ) then
			loadFriends(v);
		elseif( string.lower(name) == "onLoad" ) then
			loadonLoadEvent(v);
		elseif( string.lower(name) == "ondeath" ) then
			loadOnDeathEvent(v);
		elseif( string.lower(name) == "onleavecombat" ) then
			loadOnLeaveCombatEvent(v);
		elseif( string.lower(name) == "onskillcast" ) then
			loadOnSkillCastEvent(v);
		elseif( string.lower(name) == "skills_warrior"  and
		        player.Class1 == CLASS_WARRIOR ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_scout"  and
		        player.Class1 == CLASS_SCOUT ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_rogue"  and
		        player.Class1 == CLASS_ROGUE ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_mage"  and
		        player.Class1 == CLASS_MAGE ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_priest"  and
		        player.Class1 == CLASS_PRIEST ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_knight"  and
		        player.Class1 == CLASS_KNIGHT ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_runedancer"  and
		        player.Class1 == CLASS_RUNEDANCER ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_druid"  and
		        player.Class1 == CLASS_DRUID ) then
			loadSkills(v);
		else		-- warning for other stuff and misspellings
			if ( string.lower(name) ~= "skills_warrior"     and
			     string.lower(name) ~= "skills_scout"       and
		 	     string.lower(name) ~= "skills_rogue"       and
	 		     string.lower(name) ~= "skills_mage"        and
			     string.lower(name) ~= "skills_priest"      and
			     string.lower(name) ~= "skills_knight"      and
			     string.lower(name) ~= "skills_runedancer"  and
			     string.lower(name) ~= "skills_druid" )     then
				cprintf(cli.yellow, tostring(language[60]), string.lower(tostring(name)),
					tostring(hf_temp));
			end;
		end
	end


	function checkProfileHotkeys(name)
		if( not settings.profile.hotkeys[name] ) then
			error("ERROR: Hotkey not set for this profile: " ..name, 0);
		end
	end

	-- Check to make sure everything important is set
	checkProfileHotkeys("ATTACK");

	-- default combat type if not in profile defined
	if( settings.profile.options.COMBAT_TYPE ~= "ranged" and 
	    settings.profile.options.COMBAT_TYPE ~= "melee" ) then
		if( player.Class1 == CLASS_WARRIOR or
		    player.Class1 == CLASS_ROGUE   or
--		    player.Class1 == CLASS_RUNEDANCER  or
		    player.Class1 == CLASS_KNIGHT  ) then
			settings.profile.options.COMBAT_TYPE  = "melee";
		elseif(
		    player.Class1 == CLASS_PRIEST  or
		    player.Class1 == CLASS_SCOUT   or
--		    player.Class1 == CLASS_DRUID   or
		    player.Class1 == CLASS_MAGE    ) then
			settings.profile.options.COMBAT_TYPE  = "ranged";
		else
			error("undefined player.Class1 in settings.lua", 0);
		end;
	end

end
The new 165 revision also has this problem with me.Could it be my name?
Also the memory errors i would get with the older version were random cpawn errors,the debug didn't work either.
I'm going to make a new name and see if i works.A short name.

d003232
Posts: 1252
Joined: Wed Jun 03, 2009 4:27 pm

Re: Bad argument #1 to getkeyname

#9 Post by d003232 » Thu Aug 20, 2009 5:18 pm

Suffering wrote:I'm going to make a new name and see if i works.A short name.
No !!! Please don't. That was only a joke !!!

Just change the double key settings from

Code: Select all

<hotkey name="RES_MACRO"    key="VK_9" />
<hotkey name="LOGOUT_MACRO" key="VK_9" />
here and you won't get the error ... and I will look, what's the reason for that bug with the error message.
The RoM Bot Online Wiki needs your help!

Suffering
Posts: 34
Joined: Wed Aug 19, 2009 9:14 pm

Re: Bad argument #1 to getkeyname

#10 Post by Suffering » Thu Aug 20, 2009 5:25 pm

Now im getting another error.I'm getting pawn.lua:173 Bad argument #2 to "sprintf" <<null>>
Heres my pawn.lua:

Code: Select all

PT_NONE = 0;
PT_PLAYER = 1;
PT_MONSTER = 2;
PT_NPC = 4;
PT_NODE = 4;

CLASS_NONE = -1;
CLASS_WARRIOR = 1;
CLASS_SCOUT = 2;
CLASS_ROGUE = 3;
CLASS_MAGE = 4;
CLASS_PRIEST = 5;
CLASS_KNIGHT = 6;
CLASS_RUNEDANCER = 7;
CLASS_DRUID = 8;

ATTACKABLE_MASK_PLAYER = 0x10000;
ATTACKABLE_MASK_MONSTER = 0xE0000;

local classEnergyMap = {
	[CLASS_NONE] = "none",
	[CLASS_WARRIOR] = "rage",
	[CLASS_SCOUT] = "concentration",
	[CLASS_ROGUE] = "energy",
	[CLASS_MAGE] = "mana",
	[CLASS_PRIEST] = "mana",
	[CLASS_KNIGHT] = "mana",
	[CLASS_RUNEDANCER] = "mana",
	[CLASS_DRUID] = "mana",
};

CPawn = class(
	function (self, ptr)
		self.Address = ptr;
		self.Name = "<UNKNOWN>";
		self.Id = 0;
		self.Type = PT_NONE;
		self.Guild = "<UNKNOWN>";
		self.Level = 1;
		self.Level2 = 1;
		self.HP = 1000;
		self.MaxHP = 1000;
		self.MP = 1000;
		self.MaxMP = 1000;
		self.MP2 = 1000;
		self.MaxMP2 = 1000;
		self.X = 0.0;
		self.Y = 0.0;
		self.Z = 0.0;
		self.TargetPtr = 0;
		self.Direction = 0.0;
		self.Attackable = false;
		self.Alive = true;


		-- Directed more at player, but may be changed later.
		self.Battling = false; -- The actual "in combat" flag.
		self.Fighting = false; -- Internal use, does not depend on the client's battle flag
		self.Casting = false;
		self.Mana = 0;
		self.MaxMana = 0;
		self.Rage = 0;
		self.MaxRage = 0;
		self.Energy = 0;
		self.MaxEnergy = 0;
		self.Concentration = 0;
		self.MaxConcentration = 0;
		self.PotionLastUseTime = 0;
		self.Returning = false;		-- Whether following the return path, or regular waypoints
		self.BotStartTime = os.time(); -- Records when the bot was started.
		self.BotStartTime_nr = os.time(); -- Records when the bot was started, will not return at pause
		self.Unstick_counter = 0;	-- counts unstick tries, resets if waypoint reached
		self.Success_waypoints = 0; -- count consecutively successfull reached waypoints 
		self.Cast_to_target = 0;	-- count casts to our enemy target
		self.LastAggroTimout = 0;	-- remeber last time we wait in vain for an aggro mob
		self.Sleeping = false;		-- sleep mode with fight back if attacked
		self.Sleeping_time = 0;		-- counts the sleeping time
		self.Fights = 0;			-- counts the fights
		self.Death_counter = 0;		-- counts deaths / automatic reanimation
		self.Current_waypoint_type = WPT_NORMAL;	-- remember current waypoint type global
		self.Last_ignore_target_ptr = 0;		-- last target to ignore
		self.Last_ignore_target_time = 0;		-- last target to ignore
		self.lastHitTime = 0;				-- last time the HP of the target changed
		self.ranged_pull = false;			-- ranged pull phase active
		self.free_field1 = nil;				-- free field for user use
		self.free_field2 = nil;				-- free field for user use
		self.free_field3 = nil;				-- free field for user use
		self.free_counter1 = 0;				-- free counter for user use
		self.free_counter2 = 0;				-- free counter for user use
		self.free_counter3 = 0;				-- free counter for user use		
		self.free_flag1 = false;			-- free flag for user use
		self.free_flag2 = false;			-- free flag for user use
		self.free_flag3 = false;			-- free flag for user use		

		
		if( self.Address ~= 0 and self.Address ~= nil ) then self:update(); end
	end
);

function CPawn:update()
	local proc = getProc();
	local memerrmsg = "Failed to read memory";
	local tmp;

	local function replace_UTF8( _str, _ascii )
		local tmp = database.utf8_ascii[_ascii];
		_str = string.gsub(_str, string.char(tmp.utf8_1, tmp.utf8_2), string.char(_ascii) );
		return _str
	end

	-- we only replace umlaute, hence only that are importent for mob names
	-- player names are at the moment not importent for the MM protocol
	-- player names will be handled while loading the profile
	local function UTF8_to_ASCII(_str)
		_str = replace_UTF8(_str, 132);		-- ä
		_str = replace_UTF8(_str, 142);		-- Ä
		_str = replace_UTF8(_str, 148);		-- ö
		_str = replace_UTF8(_str, 153);		-- Ö
		_str = replace_UTF8(_str, 129);		-- ü
		_str = replace_UTF8(_str, 154);		-- Ü
		_str = replace_UTF8(_str, 225);		-- ß
		return _str;
	end

	tmp = debugAssert(memoryReadByte(proc, self.Address + charAlive_offset), memerrmsg);
	self.Alive = not(tmp == 9 or tmp == 8);
	self.HP = debugAssert(memoryReadInt(proc, self.Address + charHP_offset), memerrmsg);

	self.MaxHP = debugAssert(memoryReadInt(proc, self.Address + charMaxHP_offset), memerrmsg);
	self.MP = debugAssert(memoryReadInt(proc, self.Address + charMP_offset), memerrmsg);
	self.MaxMP = debugAssert(memoryReadInt(proc, self.Address + charMaxMP_offset), memerrmsg);
	self.MP2 = debugAssert(memoryReadInt(proc, self.Address + charMP2_offset), memerrmsg);
	self.MaxMP2 = debugAssert(memoryReadInt(proc, self.Address + charMaxMP2_offset), memerrmsg);

	self.Id = debugAssert(memoryReadUInt(proc, self.Address + pawnId_offset), memerrmsg);
	self.Type = debugAssert(memoryReadInt(proc, self.Address + pawnType_offset), memerrmsg);

	-- Disable memory warnings for name reading only
	showWarnings(false);
	local namePtr = debugAssert(memoryReadUInt(proc, self.Address + charName_offset), memerrmsg);
--	self.Name = debugAssert(memoryReadString(proc, namePtr), memerrmsg);
	if( namePtr == nil or namePtr == 0 ) then
		tmp = nil;
	else
		tmp = debugAssert(memoryReadString(proc, namePtr));
	end
	showWarnings(true); -- Re-enable warnings after reading

	-- UTF8 -> ASCII translation not for player names
	if( tmp == nil ) then
		self.Name = "<UNKNOW>";
	elseif(self.Type == PT_PLAYER ) then
		self.Name = tmp;
	else
		self.Name = UTF8_to_ASCII(tmp);
	end

	self.Level = debugAssert(memoryReadInt(proc, self.Address + charLevel_offset), memerrmsg);
	self.Level2 = debugAssert(memoryReadInt(proc, self.Address + charLevel2_offset), memerrmsg);

	self.TargetPtr = debugAssert(memoryReadInt(proc, self.Address + charTargetPtr_offset), memerrmsg);

	self.X = debugAssert(memoryReadFloat(proc, self.Address + charX_offset), memerrmsg);
	self.Y = debugAssert(memoryReadFloat(proc, self.Address + charY_offset), memerrmsg);
	self.Z = debugAssert(memoryReadFloat(proc, self.Address + charZ_offset), memerrmsg);

	local attackableFlag = debugAssert(memoryReadInt(proc, self.Address + pawnAttackable_offset), memerrmsg);
	--printf("attackableFlag: %d  (0x%X)\n", attackableFlag, self.Address + pawnAttackable_offset);

	if( self.Type == PT_MONSTER ) then
		self.Attackable = true;
	else
		if( bitAnd(attackableFlag, ATTACKABLE_MASK_PLAYER) ) then
			self.Attackable = true;
		else
			self.Attackable = false;
		end
	end

	self.Class1 = debugAssert(memoryReadInt(proc, self.Address + charClass1_offset), memerrmsg);
	self.Class2 = debugAssert(memoryReadInt(proc, self.Address + charClass2_offset), memerrmsg);

	if( self.MaxMP == 0 ) then
		-- Prevent division by zero for entities that have no mana
		self.MP = 1;
		self.MaxMP = 1;
	end

	if( self.MaxMP2 == 0 ) then
		-- Prevent division by zero for entities that have no secondary mana
		self.MP2 = 1;
		self.MaxMP2 = 1;
	end

	if( self.Alive ==nil or self.HP == nil or self.MaxHP == nil or self.MP == nil or self.MaxMP == nil or
		self.MP2 == nil or self.MaxMP2 == nil or self.Name == nil or
		self.Level == nil or self.Level2 == nil or self.TargetPtr == nil or
		self.X == nil or self.Y == nil or self.Z == nil or self.Attackable == nil ) then

		error("Error reading memory in CPawn:update()");
	end


	-- Set the correct mana/rage/whatever
	local energyStorage1;
	local energyStorage2;

	energyStorage1 = classEnergyMap[self.Class1];
	energyStorage2 = classEnergyMap[self.Class2];
	if( energyStorage1 == energyStorage2 ) then
		energyStorage2 = "none";
	end;



	if( energyStorage1 == "mana" ) then
		self.Mana = self.MP;
		self.MaxMana = self.MaxMP;
	elseif( energyStorage1 == "rage" ) then
		self.Rage = self.MP;
		self.MaxRage = self.MaxMP;
	elseif( energyStorage1 == "energy" ) then
		self.Energy = self.MP;
		self.MaxEnergy = self.MaxMP;
	elseif( energyStorage1 == "concentration" ) then
		self.Concentration = self.MP;
		self.MaxConcentration = self.MaxMP;
	end

	if( energyStorage2 == "mana" ) then
		self.Mana = self.MP2;
		self.MaxMana = self.MaxMP2;
		elseif( energyStorage2 == "rage" ) then
		self.Rage = self.MP2;
		self.MaxRage = self.MaxMP2;
	elseif( energyStorage2 == "energy" ) then
		self.Energy = self.MP2;
		self.MaxEnergy = self.MaxMP2;
		elseif( energyStorage2 == "concentration" ) then
		self.Concentration = self.MP2;
		self.MaxConcentration = self.MaxMP2;
	end
end

function CPawn:haveTarget()
	local proc = getProc();
	self.TargetPtr = memoryReadInt(proc, self.Address + charTargetPtr_offset);
	if( self.TargetPtr == nil ) then self.TargetPtr = 0; end;

	if( self.TargetPtr == 0 ) then
		return false;
	end;

	local tmp = CPawn(self.TargetPtr);

	-- You can't be your own target!
	if( self.TargetPtr == self.Address ) then
		return false;
	end

	if( tmp.HP < 1 ) then
		return false;
	end;

	return (tmp.Alive);
end

function CPawn:getTarget()
	if( self.TargetPtr) then
		return CPawn(self.TargetPtr);
	else
		return nil;
	end
end

function CPawn:alive()
	self:update();
	if( not self.Alive ) then
		return false;
	else
		return true;
	end
end

function CPawn:distanceToTarget()
	if( self.TargetPtr == 0 ) then return 0; end;

	local target = CPawn(self.TargetPtr);
	local tx,ty,tz = target.X, target.Y, target.Z;
	local px,py,pz = self.X, self.Y, self.Z;

	return math.sqrt( (tx-px)*(tx-px) + (ty-py)*(ty-py) + (tz-pz)*(tz-pz) );
end
I'll enable debugging and see if it fixes.Sorry,i'm a tard and posted the settings.lua
Last edited by Suffering on Thu Aug 20, 2009 5:27 pm, edited 1 time in total.

Suffering
Posts: 34
Joined: Wed Aug 19, 2009 9:14 pm

Re: Bad argument #1 to getkeyname

#11 Post by Suffering » Thu Aug 20, 2009 5:26 pm

Nope.Debugging doesn't fix the bad argument #2 to sprintf problem.

d003232
Posts: 1252
Joined: Wed Jun 03, 2009 4:27 pm

Re: Bad argument #1 to getkeyname

#12 Post by d003232 » Thu Aug 20, 2009 5:28 pm

Suffering wrote:Now im getting another error.I'm getting pawn.lua:173 Bad argument #2 to "sprintf" <<null>>
Heres my pawn.lua:
That's settings.lua, not pawn.lua
The RoM Bot Online Wiki needs your help!

Suffering
Posts: 34
Joined: Wed Aug 19, 2009 9:14 pm

Re: Bad argument #1 to getkeyname

#13 Post by Suffering » Thu Aug 20, 2009 5:29 pm

d003232 wrote:
Suffering wrote:Now im getting another error.I'm getting pawn.lua:173 Bad argument #2 to "sprintf" <<null>>
Heres my pawn.lua:
That's settings.lua, not pawn.lua
Yeah,sorry,i'm a bit high atm.

Suffering
Posts: 34
Joined: Wed Aug 19, 2009 9:14 pm

Re: Bad argument #1 to getkeyname

#14 Post by Suffering » Thu Aug 20, 2009 5:32 pm

oh...its not <<null>> its <got nil>

d003232
Posts: 1252
Joined: Wed Jun 03, 2009 4:27 pm

Re: Bad argument #1 to getkeyname

#15 Post by d003232 » Thu Aug 20, 2009 5:43 pm

Suffering wrote:oh...its not <<null>> its <got nil>
ok. I can't say anything to that error. We have to wait for admin. I'm just wondering, that anything is running ok at other player or me too? But we will find the reason.

Are you attacking / PK targeting players?

The settings.lua 91 bug I will correct with a SVN update this evening. Just testing it. But that one you will not get, if your profile is ok.
The RoM Bot Online Wiki needs your help!

Suffering
Posts: 34
Joined: Wed Aug 19, 2009 9:14 pm

Re: Bad argument #1 to getkeyname

#16 Post by Suffering » Thu Aug 20, 2009 5:47 pm

ok. I can't say anything to that error. We have to wait for admin. I'm just wondering, that anything is running ok at other player or me too? But we will find the reason.

Are you attacking / PK targeting players?[/quote]
No..the bot doesn't even start up.

d003232
Posts: 1252
Joined: Wed Jun 03, 2009 4:27 pm

Re: Bad argument #1 to getkeyname

#17 Post by d003232 » Thu Aug 20, 2009 5:50 pm

Suffering wrote:ok. I can't say anything to that error. We have to wait for admin. I'm just wondering, that anything is running ok at other player or me too? But we will find the reason.

Are you attacking / PK targeting players?
No..the bot doesn't even start up.[/quote]Hmm. Then delete your addresses.lua and get it new from SVN.
The RoM Bot Online Wiki needs your help!

Suffering
Posts: 34
Joined: Wed Aug 19, 2009 9:14 pm

Re: Bad argument #1 to getkeyname

#18 Post by Suffering » Thu Aug 20, 2009 5:54 pm

Nope,didn't work.I deleted addresses.lua,got a new one,then ran the rom\update.lua.Still doesn't work.

Suffering
Posts: 34
Joined: Wed Aug 19, 2009 9:14 pm

Re: Bad argument #1 to getkeyname

#19 Post by Suffering » Thu Aug 20, 2009 5:58 pm

Error:Settings.lua:345 Bad argument #2 to 'sprintf' <got nil>
Here is my settings.lua:

Code: Select all

settings_default = {
	hotkeys = {
		MOVE_FORWARD = {key = _G.key.VK_W, modifier = nil},
		MOVE_BACKWARD = {key = _G.key.VK_S, modifier = nil},
		ROTATE_LEFT = {key = _G.key.VK_A, modifier = nil},
		ROTATE_RIGHT = {key = _G.key.VK_D, modifier = nil},
		STRAFF_LEFT = {key = _G.key.VK_Q, modifier = nil},
		STRAFF_RIGHT = {key = _G.key.VK_E, modifier = nil},
		JUMP = {key = _G.key.VK_SPACE, modifier = nil},
		TARGET = {key = _G.key.VK_TAB, modifier = nil},
		TARGET_FRIEND = {key = _G.key.J, modifier = nil},
		START_BOT = {key = _G.key.VK_DELETE, modifier = nil},
		STOP_BOT = {key = _G.key.VK_END, modifier = nil}
	},
	options = {
		ENABLE_FIGHT_SLOW_TURN = false,
		MELEE_DISTANCE = 45,
		LANGUAGE = "english",
		DEBUG_ASSERT = false,
	},
	profile = {
		options = {
			-- common options
			HP_LOW = 85,
			MP_LOW_POTION = 50,
			HP_LOW_POTION = 40,
			COMBAT_TYPE = "melee",
			COMBAT_RANGED_PULL = "true",	-- only for melee classes 
			COMBAT_DISTANCE = 200,
			ANTI_KS = true,
			WAYPOINTS = "myWaypoints.xml",
			RETURNPATH = nil,
			PATH_TYPE = "waypoints",
			WANDER_RADIUS = 500,
			WAYPOINT_DEVIATION = 0,
			LOOT = true,
			LOOT_TIME = 2000,
			LOOT_IN_COMBAT = true,
			LOOT_DISTANCE = nil,
			LOOT_PAUSE_AFTER = 10,	-- probability for short pause after loot to look more human
			POTION_COOLDOWN = 15,
			MAX_FIGHT_TIME = 12,
			DOT_PERCENT = 90,
			LOGOUT_TIME = 0,
			LOGOUT_SHUTDOWN = false,
			LOGOUT_WHEN_STUCK = true,
			MAX_UNSTICK_TRIALS = 10,
			TARGET_LEVELDIF_BELOW = 99,
			TARGET_LEVELDIF_ABOVE = 99,
			QUICK_TURN = false,
			MP_REST = 15,
			HP_REST = 15,
			RES_AUTOMATIC_AFTER_DEATH = false,	-- automatic resurrect after death true | false,

			
			-- expert options
			WAYPOINTS_REVERSE = false,	-- use the waypoint file in reverse order
			MAX_DEATHS = 10,		-- maximal death if automatic resurrect befor logout
			WAIT_TIME_AFTER_RES = 8000,	-- time to wait after resurrection, needs more on slow PCs
			RETURNPATH_SUFFIX = "_return",	-- suffix for default naming of returnpath
			HARVEST_SCAN_WIDTH = 10,	-- steps horizontal
			HARVEST_SCAN_HEIGHT = 8,	-- steps vertical
			HARVEST_SCAN_STEPSIZE = 35,	-- wide of every step
			HARVEST_SCAN_TOPDOWN = true,	-- true = top->down  false = botton->up
			HARVEST_SCAN_XMULTIPLIER = 1.0,	-- multiplier for scan width
			HARVEST_SCAN_YMULTIPLIER = 1.1,	-- multiplier for scan line height
			HARVEST_SCAN_YREST = 10,	-- scanspeed
			USE_SLEEP_AFTER_RESUME = false, -- enter sleep mode afer pressing pause key
			
		}, hotkeys = {}, skills = {}, friends = {},
		events = {
			onDeath = function () pauseOnDeath(); end,
			onLoad = nil,
			onLeaveCombat = nil,
			onSkillCast = nil,
		}
	},
};

settings = settings_default;


-- check if keys are double assigned or empty
check_keys = { };
function check_double_key_settings( _name, _key, _modifier )
	--if( _modifier == "" ) then _modifier = nil; end;

	for i,v in pairs(check_keys) do
		if( v.key      == _key  and
		    v.modifier == _modifier ) then
				local modname, keyname;
				if( v.modifier ) then modname = getKeyName(v.modifier); end;
				if( v.key ) then keyname = getKeyName(v.key); end;

				local errstr = sprintf("Error: You assigned the key \'%s %s\' double: for \'%s\' and for \'%s\'.\n",
					tostring(modname), tostring(keyname), v.name, _name) .. "Please check your settings!";
				error(errstr, 0);
		if( _key == nil) then
			cprintf(cli.yellow, "Error: The key for \'%s\' is empty!\n", _name);
			error("Please check your settings!", 0);
		end

		end
	end;
	
	-- check the using of modifiers
	if( _modifier ~= nil) then
		local modname, keyname;
		if( _modifier ) then modname = getKeyName(_modifier); end;
		if( _key ) then keyname = getKeyName(_key); end;

		cprintf(cli.yellow, "Due to technical reasons, we don't support "..
		   "modifiers like CTRL/ALT/SHIFT for hotkeys at the moment. "..
		   "Please change your hotkey %s-%s for \'%s\'\n", tostring(modname), tostring(keyname), _name);
		   
		   -- only a warning for TARGET_FRIEND / else an error
		   if(_name == "TARGET_FRIEND") then
		   	cprintf(cli.yellow, "You can't use the player:target_NPC() function until changed!\n");
		   else
		   	error("Please check your settings!", 0);
		   end
	end

	
	local tmp = {};
	tmp.name = _name;
	tmp.key  = _key;
	tmp.modifier  = _modifier;	
	table.insert(check_keys, tmp);	

end

function settings.load()
	local filename = getExecutionPath() .. "/settings.xml";
	local root = xml.open(filename);
	local elements = root:getElements();

	-- Specific to loading the hotkeys section of the file
	local loadHotkeys = function (node)
		local elements = node:getElements();
		for i,v in pairs(elements) do
			-- If the hotkey doesn't exist, create it.
			settings.hotkeys[ v:getAttribute("description") ] = { };
			settings.hotkeys[ v:getAttribute("description") ].key = key[v:getAttribute("key")];
			settings.hotkeys[ v:getAttribute("description") ].modifier = key[v:getAttribute("modifier")];

			if( key[v:getAttribute("key")] == nil ) then
				local err = sprintf("settings.xml error: %s does not have a valid hotkey!", v:getAttribute("description"));
				error(err, 0);
			end

			check_double_key_settings( v:getAttribute("description"), v:getAttribute("key"), v:getAttribute("modifier") );
		end
	end

	local loadOptions = function (node)
		local elements = node:getElements();
		for i,v in pairs(elements) do
			settings.options[ v:getAttribute("name") ] = v:getAttribute("value");
		end
	end

	-- load RoM keyboard bindings.txt file
	local function load_RoM_bindings_txt()
		
		local filename, file;
		
		local userprofilePath = os.getenv("USERPROFILE");
		local documentPaths = {
			userprofilePath .. "\\My Documents\\", -- English
			userprofilePath .. "\\Eigene Dateien\\", -- German
			userprofilePath .. "\\Mes Documents\\", -- French
			userprofilePath .. "\\Omat tiedostot\\", -- Finish
			userprofilePath .. "\\Belgelerim\\", -- Turkish
			userprofilePath .. "\\Mina Dokument\\", -- Swedish
			userprofilePath .. "\\Dokumenter\\", -- Danish
			userprofilePath .. "\\Documenti\\", -- Italian
			userprofilePath .. "\\Mijn documenten\\", -- Dutch
			userprofilePath .. "\\Moje dokumenty\\", -- Polish
			userprofilePath .. "\\Mis documentos\\", -- Spanish
--			"F:\\privat\\",
		};

		-- Select the first path that exists
		for i,v in pairs(documentPaths) do
			local filename = v .. "Runes of Magic\\bindings.txt"
			if( fileExists(filename) ) then
				file = io.open(filename, "r");
				cprintf(cli.green, "We read the hotkey settings from your "..
				   "bindings.txt file %s instead of using the settings.lua file.\n", filename)
			end
		end

		-- If we wern't able to locate a document path, return.
		if( file == nil ) then
			return;
		end


		-- Load bindings.txt into own table structure
		bindings = { name = { } };
		-- read the lines in table 'lines'
		for line in file:lines() do
			for name, key1, key2 in string.gfind(line, "(%w*)%s([%w+]*)%s*([%w+]*)") do
				bindings[name] = {};
				bindings[name].key1 = key1;
				bindings[name].key2 = key2;

				--settings.hotkeys[name].key = 
			end
		end

		local function bindHotkey(bindingName)
			local links = { -- Links forward binding names to hotkey names
				MOVEFORWARD = "MOVE_FORWARD",
				MOVEBACKWARD = "MOVE_BACKWARD",
				TURNLEFT = "ROTATE_LEFT",
				TURNRIGHT = "ROTATE_RIGHT",
				STRAFELEFT = "STRAFF_LEFT",
				STRAFERIGHT = "STRAFF_RIGHT",
				TARGETNEARESTENEMY = "TARGET",
				TARGETNEARESTFRIEND = "TARGET_FRIEND",	
			};

			local hotkeyName = bindingName;
			if(links[bindingName] ~= nil) then
				hotkeyName = links[bindingName];
			end;


			if( bindings[bindingName] ~= nil ) then
				if( bindings[bindingName].key1 ~= nil ) then
					-- Fix key names
					bindings[bindingName].key1 = string.gsub(bindings[bindingName].key1, "CTRL", "CONTROL");

					if( string.find(bindings[bindingName].key1, '+') ) then
						local parts = explode(bindings[bindingName].key1, '+');
						-- parts[1] = modifier
						-- parts[2] = key

						settings.hotkeys[hotkeyName].key = key["VK_" .. parts[2]];
						settings.hotkeys[hotkeyName].modifier = key["VK_" .. parts[1]];
					else
						settings.hotkeys[hotkeyName].key = key["VK_" .. bindings[bindingName].key1];
					end
					
					check_double_key_settings( hotkeyName, settings.hotkeys[hotkeyName].key, 
					  settings.hotkeys[hotkeyName].modifier );
				end
			end
		end

		bindHotkey("MOVEFORWARD");
		bindHotkey("MOVEBACKWARD");
		bindHotkey("TURNLEFT");
		bindHotkey("TURNRIGHT");
		bindHotkey("STRAFELEFT");
		bindHotkey("STRAFERIGHT");
		bindHotkey("JUMP");
		bindHotkey("TARGETNEARESTENEMY");
		bindHotkey("TARGETNEARESTFRIEND");
	end

	-- check ingame settings
	-- only if we can find the bindings.txt file
	local function check_ingame_settings( _name, _ingame_key)
		
		if( not bindings ) then		-- no bindings.txt file loaded
			return
		end;
		
		if( settings.hotkeys[_name].key ~= key["VK_"..bindings[_ingame_key].key1] and
		    settings.hotkeys[_name].key ~= key["VK_"..bindings[_ingame_key].key2] ) then
			cprintf(cli.yellow, "Your bot settings for hotkey \'%s\' in settings.xml "..
			   "don't match your RoM ingame keyboard settings.\n",
			        _name);
			error("Please check your settings!", 0);
		end
	end


	function checkHotkeys(_name, _ingame_key)
		if( not settings.hotkeys[_name] ) then
			error("ERROR: Global hotkey not set: " .. _name, 0);
		end
		
		-- check if settings.lua hotkeys match the RoM ingame settings
		-- check_ingame_settings( _name, _ingame_key);
	end


	for i,v in pairs(elements) do
		local name = v:getName();

		if( string.lower(name) == "hotkeys" ) then
			loadHotkeys(v);
		elseif( string.lower(name) == "options" ) then
			loadOptions(v);
		end
	end


	load_RoM_bindings_txt();	-- read bindings.txt from RoM user folder
	
	-- Check to make sure everything important is set
	--           bot hotkey name    RoM ingame key name         
	checkHotkeys("MOVE_FORWARD",   "MOVEFORWARD");
	checkHotkeys("MOVE_BACKWARD",  "MOVEBACKWARD");
	checkHotkeys("ROTATE_LEFT",    "TURNLEFT");
	checkHotkeys("ROTATE_RIGHT",   "TURNRIGHT");
	checkHotkeys("STRAFF_LEFT",    "STRAFELEFT");
	checkHotkeys("STRAFF_RIGHT",   "STRAFERIGHT");
	checkHotkeys("JUMP",           "JUMP");
	checkHotkeys("TARGET",         "TARGETNEARESTENEMY");
	checkHotkeys("TARGET_FRIEND",  "TARGETNEARESTFRIEND");
	
end


function settings.loadProfile(_name)
	-- Delete old profile settings (if they even exist), restore defaults
	settings.profile = settings_default.profile;

	local filename = getExecutionPath() .. "/profiles/" .. _name .. ".xml";
	local root = xml.open(filename);
	local elements = root:getElements();

	local loadOptions = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			settings.profile.options[v:getAttribute("name")] = v:getAttribute("value");
		end
	end

	local loadHotkeys = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			settings.profile.hotkeys[v:getAttribute("name")] = {};
			settings.profile.hotkeys[v:getAttribute("name")].key = key[v:getAttribute("key")];
			settings.profile.hotkeys[v:getAttribute("name")].modifier = key[v:getAttribute("modifier")];

			if( key[v:getAttribute("key")] == nil ) then
				local err = sprintf("Profile error: Please set a valid key for "..
				  "hotkey %s in your profile file \'%s.xml\'.", tostring(v:getAttribute("name")), name );
				error(err, 0);
			end
			check_double_key_settings( v:getAttribute("name"), v:getAttribute("key"), v:getAttribute("modifier") );
		end
	end

	local loadonLoadEvent = function(node)
		local luaCode = tostring(node:getValue());

		if( string.len(luaCode) > 0 and string.find(luaCode, "%w") ) then
			settings.profile.events.onLoad = loadstring(luaCode);
			if( type(settings.profile.events.onLoad) ~= "function" ) then
				settings.profile.events.onLoad = nil;
			end;
		end
	end

	local loadOnDeathEvent = function(node)
		local luaCode = tostring(node:getValue());

		if( string.len(luaCode) > 0 and string.find(luaCode, "%w") ) then
			settings.profile.events.onDeath = loadstring(luaCode);
			if( type(settings.profile.events.onDeath) ~= "function" ) then
				settings.profile.events.onDeath = nil;
			end;
		end
	end

	local loadOnLeaveCombatEvent = function(node)
		local luaCode = tostring(node:getValue());

		if( string.len(luaCode) > 0 and string.find(luaCode, "%w") ) then
			settings.profile.events.onLeaveCombat = loadstring(luaCode);
			if( type(settings.profile.events.onLeaveCombat) ~= "function" ) then
				settings.profile.events.onLeaveCombat = nil;
			end;
		end
	end

	local loadOnSkillCastEvent = function(node)
		local luaCode = tostring(node:getValue());

		if( string.len(luaCode) > 0 and string.find(luaCode, "%w") ) then
			settings.profile.events.onSkillCast = loadstring(luaCode);
			if( type(settings.profile.events.onSkillCast) ~= "function" ) then
				settings.profile.events.onSkillCast = nil;
			end;
		end
	end


	local skillSort = function(tab1, tab2)
		if( tab2.priority < tab1.priority ) then
			return true;
		end;

		return false;
	end

	local loadSkills = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			local name, hotkey, modifier, level;
			name = v:getAttribute("name");
			hotkey = key[v:getAttribute("hotkey")];
			modifier = key[v:getAttribute("modifier")];
			level = v:getAttribute("level");

			check_double_key_settings( v:getAttribute("name"), v:getAttribute("hotkey") );

			-- Over-ride attributes
			local priority, maxhpper, inbattle, pullonly, maxuse
			priority = v:getAttribute("priority");
			maxhpper = tonumber(v:getAttribute("hpper"));
			inbattle = v:getAttribute("inbattle");
			pullonly = v:getAttribute("pullonly");
			maxuse = tonumber(v:getAttribute("maxuse"));

			-- check if 'wrong' options are set
			if( v:getAttribute("mana")      or
			    v:getAttribute("manainc")   or
			    v:getAttribute("rage")      or
			    v:getAttribute("energy")    or
			    v:getAttribute("concentration")      or
			    v:getAttribute("range")     or
			    v:getAttribute("cooldown")  or
			    v:getAttribute("minrange")  or
			    v:getAttribute("type")      or
			    v:getAttribute("target")    or
			    v:getAttribute("casttime") ) then
			    	cprintf(cli.yellow, "The options \'mana\', \'manainc\', \'rage\', "..
			    	   "\'energy\', \'concentration\', \'range\', "..
			    	   "\'cooldown\', \'minrange\', \'type\', \'target\' and \'casttime\' "..
			    	   "are no valid options for your skill \'%s\' in your profile \'%s.xml\'. "..
			    	   "Please delete them and restart!\n", name, _name);
			    	   error("Bot finished due of errors above.\n", 0);
			end;
			if( v:getAttribute("modifier") ) then
			    	cprintf(cli.yellow, "The options \'modifier\' "..
			    	  "for your skill \'%s\' in your profile \'%s.xml\' "..
			    	  "is not supported at the moment. "..
			    	  "Please delete it and restart!\n", name, _name);
				error("Bot finished due of errors above.\n", 0);
			end;

			if( name == nil) then
			    	cprintf(cli.yellow, "You defined an \'empty\' skill name in "..
			    	  "your profile \'%s.xml\'. Please delete or correct "..
			    	  "that line!\n", _name);
				error("Bot finished due of errors above.\n", 0);
			end;

			if( inbattle ~= nil ) then
				if( inbattle == "true" or 
				    inbattle == true ) then
					inbattle = true;
				elseif( inbattle == "false"  or
					inbattle == false ) then
					inbattle = false;
				else
						cprintf(cli.yellow, "You defined an wrong option inbattle=\'%s\' at skill %s in "..
						  "your profile \'%s.xml\'. Please delete or correct "..
						  "that line!\n", inbattle, name, _name);
					error("Bot finished due of errors above.\n", 0);
				end;
			end

			if( pullonly ~= nil ) then
				if( pullonly == "true" or
					pullonly == true ) then
					pullonly = true;
				else
						cprintf(cli.yellow, "You defined an wrong option pullonly=\'%s\' at skill %s in "..
						  "your profile \'%s.xml\'. Only \'true\' is possible. Please delete or correct "..
						  "that line!\n", pullonly, name, _name);
					error("Bot finished due of errors above.\n", 0);
				end;
			end

			if( level == nil or level < 1 ) then
				level = 1;
			end

			local baseskill = database.skills[name];
			if( not baseskill ) then
				local err = sprintf("ERROR: \'%s\' is not defined in the database!", name);
				error(err, 0);
			end

			local tmp = CSkill(database.skills[name]);
			tmp.hotkey = hotkey;
			tmp.modifier = modifier;
			tmp.Level = level;

			if( toggleable ) then tmp.Toggleable = toggleable; end;
			if( priority ) then tmp.priority = priority; end
			if( maxhpper ) then tmp.MaxHpPer = maxhpper; end;
			if( inbattle ~= nil ) then tmp.InBattle = inbattle; end;
			if( pullonly == true ) then tmp.pullonly = pullonly; end;
			if( maxuse ) then tmp.maxuse = maxuse; end;

			table.insert(settings.profile.skills, tmp);
		end

		table.sort(settings.profile.skills, skillSort);

	end

	local loadFriends = function(node)
		local elements = node:getElements();

		for i,v in pairs(elements) do
			local name = v:getAttribute("name");
			table.insert(settings.profile.friends, name);
		end
	end

	local hf_temp = _name;	-- remember profile name shortly

	for i,v in pairs(elements) do
		local name = v:getName();

		if( string.lower(name) == "options" ) then
			loadOptions(v);
		elseif( string.lower(name) == "hotkeys" ) then
			loadHotkeys(v);
		elseif( string.lower(name) == "skills" ) then
			loadSkills(v);
		elseif( string.lower(name) == "friends" ) then
			loadFriends(v);
		elseif( string.lower(name) == "onLoad" ) then
			loadonLoadEvent(v);
		elseif( string.lower(name) == "ondeath" ) then
			loadOnDeathEvent(v);
		elseif( string.lower(name) == "onleavecombat" ) then
			loadOnLeaveCombatEvent(v);
		elseif( string.lower(name) == "onskillcast" ) then
			loadOnSkillCastEvent(v);
		elseif( string.lower(name) == "skills_warrior"  and
		        player.Class1 == CLASS_WARRIOR ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_scout"  and
		        player.Class1 == CLASS_SCOUT ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_rogue"  and
		        player.Class1 == CLASS_ROGUE ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_mage"  and
		        player.Class1 == CLASS_MAGE ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_priest"  and
		        player.Class1 == CLASS_PRIEST ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_knight"  and
		        player.Class1 == CLASS_KNIGHT ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_runedancer"  and
		        player.Class1 == CLASS_RUNEDANCER ) then
			loadSkills(v);
		elseif( string.lower(name) == "skills_druid"  and
		        player.Class1 == CLASS_DRUID ) then
			loadSkills(v);
		else		-- warning for other stuff and misspellings
			if ( string.lower(name) ~= "skills_warrior"     and
			     string.lower(name) ~= "skills_scout"       and
		 	     string.lower(name) ~= "skills_rogue"       and
	 		     string.lower(name) ~= "skills_mage"        and
			     string.lower(name) ~= "skills_priest"      and
			     string.lower(name) ~= "skills_knight"      and
			     string.lower(name) ~= "skills_runedancer"  and
			     string.lower(name) ~= "skills_druid" )     then
				cprintf(cli.yellow, tostring(language[60]), string.lower(tostring(name)),
					tostring(hf_temp));
			end;
		end
	end


	function checkProfileHotkeys(name)
		if( not settings.profile.hotkeys[name] ) then
			error("ERROR: Hotkey not set for this profile: " ..name, 0);
		end
	end

	-- Check to make sure everything important is set
	checkProfileHotkeys("ATTACK");

	-- default combat type if not in profile defined
	if( settings.profile.options.COMBAT_TYPE ~= "ranged" and 
	    settings.profile.options.COMBAT_TYPE ~= "melee" ) then
		if( player.Class1 == CLASS_WARRIOR or
		    player.Class1 == CLASS_ROGUE   or
--		    player.Class1 == CLASS_RUNEDANCER  or
		    player.Class1 == CLASS_KNIGHT  ) then
			settings.profile.options.COMBAT_TYPE  = "melee";
		elseif(
		    player.Class1 == CLASS_PRIEST  or
		    player.Class1 == CLASS_SCOUT   or
--		    player.Class1 == CLASS_DRUID   or
		    player.Class1 == CLASS_MAGE    ) then
			settings.profile.options.COMBAT_TYPE  = "ranged";
		else
			error("undefined player.Class1 in settings.lua", 0);
		end;
	end

end

d003232
Posts: 1252
Joined: Wed Jun 03, 2009 4:27 pm

Re: Bad argument #1 to getkeyname

#20 Post by d003232 » Thu Aug 20, 2009 6:07 pm

You are a good tester ... with your profile :-)

Just make a little correction at your seetings.lua line 345/346

Code: Select all

				local err = sprintf("Profile error: Please set a valid key for "..
				  "hotkey %s in your profile file \'%s.xml\'.", tostring(v:getAttribute("name")), _name );
I should be '_name' instead of 'name'. It will be in the SVN after I have the other stuff finished.
The RoM Bot Online Wiki needs your help!

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest