ScriptUO

Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: Grandewd on July 02, 2014, 03:21:43 PM

Title: Getting the value of Physical Resist from a piece of armor
Post by: Grandewd on July 02, 2014, 03:21:43 PM
We have #fr #cr #pr #er to get the values of Fire/Poison/Energy/Cold.
What happened to Physical?  How do I get the value for Physical Resist on a piece of armor?

Thx
Title: Re: Getting the value of Physical Resist from a piece of armor
Post by: Pearls on July 03, 2014, 12:36:54 AM
#AR, just check the EasyUO window on the right to see what else is there :)
Title: Re: Getting the value of Physical Resist from a piece of armor
Post by: manwinc on July 03, 2014, 01:43:56 AM
Here is my sub for pulling the value of Properties off items.


Code: [Select]
Sub Property
NameSpace Push
Namespace Local Mwinc_Property
set !Item %1
set !Property %2
For !Attempt 1 10
{
Event Property !Item
if Stone in #property
Break
wait 5
}
Str Count #property !Property
if #Strres > 0
{
set !Cnt #Strres
for !Holder 1 !Cnt
{
set !Value2 0
Str Len !Property
set !Length #Strres
Str Pos #property !Property !Holder
set !Start #Strres + !Length
for !Number 1 4
{
Str Mid #Property !Start !Number
if #Strres > 0
set !Value2 #Strres
}
set !Value !Value + !Value2
}
}
Else
set !Value 0
set #Result !Value
Namespace Clear
Namespace pop
Return #Result

And this  below is how you utilize it

Gosub Property (id of item) (String Before Value You Want)

You have to Remember that in order to get EasyUO to Recognize Spaces you have to use the #Spc and parsing to build the string.

Physical Resist = Physical , #Spc , Resist
Fire Resist = Fire , #Spc , Resist
Lower Mana Cost = Lower , #Spc , Mana , #Spc , Cost 

Sample code of how the Sub Works

Code: [Select]
Display Target the Item you wish to see the Physical Resist of
Set #targcurs 1
While #targcurs = 1
wait 1
Gosub Property #Ltargetid Physical , #spc , Resist
Display The Physical Resist is #Result
Halt


You can Disect the Sub if you'd like, but I'll explain the Input/output Values. You can Only Check 1 Property at a time. It uses #Result to return the Value that it found for that Property 0 if the value was 0 or if the property wasn't on the item. It Also reads all Values of the String,

So if you just told it Gosub Property (Id) Resist

It would find Each value after each word "Resist" And sum them up Giving you the total Resists on the piece of armor.

Title: Re: Getting the value of Physical Resist from a piece of armor
Post by: Grandewd on July 11, 2014, 04:19:46 PM
Hi Manwinc,

Thank you for taking the time to respond, and for yet another reason to more fully understand global namespaces and persistent variables.

If you don't mind, could you possibly explain a couple of things to me:

From your example:

Code: [Select]
NameSpace Push
Namespace Local Mwinc_Property
set !Item %1
set !Property %2
For !Attempt 1 10

1)  I've looked at many scripts that are using global variables, and quite a few of them never use the NameSpace Push/Clear/Pop.  When and why are they sometimes used and other times not?
2)  set !Item %1  (So this sets a namespace variable (!Item) to a normal variable (%1) ) correct?  Why do I do that, ie, where is that %1 variable used?

Sorry if these questions are so very basic, but I don't have a mental image of what's happening there....
Title: Re: Getting the value of Physical Resist from a piece of armor
Post by: manwinc on July 11, 2014, 04:47:31 PM
So, Lets say you are using a sub. And Inside of that Sub you use another Sub.

Code: [Select]
Gosub Test 1 2 3
Halt

Sub Test
Display  % , 1 = %1 $ % , 2 = %2 $ % , 3 = %3
Gosub Test2 4 5 6
Display  % , 1 = %1 $ % , 2 = %2 $ % , 3 = %3
Return

Sub Test2
Return

So, When you use the Gosub Command, it automatically sets the %0 %1 %2 %3 %4 Variables etc, So if you use a Gosub Within A sub, those Variables are going to change from what they originally were as you can see from the example code.

Its just good habit that if you are writing Universal Subs that you go ahead and set ! Variables to the %1-%n

Not Sure how much you've gotten to Play with Namespaces, but I'll give a brief Explanation.

Namespaces are used to "Separate" your Variables from other Variables that are being used throughout the Script, and can also be used to communicate information between Scripts (Bit more Advanced)

The Idea, is that when you use these "Universal" Subs, that they don't Change any of the % Variables, but still perform the task that was given to them.

You start off with a Namespace Push, This "Saves" Whatever the Last Namespace was so at the end of your Sub you Can Namespace Pop, Which Returns it to the original Namespace. What you'll see in most of my subs is what you've already noticed


Code: [Select]
Sub Test
Namespace Push ; Saves whatever the last namespace was
Namespace Local Name_Of_Namespace_Here
set !Var1 %1 ; Saving the %1-%n Variables to ! Variables to you don't lose them if you use a gosub inside the sub
set !Var2 %2
set !Var3 %3
;Actions
Namespace Pop ; REturns the namespace to what it was on the last Namespace Push
Return

The Concept is that if I were to Use the Sub, it would perform the action it was Built to do without Effecting any of the % Variables.