Page 2 of 7 FirstFirst 1234 ... LastLast
Results 11 to 20 of 70

Thread: Learn how to script with this simple hunting script

  1. #11

    Default

    Quote Originally Posted by Tgo01 View Post
    The indents just make the code a lot easier to read. Like if you're writing an if/else statement then you start the statement with if and end it with end, so you would write it like:

    Code:
    if a != b
    	if a == b
    		echo "Wait, what am I saying?"
    	else
    		echo "no idea"
    	end
    else
    	if b == c
    		echo "Huh?
    	elsif 1 == 2
    		echo "1 can't equal 2!"
    	else
    		echo "Could you repeat that?"
    	end
    end
    This way you can easily see which else/elsif/end belong to which if statements, you can also easily tell which code falls under which if/else statement.

    Likewise the following code would work just as well but if you ever want to edit the code in the future it might be a bit confusing:

    Code:
    if a != b
    if a == b
    echo "Wait, what am I saying?"
    else
    echo "no idea"
    end
    else
    if b == c
    echo "Huh?
    elsif 1 == 2
    echo "1 can't equal 2!"
    else
    echo "Could you repeat that?"
    end
    end


    I'm not sure what you're asking.



    Questions are welcomed and encouraged! How else is one supposed to learn?
    I think he's asking about functions. to which the answer is, yes. They're defined in lich.rbw itself. Look for any lines that begin with "def name_of_some_function_here" or similar. That's where you would find things like where the code for "checkstamina" or "percentmind" (functions you can call in scripts) are.

    http://www.howtogeek.com/howto/progr...method-syntax/
    Last edited by Donquix; 05-25-2015 at 11:12 PM.
    Mithrilschlong, 2015-03-10 to slightly later on 2015-03-10. You will not be forgotten!

  2. #12

    Default

    Another thing you can do:

    Code:
    def this_script_cloud_go_away
    	GameObj.loot.each{ |i|
    		if i.noun =~ /cloud/
    			if (Spell[612].affordable?) && (Spell[612].known?)
    				Spell[612].cast
    				break
    			elsif (Spell[417].affordable?) && (Spell[417].known?)
    				Spell[417].cast(i)
    			elsif (Spell[1218].affordable?) && (Spell[1218].known?)
    				Spell[1218].cast(i)
    			elsif (Spell[119].affordable?) && (Spell[119].known?)
    				Spell[119].cast(i)
    			end
    		end
    	}
    end
    Put this in your loop and if there are no clouds in the room with you then great! Nothing will happen.

    Otherwise if you know Breeze (612) and have enough mana for it it will cast breeze to get rid of the clouds, otherwise it goes through all of the dispels (cheaper ones first) and if you know that dispel and have enough mana to cast it it will cast that dispel on each cloud it finds.
    Last edited by Tgo01; 05-26-2015 at 01:28 AM.

  3. #13

    Default

    Quote Originally Posted by Donquix View Post
    I think he's asking about functions.
    Ah I see. Yeah, what Donquix said

    You don't have to know all of that stuff to code your own script, but it sure as hell makes things easier. There is a lot of stuff in there I didn't even know existed, like just yesterday I found out about the empty_right_hand and emptyhands definitions.

  4. #14

    Default

    More fun things to do with your script:

    Code:
    def this_script_stay_down
    	GameObj.npcs.any? { |npc| 
    		if (npc.status !~ /prone|sit|lay|kneel|stun|sleep/ && npc.type =~ /aggressive/) && (GameObj.pcs.length == nil)
    			Spell[410].cast if (Spell[410].known?) && (Spell[410].affordable?)
    		end
    	}
    end
    
    def this_script_help_people_up
    	this_script_stand_me
    	GameObj.pcs.each { |pc|
    		if pc.status =~ /prone|sit|lay|kneel/ && pc.status !~ /dead/
    			waitrt?
    			fput "pull #{pc}"
    		end
    	}
    end
    Run this_script_stay_down first and it will cast elemental wave only if you have enough mana for it and you know the spell 410 and if there is an aggressive NPC in the room that is not already prone, kneeling, sitting or stunned and there are no people in the room.

    Run this_script_help_people_up right after that and it will pull up anyone in the room who is not already standing, y'know, just in case they entered the room during that millisecond before you actually cast the spell, you know how that seems to happen all the time.

    this_script_help_people_up also makes use of the definition this_script_stand_me mentioned in the original post to make sure you yourself are standing first before attempting to help anyone else up.
    Last edited by Tgo01; 05-26-2015 at 08:14 PM.

  5. #15

    Default

    Quote Originally Posted by Donquix View Post
    I think he's asking about functions. to which the answer is, yes. They're defined in lich.rbw itself. Look for any lines that begin with "def name_of_some_function_here" or similar. That's where you would find things like where the code for "checkstamina" or "percentmind" (functions you can call in scripts) are.

    http://www.howtogeek.com/howto/progr...method-syntax/
    Yep, you got it here. Thank you. I was wondering if there was a set of built-in words to make the codes associate and whatnot. This looks like fun (and a bit confusing) but I'm definitely interested.

    Thanks again for putting this up and keep rolling with it. I'm watching!

  6. #16

    Default

    Quote Originally Posted by Tgo01 View Post
    this_script_help_people_up
    So....could something like this, tuned up a bit, help like ;helpfolks? (Which seems to be broken for me at the moment as well.)

  7. #17

    Default

    Quote Originally Posted by Soulance View Post
    So....could something like this, tuned up a bit, help like ;helpfolks? (Which seems to be broken for me at the moment as well.)
    Does it not work at all?

    Only thing I could see possibly being an issue is it only does a check every 3 seconds so if you're passing by someone who needs help during this 3 second pause it won't work. You could try tuning the pause down to like 0.5 or even 0.1 seconds.

    You want some sort of pause in a loop otherwise your game might crash. I've found that 0.1 seconds usually prevents this problem, if it's taxing your computer too much (which it shouldn't) you could try upping it to 0.2 or 0.5.

  8. #18

    Default

    Code:
    $run_away_if_more_than_this_number_of_critters = 1
    
    def this_script_check_number_of_critters
    	npc_count = 0
    	GameObj.npcs.each{ |npc| npc_count += 1 if (npc.status !~ /dead/) && (npc.type =~ /aggressive/) }
    	if npc_count > $run_away_if_more_than_this_number_of_critters
    		echo "Too many critters here!"
    		exit
    	end
    end
    Set the $run_away_if_more_than_this_number_of_critters variable and run this_script_check_number_of_critters during your loop and the script will add up the number of NPCs in the room that aren't dead and are aggressive (so it will ignore pets) and if the number of NPCs in the room is greater than the number you set in the $run_away_if_more_than_this_number_of_critters variable then the script will run the code listed. Right now it's just set to telling you there are too many critters in the room and exiting the script. Ideally you would have this break the kill part of the loop which will itself be in a loop that would move you to another room and keep moving you until it finds a room that doesn't have so many critters in it.

  9. #19

    Default

    Quote Originally Posted by Tgo01 View Post
    Does it not work at all?

    Only thing I could see possibly being an issue is it only does a check every 3 seconds so if you're passing by someone who needs help during this 3 second pause it won't work. You could try tuning the pause down to like 0.5 or even 0.1 seconds.

    You want some sort of pause in a loop otherwise your game might crash. I've found that 0.1 seconds usually prevents this problem, if it's taxing your computer too much (which it shouldn't) you could try upping it to 0.2 or 0.5.
    Eh, it 'kinda' works here and there but I think you're right about it just being a timing thing. By the time it's doing what it is supposed to do the person is already out of the stun. Seems like it would start to prepare the spell, then miscast, then prepare it again, miscast. I'll have to go back and test a little more again because I stopped using it. It was nice for bandits though.

  10. #20

    Default

    Quote Originally Posted by Tgo01 View Post
    Code:
    target_names = /kobold|squirrel|rolton/
    
    $my_target = GameObj.npcs.find{ |npc| npc.name =~ target_names && npc.type =~ /aggressive/ }
    I'm guessing the way this script is written, that the first npc that it finds that is on the list at all will become the target. Is a smart targeting setup outside the scope of this tutorial? I'm thinking that a better way would be to make a loop that will check all npcs for the first item on the list before checking for the second.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •