, but which keg will be detonated when I do it, when there are more than one kegs?
, which doesn't have much puzzle potential. I'd suggest doing it by choosing kegs closest to the player (which is more useful), and then tiebreak by something like orientation.
×Both of them stores the X and Y coordinate in NearestMonsterX and NearestMonsterY. If you need multiple of them, change the variable to .NearestMonsterX and .NearestMonsterY, so every NPC has their own result.
FindNearestMonsterDiagonal calculate distance by treating all 8 adjacent tiles as distance 1, and tiebreaks from NW corner in CW direction, while FindNearestOrbOrthogonal only treats the 4 orthogonally adjacent tile as distance 1, and tiebreaks from N corner in CW direction.
Distance is the start distance, and TillDistance is the end distance, which is necessary because DROD would think the script's in an infinite loop and interrupt it if it's too high.
There are Wait for item and Wait for entity Monster in the script, this is the thing the script's searching for. Change them to whatever necessary for your need (in you case, Wait for item Keg).
FindNearestMonsterDiagonal
Click here to view the secret text
×
Appear
Label loop
Set var ".found" = 0
Set var "TillDistance" = 5
Set var "Distance" = 1
Set var ".index" = 0
GoSub FindNearestMonsterDiagonal
If ...
Wait until var ".found" = 0
Move to Player 0,1
Else
Set var "_MyScriptX" = NearestMonsterX
Set var "_MyScriptY" = NearestMonsterY
If ...
Wait until var "Distance" <= 1
Attack tile 0,0,Stab
If End
Move to 0,0,0,1
Set var "_MyScriptX" = -9999
Set var "_MyScriptY" = -9999
If End
Go to loop
Label FindNearestMonsterDiagonal
Set var "_MyScriptX" = -9999
Set var "_MyScriptY" = -9999
If ...
Wait until var "Distance" > TillDistance
Set var ".found" = 0
Return
Else If
Wait until var ".index" < Distance*8
Set var ".quadrant" = .index/(Distance*2)
Set var ".angle" = .index%(Distance*2)
If ...
Wait until var ".quadrant" = 0
Set var "_MyScriptX" = _MyX-Distance+.angle
Set var "_MyScriptY" = _MyY-Distance
Else If
Wait until var ".quadrant" = 1
Set var "_MyScriptX" = _MyX+Distance
Set var "_MyScriptY" = _MyY-Distance+.angle
Else If
Wait until var ".quadrant" = 2
Set var "_MyScriptX" = _MyX+Distance-.angle
Set var "_MyScriptY" = _MyY+Distance
Else If
Wait until var ".quadrant" = 3
Set var "_MyScriptX" = _MyX-Distance
Set var "_MyScriptY" = _MyY+Distance-.angle
If End
If ...
Wait until var "_MyScriptX" < 0
Set var ".index" + 1
Go to FindNearestMonsterDiagonal
Else If
Wait until var "_MyScriptX" > 37
Set var ".index" + 1
Go to FindNearestMonsterDiagonal
Else If
Wait until var "_MyScriptY" < 0
Set var ".index" + 1
Go to FindNearestMonsterDiagonal
Else If
Wait until var "_MyScriptY" > 31
Set var ".index" + 1
Go to FindNearestMonsterDiagonal
If End
If ...
Wait for entity Monster 0,0,0,0
Set var "NearestMonsterX" = _MyScriptX
Set var "NearestMonsterY" = _MyScriptY
Set var "_MyScriptX" = -9999
Set var "_MyScriptY" = -9999
Set var ".found" = 1
Return
Else
Set var "_MyScriptX" = -9999
Set var "_MyScriptY" = -9999
Set var ".index" + 1
Go to FindNearestMonsterDiagonal
If End
Else
Set var "Distance" + 1
Set var ".index" = 0
Go to FindNearestMonsterDiagonal
If End
FindNearestOrbOrthogonal
Click here to view the secret text
× Set var ".found" = 0
Label start
Set var "_MyX" = _X
Set var "_MyY" = _Y
Set var "_MyO" = _O
If ...
Wait for player to input Special Command
Set var "TillDistance" = 25
Set var "Distance" = 1
Set var ".index" = 0
GoSub FindNearestOrbOrthogonal
If ...
Wait until var ".found" = 1
Set var "_MyScriptX" = NearestMonsterX
Set var "_MyScriptY" = NearestMonsterY
Attack tile 0,0,Stab
Game effect Center,Bolt,0,0,On
If End
Set var "_MyScriptX" = -9999
Set var "_MyScriptY" = -9999
If End
Wait 0
Go to start
Label FindNearestOrbOrthogonal
If ...
Wait until var "Distance" > TillDistance
Set var ".found" = 0
Return
Else If
Wait until var ".index" < Distance*4
Set var ".quadrant" = .index/Distance
Set var ".angle" = .index%Distance
If ...
Wait until var ".quadrant" = 0
Set var "_MyScriptX" = _X+.angle
Set var "_MyScriptY" = _Y-Distance+.angle
Else If
Wait until var ".quadrant" = 1
Set var "_MyScriptX" = _X+Distance-.angle
Set var "_MyScriptY" = _Y+.angle
Else If
Wait until var ".quadrant" = 2
Set var "_MyScriptX" = _X-.angle
Set var "_MyScriptY" = _Y+Distance-.angle
Else If
Wait until var ".quadrant" = 3
Set var "_MyScriptX" = _X-Distance+.angle
Set var "_MyScriptY" = _Y-.angle
If End
If ...
Wait until var "_MyScriptX" < 0
Set var ".index" + 1
Go to FindNearestOrbOrthogonal
Else If
Wait until var "_MyScriptX" > 37
Set var ".index" + 1
Go to FindNearestOrbOrthogonal
Else If
Wait until var "_MyScriptY" < 0
Set var ".index" + 1
Go to FindNearestOrbOrthogonal
Else If
Wait until var "_MyScriptY" > 31
Set var ".index" + 1
Go to FindNearestOrbOrthogonal
If End
If ...
Wait for item Orb (any),0,0,0,0
Set var "NearestMonsterX" = _MyScriptX
Set var "NearestMonsterY" = _MyScriptY
Set var "_MyScriptX" = -9999
Set var "_MyScriptY" = -9999
Set var ".found" = 1
Return
Else
Set var "_MyScriptX" = -9999
Set var "_MyScriptY" = -9999
Set var ".index" + 1
Go to FindNearestOrbOrthogonal
If End
Else
Set var "Distance" + 1
Set var ".index" = 0
Go to FindNearestOrbOrthogonal
If End