ScriptUO
Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: JackCiaran on April 04, 2010, 08:44:46 PM
-
This actually works but I was wondering if there was something I can change to not path find my monster as much but still stay on it? or just even make it better! I get the message "Can't get there" when the monster dies.
SUB CHECKFORENEMIES
finditem abc g_10
if #findCnt > 0
{
set #lobjectid #findid
SET %q #findid
event macro 27
wait 5
REPEAT
finditem %q
event pathfind #findx #findY
event macro 27
WAIT 5
until #findCNT = 0
GOSUB FINDCORPSE
}
GOSUB PRIMARYLOCATION
RETURN
-
If you look inside your sub here, you're doing a finditem for an enemy right? Then if you FIND the enemy, you're executing whatever is in the brackets. What JAF said is that when your enemy DIES you don't FIND him anymore... so you're not executing anything in the brackets... hence you're not FINDING THE CORPSE FOR LOOTING. hehe Cause it's in the brackets where you find the monster... and he's dead... so you can't find him anymore... :)
SUB CHECKFORENEMIES
finditem abc g_10
if #findCnt > 0
{
set #lobjectid #findid
SET %q #findid
event macro 27
wait 5
REPEAT
finditem %q
event pathfind #findx #findY
event macro 27
WAIT 5
until #findCNT = 0
GOSUB FINDCORPSE
}
GOSUB PRIMARYLOCATION
RETURN
-
thankyou Twinkle McNugget could someone help me learn how to use the brackets in this situation? I basically dont understand the proper way to use them and can't find a reference to go from that I can understand.
-
alright what i am trying to get the sub to do is
find the enemy
if I find one (if I dont find any monsters I wanna go to my sub primarylocation)
check to see if the monster is >= 2 tiles away
if it is
pathfind to it
wait ( to give it time to get there )
attack the monster
and then I want to check to see if the monster is >= 2 tiles away
and if it is
pathfind to it again ( because i believe the findx and findy will change from the original find if the monster moves and ill go to the wrong spot so i would like to check it again)
and then i want to wait for the monster to die ( the way i found to do that was with #findCNT = 0 )
after its dead i want to go to my sub find corpse.
now after typing this out would it be best to just make another sub instead of trying fit all that into one sub?
-
thankyou Twinkle McNugget could someone help me learn how to use the brackets in this situation? I basically dont understand the proper way to use them and can't find a reference to go from that I can understand.
To help answer your question, lets take a look at your code.
SUB CHECKFORENEMIES
finditem abc g_10
if #findCnt > 0
{
set #lobjectid #findid
SET %q #findid
event macro 27
wait 5
REPEAT
finditem %q
event pathfind #findx #findY
event macro 27
WAIT 5
until #findCNT = 0
GOSUB FINDCORPSE
}
GOSUB PRIMARYLOCATION
RETURN
Now, in this code below, you are telling your script to find something and then saying IF it finds abc to do EVERYTHING inside of the code tags that follow:
SUB CHECKFORENEMIES
finditem abc g_10
if #findCnt > 0
So, lets say the script finds abc on the ground within 10 tiles. The script then knows to execute the code within the code tags that follow:
{
set #lobjectid #findid
SET %q #findid
event macro 27
wait 5
REPEAT
finditem %q
event pathfind #findx #findY
event macro 27
WAIT 5
until #findCNT = 0
GOSUB FINDCORPSE
}
Once your script jumps into the code brackets you have it repeating the finditem %q (your monster) AND pathfinding to %q's coordinates until the findcnt = 0, at which point it jumps out of the repeat and goes to the sub Findcorpse. When your Sub Findcorpse completely executes, it should return you back to the line following your gosub findcorpse statement.... which just happens to be your } bracket. The script then sees that the code bracket has been closed and executes the next line of code.
Now, the difference is this... When the script does the Finditem abc g_10 and executes the IF #findcnt > 0 and it finds NOTHING the script knows NOT to jump into the brackets and execute the code inside of them. Which means, it jumps straight past the brackets down to the GOSUB PRIMARYLOCATION line and executes it.
I hope this helps to answer your question.
JaF
-
thankyou Twinkle McNugget could someone help me learn how to use the brackets in this situation? I basically dont understand the proper way to use them and can't find a reference to go from that I can understand.
Brackets are only used in certain situations. With if's if they are greater than one line AFTER the if statment is one.
The example below is correct because it only has one line AFTER the if. If that statement were #TRUE, it would execute the next line by setting %Jack to whatever. If it were #FALSE, it would read the IF statement, see it's #FALSE, and SKIP the next line without brackets and execute the very next line after the SET command.
IF %Jack = noob
SET %Jack Is_having_trouble_with_brackets
This next example has MORE than 2 lines after IF statement. So you MUST use brackets to execute it all together as part of the IF #TRUE/#FALSE, or it will not be correct. Example:
IF %Jack = noob
{
SET %Jack Is_having_trouble_with_brackets
SET %Jack1 He_is_learning_tho
}
The above is correct, and ONLY those 2 lines in the bracket will be executed if the IF is #TRUE. If it's #FALSE, it would skip those 2 lines in the brackets. It's really easy when you get the hang of it. 90 percent of your problems right now while you're learning will be syntax problems. Just keep at it and you'll get it. :) Also: You need to use brackets with whiles and repeats and fors also... there's probly more but I'm wingin it.
-
To complicate it just a bit more, you can tell the If conditional how many lines to execute if the condition is met in lieu of using brackets by using a number at the end of the conditional line:
If %Twinkle McNugget = Helpful 2
Thank him
Give him some SUO Karma love by hitting the heart under his icon
will run the same as:
If %Twinkle McNugget = Helpful
{
Thank him
Give him some SUO Karma love by hitting the heart under his icon
}
I prefer the brackets because I will inevitably screw up more otherwise, but its helpful to know its an option when you read other folks' scripts as some of them use the number convention.
-
I also prefer the brackets because I think it makes the code easier to follow. Just a personal preferance I suppose, as either way will function the same.
-
To complicate it just a bit more, you can tell the If conditional how many lines to execute if the condition is met in lieu of using brackets by using a number at the end of the conditional line:
Paul have you actually tried writing a script like this? I tried it and in some instances it didn't execute as I would have expected. I eventually ripped it all out and did it right. :) It DOES work, but I believe there are instances where it doesn't. While you're learning Jack, don't use this. It's more of an advanced thing even tho it's easy. :)
-
I don't use it, so no, I have not written any code using it, but its in a bunch of scripts. Snicker7 has it in the bodfiller that I was just digging through... I only mentioned it so that Jack would know what he was looking at if he runs into it.
-
Thanks everyone for your input it made my script change completely haha but I feel its tons better!
I am curious tho is there a way to set a pathfind location onto something like this
set %first_location_of_where_I_want_to_go 8745 81
and then use
event pathfind %first_location_of_where_I_want_to_go
to call on it? or am I using the wrong code for that
-
Thanks everyone for your input it made my script change completely haha but I feel its tons better!
I am curious tho is there a way to set a pathfind location onto something like this
set %first_location_of_where_I_want_to_go 8745 81
and then use
event pathfind %first_location_of_where_I_want_to_go
to call on it? or am I using the wrong code for that
Try this...
Set %X 8745
Set %Y 81
Event Pathfind %X %Y
-
Yes, you can even number them like this: locationx1 location y1 location x2 location y2... and so on... and then call them with a loop to have your character walk a path... :)