1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Greetings Guest!!

    In order to combat SPAM on the forums, all users are required to have a minimum of 2 posts before they can submit links in any post or thread.

    Dismiss Notice
  3. Greetings Guest, Having Login Issues? Check this thread!
    Dismiss Notice
  4. Hail Guest!,
    Please take a moment to read this post reminding you all of the importance of Account Security.
    Dismiss Notice

[Tech Help] Command Line Script to Store a Variable Permanently

Discussion in 'UO Enhanced Client Discussion' started by Llewen, Jan 19, 2017.

  1. Llewen

    Llewen Grand Inquisitor
    Stratics Veteran Stratics Legend Campaign Supporter

    Joined:
    Mar 3, 2006
    Messages:
    4,789
    Likes Received:
    250
    I'd like to make a command line script that can store the name of an object permanently to use in other command line scripts. What I want to do is run the script, it presents a target, I can target a pet, it stores the name of that pet in a variable, which I can then use in another script instead of having to edit the script every time I change pets.
     
  2. petemage

    petemage Slightly Crazed

    Joined:
    Oct 6, 2013
    Messages:
    1,372
    Likes Received:
    1,135
    Sorry, not gonna try to put this into command script items, but what you want to do is:

    1)
    Code:
    RequestTargetInfo()
    will give you an cursor to select (request) an target. That's the easy part.

    2) To get the response (target) you have to register to the SystemData.Events.TARGET_SEND_ID_CLIENT event. This is accomplished by
    Code:
    WindowRegisterEventHandler("MyWindow", SystemData.Events.TARGET_SEND_ID_CLIENT, "MyWindow.RequestTargetInfoReceived")
    3) Once you selected a target,
    Code:
    MyWindow.RequestTargetInfoReceived
    will be called and you can use
    Code:
    SystemData.RequestInfo.ObjectId
    to get the Id of the selected object (i.e. your pet)

    4) To get from the id to the pet's name, you need to register windowdata for pets with
    Code:
    RegisterWindowData(WindowData.Pets.Type, 0)
    and then you can loop through all pets to find the one you targeted:
    Code:
    if (WindowData.Pets.PetId ~= nil ) then	
    		local petSize = table.getn(WindowData.Pets.PetId)
    		if (petSize > 0) then
    			for numPet = 1, petSize do
    				local mobileId = WindowData.Pets.PetId[numPet]
    								...
    5) To persist between logouts, you can use
    Code:
    Interface.SaveString( settingName, settingValue )
    to save the pets name and use LoadString to get it back. You can also store the id with StoreNumber/LoadNumber.

    Ideally you want to have a window for 2) and 3) since you don't want to mess with other target cursors of other parts of the UI. You could quick n dirty register to "Root" instead of "MyWindow", but if you cancel a request or forget to unregister the response handler that might screw things up a bit.

    If you not gonna put it into a mod, I doubt you gonna have fun with this :p
     
    #2 petemage, Jan 20, 2017
    Last edited: Jan 20, 2017
  3. Llewen

    Llewen Grand Inquisitor
    Stratics Veteran Stratics Legend Campaign Supporter

    Joined:
    Mar 3, 2006
    Messages:
    4,789
    Likes Received:
    250
    Thanks. Ya, that's a bit complex for a command line script... I think I'm stuck with editing my command line whenever I change loose pets. Not a big deal really.