Author Topic: Tutorial 6 - I'm so ticked off at Cerveza!  (Read 11457 times)

0 Members and 1 Guest are viewing this topic.

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Tutorial 6 - I'm so ticked off at Cerveza!
« on: February 25, 2009, 06:39:07 AM »
0
"I'm using his Potion Drinker and Self Bandage script and it keeps messing me up when I'm casting spells".

Yeah, I was kinda expecting to hear from you squeeky.

Since you have already read 1-5... you HAVE read 1-5 before reading this right? Damnit squeeky! GO READ 1-5!!

Ok, now that everyone has read 1-5  >:( we'll change up the script a little bit so squeeky can cast his darn spells.

Here's the finished Potion/Bandage script.
Code: [Select]
;=================================================================
; Script Name: Cerveza's Cure And Heal Pot Drinker w/Hotkey Bandages
; Author: Cerveza
; Version: 1.0
; Shard OSI / FS: OSI / FS OK
; Revision Date: 2/24/2009
; Purpose: Drink Cure/Heal Potions when needed, Applies bandages on hotkey
; Globals: None
;=================================================================

;************************ Setup **********************************
set %healpotHP ( #maxHits - 40 ) ; change this for how many points down to drink heal
set %timer_pot_heal #sCnt
set %bandage_hotkey F10 ; you can change this to whatever you want your bandage hotkey

;*********************** MainLoop ********************************
SUO:
repeat
  
  if C in #charStatus
    gosub DoIt NUF NONE ; %1=NUF %2=NONE
  
  if #hits < %healpotHP && #sCnt > %timer_pot_heal
  {
    gosub DoIt UUF NONE ; %1=UUF %2=NONE
    set %timer_pot_heal ( #sCnt + 10 )
  }
  wait 5

  onhotkey %bandage_hotkey
    gosub DoIt ZJF SELF ; %1=ZJF %2=SELF
  
until #CharGhost = YES
while #CharGhost = YES
  wait 0
GoTo SUO

;************************ Subs ***********************************
; %1 - Item TYPE to use. NUF=Cure Pot, UUF=Heal Pot, ZJF=Bandage
; %2 - Target. SELF to target self, all other will skip targetting
sub DoIt
  namespace push
  namespace local DIT ; short for DrinkIT
  wait 5
  findItem %1 C_ , #backpackID
  if #findKind = -1
    return
  set #lobjectID #findID
  set #ltargetKind 1
  event macro 17 0
  if %2 = SELF
  {
    target 3s
    event macro 23 0
  }
  namespace clear
  namespace pop
return

The problem that squeeky is running into is that scripts run all the time. Unless you use them for 100% of your actions in UO, then eventually you will have some interaction problems. That means that when they are trying to target you for a bandage, you are trying to target that dragon with a flamestrike. Sometimes you get burnt. (hehe)

So what can we do? Well, we can't make everything work every time for everyone. But we can do our best.

Here's squeeky's biggest problem. He goes to cast a spell, and he needs a bandage at the same time. The target cursor for the spell comes up, THEN the script targets him with the bandage, but the spell goes off and squeeky gets roasted while shouting "DEATH TO CERVEZA". So what can we do for squeeky?

I guess we really want is some kind of target cursor check. That way if the spell target is up, we won't try to use a bandage, or drink a pot or basically anything else. "Cerveza, is there some way we can check to see if the target cursor is up"? Why yes, younglings, there is.

#targCurs is what we'll use. 0 = Normal cursor, 1 = Target cursor

Yes squeeky, I got your PM. Sorry everyone, squeeky was complaining that the script also screws up when he's dragging items. So lets see if there's something we can check to see if an item is being held on the cursor.

#lliftedKind 0 = no objects on the cursor, 1 = an object is on the cursor.

So... what we need to do is set up a trigger to check for either of those things happening. If either is happening, then we don't want to use our script at all... but as soon as both things are NOT happening, we want our script to work.

hehe, we're scripters... we can make this happen.

if #targCurs = 1 || #lliftedKind = 1

Dude, thats some scripting right there. What that line says is "If the target cursor is 1 (active) OR there is an item on the cursor".

Now what do we do with this? There's two different paths to go here. Do we want to put the condition in the main loop of the script? Or do we want it in the sub routine? I suppose it's completely up to you... I suppose my recommendation would be to put it in the sub routine. The reason being... later you might add in a bunch of stuff to this script that doesn't care if the cursor is active or your dragging something. Like, if you have a menu setup that shows your hit points and turns RED if your hits go below 40. You want that part of your script to run NO MATTER WHAT is going on with the target cursor. Thats why I'd recommend putting it in the sub routine itself.

Or - you could put it in the trigger that calls the sub routine  :o

This is my sneeky way of showing you the different uses.... how about changing our "drink cure" trigger...

if C in #charStatus && #targCurs = 0 && #lliftedKind = 0

Wow, thats some shizit there. What that lines says is "if your char is poisoned AND the cursor is normal (0) AND nothing is on the cursor.

See how we changed it from before? Using the OR ( || ) statement we can say "if either of these things are true". Using the AND ( && ) statement we're saying, "If ALL of these conditions are met, then you may continue".

In scripting, I've found that putting the complete triggers before calling a sub is the best practice. Think about the script flow for a second. If we put the cursor checks in the sub itself, the script must always visit the sub routine, THEN determine the cursor status. If we put the line in the trigger that calls the sub, we can avoid the sub completely if the conditions aren't exactly met.

So simple changes.....
Code: [Select]
;=================================================================
; Script Name: Cerveza's Cure And Heal Pot Drinker w/Hotkey Bandages
; Author: Cerveza
; Version: 1.2
; Shard OSI / FS: OSI / FS OK
; Revision Date: 2/24/2009
; Purpose: Drink Cure/Heal Potions when needed, Applies bandages on hotkey
; Globals: None
;=================================================================
; v1.0 First Release
; v1.1 Merged potions and bandages
; v1.2 Added cursor checks
;=================================================================
; Thanks: Definitely NOT squeeky
;=================================================================

;************************ Setup **********************************
set %healpotHP ( #maxHits - 40 ) ; change this for how many points down to drink heal
set %timer_pot_heal #sCnt
set %bandage_hotkey F10 ; you can change this to whatever you want your bandage hotkey

;*********************** MainLoop ********************************
SUO:
repeat
  
  if C in #charStatus && #targCurs = 0 && #lliftedKind = 0
    gosub DoIt NUF NONE ; %1=NUF %2=NONE
  
  if #hits < %healpotHP && #sCnt > %timer_pot_heal  && #targCurs = 0 && #lliftedKind = 0
  {
    gosub DoIt UUF NONE ; %1=UUF %2=NONE
    set %timer_pot_heal ( #sCnt + 10 )
  }
  wait 5

  onhotkey %bandage_hotkey
  {
    if #targCurs = 0 && #lliftedKind = 0
      gosub DoIt ZJF SELF ; %1=ZJF %2=SELF
  }

until #CharGhost = YES
while #CharGhost = YES
  wait 0
GoTo SUO

;************************ Subs ***********************************
; %1 - Item TYPE to use. NUF=Cure Pot, UUF=Heal Pot, ZJF=Bandage
; %2 - Target. SELF to target self, all other will skip targetting
sub DoIt
  namespace push
  namespace local DIT ; short for DrinkIT
  wait 5
  findItem %1 C_ , #backpackID
  if #findKind = -1
    return
  set #lobjectID #findID
  set #ltargetKind 1
  event macro 17 0
  if %2 = SELF
  {
    target 3s
    event macro 23 0
  }
  namespace clear
  namespace pop
return

I had to put in the one liner for bandages as well, since it's called on a hotkey and not automatic. Should work. Haven't checked. Haven't loaded UO in a while actually.

So there you have it. An update for squeeky.
« Last Edit: August 03, 2010, 12:49:05 PM by Cerveza »
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Tutorial 6 - I'm so ticked off at Cerveza!
« Reply #1 on: September 20, 2011, 06:31:41 AM »
0
stickied
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Tags: