Page 1 of 1

Ammunition Setting Spam

Posted: Tue Jun 16, 2015 8:58 pm
by Bill D Cat
From bot.lua at around line 755

Code: Select all

		-- reloading ammunition
		if ( settings.profile.options.RELOAD_AMMUNITION ) then
			local ammo = string.lower(settings.profile.options.RELOAD_AMMUNITION);
			if  ammo == "thrown" and (player.Class1 == CLASS_ROGUE or (player.Class2 == CLASS_ROGUE and player.Level > 11 and player.Level2 > 11)) then
				if inventory:getAmmunitionCount() == 0 then
					inventory:reloadAmmunition(ammo);
				end
			elseif ammo == "arrow" and (player.Class2 == CLASS_SCOUT or player.Class1 == CLASS_SCOUT) then
				if inventory:getAmmunitionCount() == 0 then
					inventory:reloadAmmunition(ammo);
				end
			else
			    print("RELOAD_AMMUNITION can only be false, arrow or thrown!");
			end
		end
Situation goes like this. Create a new Rogue and set RELOAD_AMMUNITION to "thrown" or a new Scout and set it to "arrow" and start playing. So far so good. Get to level 10, pick a second class that isn't Rogue or Scout and the spam begins. "RELOAD_AMMUNITION can only be false, arrow or thrown!" in the MM window every waypoint. Would this be better coded as follows to avoid the spam?

Code: Select all

		-- reloading ammunition
		if ( settings.profile.options.RELOAD_AMMUNITION ) then
			local ammo = string.lower(settings.profile.options.RELOAD_AMMUNITION);
			if ammo ~= "thrown" and ammo ~= "arrow" and ammo ~= "false" then
			    print("RELOAD_AMMUNITION can only be false, arrow or thrown!");
			end
			if  ammo == "thrown" and (player.Class1 == CLASS_ROGUE or (player.Class2 == CLASS_ROGUE and player.Level > 11 and player.Level2 > 11)) then
				if inventory:getAmmunitionCount() == 0 then
					inventory:reloadAmmunition(ammo);
				end
			elseif ammo == "arrow" and (player.Class2 == CLASS_SCOUT or player.Class1 == CLASS_SCOUT) then
				if inventory:getAmmunitionCount() == 0 then
					inventory:reloadAmmunition(ammo);
				end
			end
		end
Yeah, I know I can just edit the profile when I change classes to avoid it, but sometimes I just use the default profile and set whichever applies to my classes. My actual playing characters each have their own profiles so that's no problem. It's just when I'm making a new character to work on zone waypoint files.

Re: Ammunition Setting Spam

Posted: Wed Jun 17, 2015 4:27 am
by rock5
The way you have it it will still try to load the ammo though. Maybe you should use an elseif. Also you don't have to check for false because ammo can't equal false in the block of code because of the first 'if' statement.

Code: Select all

      -- reloading ammunition
      if ( settings.profile.options.RELOAD_AMMUNITION ) then
         local ammo = string.lower(settings.profile.options.RELOAD_AMMUNITION);
         if ammo ~= "thrown" and ammo ~= "arrow" then
             print("RELOAD_AMMUNITION can only be false, arrow or thrown!");
         elseif  ammo == "thrown" and (player.Class1 == CLASS_ROGUE or (player.Class2 == CLASS_ROGUE and player.Level > 11 and player.Level2 > 11)) then
            if inventory:getAmmunitionCount() == 0 then
               inventory:reloadAmmunition(ammo);
            end
         elseif ammo == "arrow" and (player.Class2 == CLASS_SCOUT or player.Class1 == CLASS_SCOUT) then
            if inventory:getAmmunitionCount() == 0 then
               inventory:reloadAmmunition(ammo);
            end
         end
      end

Re: Ammunition Setting Spam

Posted: Wed Jun 17, 2015 6:18 am
by Bill D Cat
Actually, you could do away with the check altogether if you wanted. I mean, you could set RELOAD_AMMUNITION = "Banana" and it won't try to load ammo because it fails the checks later on. Mostly this is only going to be an issue where you have a Rogue secondary and have not raised your primary class to 12 yet. Actually, if you only got to level 10 Rogue and took a second class it'll keep spamming until you've raised the Rogue to level 12 as well. I guess it doesn't effect Scout like I originally posted, since it doesn't have a level check. The class check in the statements below would be sufficient to control what ammunition was reloaded. Setting RELOAD_AMMUNITION to "thrown" or "arrow" when you don't have Rogue or Scout as one of your active classes would have spammed the warning message, but my change to the code block fixed that.

Code: Select all

elseif  ammo == "thrown" and (player.Class1 == CLASS_ROGUE or (player.Class2 == CLASS_ROGUE and player.Level > 11 and player.Level2 > 11)) then

elseif ammo == "arrow" and (player.Class2 == CLASS_SCOUT or player.Class1 == CLASS_SCOUT) then
I just don't see there is a need to have the check for "thrown", "arrow" or "false" linked into a conditional with the class/ammo check later. If the warning message is triggered, both the following checks will fail anyway based on the first conditional statement, and no ammo will be loaded. I don't think there will be any speed difference between my code and your suggestion either.

And if you take out the check for "false" then you could pretty much just do away with the whole check anyway. Setting RELOAD_AMMUNITION = "None" would work just as well since any string other than "thrown" or "arrow" would effectively be ignored.

Re: Ammunition Setting Spam

Posted: Wed Jun 17, 2015 7:00 am
by rock5
You're right that your code should work and and the elseif isn't strictly needed but the elseif stops the unnecessary further comparisons. It's just neater programming.

We do need the message. The purpose of the message is to inform the user that they used an invalid value. You are right that the problem is if the value is correct but you are the wrong level then you get the message anyway and your fix fixes this.

You don't need to check for false because if it's false then it wont pass the first if statement.

Code: Select all

if ( settings.profile.options.RELOAD_AMMUNITION ) then
If you are inside this 'if' statement then you already know that that value isn't false (or nil) so you don't have to check if it's false because you already know it isn't.