ScriptUO

Scripting Resources & Utilities => OEUO => OpenEUO Scripting Chat => Topic started by: J.006 on December 30, 2011, 05:23:37 AM

Title: [question]AttackSelectTarget
Post by: J.006 on December 30, 2011, 05:23:37 AM
I want to make a automate whirlwindAttack script,so I use these code
Code: [Select]
SelectPreviousMobile = function() UO.Macro(51,5,'') end
AttackSelected = function() UO.Macro(53,'','') end
But there is error what is if there is no target be selected,the IDE will report "ERR_WRONGPAR"..
so how to slove it? :(
Title: Re: [question]AttackSelectTarget
Post by: manwinc on January 01, 2012, 06:46:36 AM
I'm not sure in OpenEUO, but I know in Easyuo the Easiest method for attacking something is to

set #ltargetid (id)
Event macro 27 0 ; <- Last Target
Title: Re: [question]AttackSelectTarget
Post by: Crome969 on January 01, 2012, 10:21:43 AM
I want to make a automate whirlwindAttack script,so I use these code
Code: [Select]
SelectPreviousMobile = function() UO.Macro(51,5,'') end
AttackSelected = function() UO.Macro(53,'','') end
But there is error what is if there is no target be selected,the IDE will report "ERR_WRONGPAR"..
so how to slove it? :(
didnt tested but why you making(51,5,"") you can use (51,5) instead.

i can show you how i registered functions in past with following example:

Code: [Select]
Use={}
--##########################################
Use.LastObjectID=(
function (tID)
while(UO.TargCurs==false)do
UO.LObjectID=tID
UO.LTargetKind=1
UO.Macro(17,0)
wait(500)
end
end
)
--##########################################
Use.LastTargetID=(
function (tID,tKind)
while(UO.TargCurs==true)do
UO.LTargetID=tID
UO.LTargetKind=tKind
UO.Macro(22,0)
wait(500)
end
end

So it should work properly regular..

Edit:
When i rethink your "Solution" its about the "" in the UO.Macro.
In C# i would define different Constructors for different cases.
PseudoCode example:
Code: [Select]
function x (par1)
{
}
function x (par1,par2)
{
}
function x(par1,par2,par3)
{
}
The transmitting of data from openuo into the Easyuocore using stacks( stringstacks) to convert the functions in openuo\easyuo into delphi.
When you now give that stack 3 parameters for something what only have 2 allowed it wouldnt work and return that exception.
When you give a function 3 Parameters, and 3 are allowed, but they must be later converted into integers, it may fail because its "" also nothing.
I would prefer to only use the Parameters you need and not send more parameters:)
So UO.Macro(21,"","") wouldnt work, but UO.Macro(21)
 


Crome
Title: Re: [question]AttackSelectTarget
Post by: J.006 on January 03, 2012, 05:32:57 AM
Thx for reply. :)
But if I use UO.Macro(53),the exception is also the "ERR_WRONGPAR".
So I think it maybe the OPENUO's BUG,beacause if I use the macro in UO,AttackSelectTarget,it will show me the information "There is no current target."
Title: Re: [question]AttackSelectTarget
Post by: manwinc on January 03, 2012, 06:23:45 AM
Perhaps do a check for a change in target?

Check Target
Select Next mobile
if New Target is Different From last target
Attack Selected Target
Title: Re: [question]AttackSelectTarget
Post by: Crome969 on January 03, 2012, 07:37:45 AM
Thx for reply. :)
But if I use UO.Macro(53),the exception is also the "ERR_WRONGPAR".
So I think it maybe the OPENUO's BUG,beacause if I use the macro in UO,AttackSelectTarget,it will show me the information "There is no current target."
Did you tried it with other UO.Macros?
An d when UO.Macro 53 has different handler in his method you will need a 0 or such to predefine handler. I never used Event macro 53 before, think i handled it with other macros ..
Title: Re: [question]AttackSelectTarget
Post by: J.006 on January 09, 2012, 05:00:05 AM
Finally,I use this two function to slove the problem :)
Code: [Select]
SelectPreviousMobile = function() UO.Macro(51,5,'') end
AttackLast = function() UO.Macro(27,0,'') end
Thx everyone in this post.
Title: Re: [question]AttackSelectTarget
Post by: J.006 on January 22, 2012, 04:50:03 AM
Got a new problem,is there a function to determine the selectedTarget is friendly or monster?
Title: Re: [question]AttackSelectTarget
Post by: Endless Night on January 22, 2012, 06:11:11 AM
Got a new problem,is there a function to determine the selectedTarget is friendly or monster?

Using its id .. find it and then look at the rep value.
Title: Re: [question]AttackSelectTarget
Post by: J.006 on January 23, 2012, 02:59:04 AM
Got a new problem,is there a function to determine the selectedTarget is friendly or monster?

Using its id .. find it and then look at the rep value.

What is rep value? :)
Title: Re: [question]AttackSelectTarget
Post by: manwinc on January 23, 2012, 11:54:58 PM
First, I'm sorry if my use of LUA is not Correct. I haven't used it much.

In this Situation, you might be better off doing the Macro for Select Next Hostile. Really No reason to Use the New Targeting System for attacking things by selecting Next Mobile.

Would be Much easier to just build an array for the "types" you wish to attack then use something similar to these subs to locate the nearest monster and attack it.

Code: [Select]
function finddist(x,y)  
  dx = math.abs(UO.CharPosX - x)  
  dy = math.abs(UO.CharPosY - y)  
  return math.max(dx, dy)  
end

function attack(types)
  local closest = nil
  local fdist = 13
  for i = 1,UO.ScanItems(true) do
     local id,type,kind,contid,x,y,z,stack,rep,col = UO.GetItem(i)
     dist = finddist(x,y)
     for c = 1,#types do
         if type == types[c] and dist<fdist do
               fdist = dist
               closest = id
         end
      end
  end
  if closest ~= nil do
    UO.LTargetID = id
    UO.LTargetKind = 1
    UO.Macro(27,0)
  end
end
Title: Re: [question]AttackSelectTarget
Post by: J.006 on January 24, 2012, 12:52:22 AM
I had tested the "SelectNearestHostile" before,it had some bugs,because not every monster in the screen is "hostile",but they still can attack you,maybe I 'm in a FreeShards. :)
Anyway,thx for your code,I 'll check them later. :)