Help on understanding targets

Discussion in 'Script Support' started by Torozaki, Nov 8, 2017.

  1. Torozaki

    Torozaki Page

    Joined:
    Aug 23, 2015
    Messages:
    6
    Likes Received:
    0
    I'm sorry if this has been posted a million times, but I am having a little trouble understanding coding the target part of my script. I have looked through multiple scripts that use targets, as well as the Target.html in the docs folder.

    What I am trying to do:
    Make an item on the ground that a player double clicks and targets something in their pack to change a true/false setting (already mostly understand that part).

    What I am having issues with:
    A lot of the scripts I have looked at have multiple different pre-OnTarget settings and I am not sure if I need them for my script. With the assumption that I probably don't, what exactly is the "int range" used for in this?

    (ctor) Target( int range, bool allowGround, TargetFlags flags )

    That would be this line, right?:
    Code:
     public MyTarget() : base(/*int range*/, false, TargetFlags.None)
    To me it looks as though its a range from player? But that doesn't make sense with many of the scripts I have looked at. If I code it like this:

    Code:
        private class MyTarget : Target
        {
            public MyTarget() : base(0, false, TargetFlags.None)
            {
            }
            protected override void OnTarget(Mobile from, object targ)
            {
                //insert what I want my target to do
            }
        }
    Would that work?

    I got done with the rest of my script, and had to just wing it on that part. Got it to work, and it seems to work fine.

    This is what I had to put in to get it to work:
    Code:
        public class MyTarget : Target
       {
         
          public MyTarget() : base(3, false, TargetFlags.None)
            {
            }
            
            protected override void OnTarget(Mobile from, object targ)
            {
                Item item = targ as Item;
                
                if(!(item is MyItem))
               {
    insert rest of script here...
    
    Kinda took some stuff from other scripts. Found out the int is for distance target can be used from target source, which makes MANY scripts using targets not make any sense! Found some more things I need to tweak/add, but I think what I was working on is practically done. ;)
     
    #1 Torozaki, Nov 8, 2017
    Last edited: Nov 9, 2017

Share This Page