Author Topic: First script - Simple item mover  (Read 23370 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
Re: First script - Simple item mover
« Reply #15 on: October 14, 2010, 07:01:44 AM »
+1
I'm kinda understanding it so far... looks like a lot of holes yet though.
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 Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: First script - Simple item mover
« Reply #16 on: October 14, 2010, 07:03:39 AM »
+1
I'm kinda understanding it so far... looks like a lot of holes yet though.

only steps 3b and 3c for completion.   step 3b is another leaning curve... 3c same old same old
« Last Edit: October 14, 2010, 07:05:43 AM by Endless Night »
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: First script - Simple item mover
« Reply #17 on: October 14, 2010, 07:59:05 AM »
+1
step 3b
Get ITem Type from UO.LTargetID

Well in EUO this would have been farily simple
Code: [Select]
finditem #ltargetid
If #findcnt > 0
  set !ITemType #findtype

OpenEUO does not filter finditem results instead it returns results as if you did finditem *, so you have to the filtering yourself.

Now this is going to be a bit of code were going to use over and over perhaps in many scripts. Thierfor it makes sense to turn it into a sub/function

Code: [Select]
function ENs_GetItemTypeFromItemID(nItemID)
  local nThisType = nil
  local nCnt = UO.ScanItems(true) -- visible only
  local nIndex = 0
  while nIndex < nCnt and nThisType == nil do
    local nID,nType,nKind,nContID,nX,nY,nZ,nStack,nRep,nCol = UO.GetItem(nIndex)
    if nID == nItemID then nThisType = nType end
    nIndex = nIndex + 1
    end
  return nThisType
end

What does this sub do... finditem *   .. then it iterates throw each of the founditems looknig for the one that matches the ID we passed as an argument.  When it finds it .. it returns the itemtype value.

So in our main code we replace the comment line with .
Code: [Select]
   nItemTypeToMove = ENs_GetItemTypeFromItemID(UO.LTargetID)
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: First script - Simple item mover
« Reply #18 on: October 14, 2010, 08:16:20 AM »
+1
Step 3c
Not above i referenced 3c in 2 different ways. 
a) move items of type x from source containor to destination containor
b) move all items from source containor to destination containor

This is also a sub that will be used many times from many scripts thier for a function is called for

Code: [Select]
function ENs_MoveITemsFromTo(nFromBag, nToBag, nItemType)  -- pass nitemtype -1 if not by type
 local nMoved = 0
 for nIndex = 0 , UO.ScanItems(true)-1 do
   local nID,nType,nKind,nContID,nX,nY,nZ,nStack,nRep,nCol = UO.GetItem(nIndex)
   if nContid == nFromBag then
     if ( nItemType ~= -1 and nType == nItemType ) or nItemType == -1 then
        nMoved = nMoved + ENs_MoveItemToContainor(nID , nToBag )  end
     end
 end
 return nMoved
end

function ENs_MoveItemToContainor(nID , nContID)
  UO.Drag(nID)
  wait(600)
  UO.DropC(nContID)
  wait(600)
  return 1
end


We shall call it like this in the 2 different instances
Quote
local nItemsMoved = ENs_MoveITemsFromTo(nSourceBag, nDestinationBag, nItemTypeToMove)  -- if nItemTypeToMove = -1 it moves all items in souce bag


Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: First script - Simple item mover
« Reply #19 on: October 14, 2010, 08:25:26 AM »
+1
Bonus Points
The script is done.    But we made some nice functions in this project that i think i will use over and over.   And as such i dont want to include them in my script and clutter it up.  So im going to cut out the functions into my first main sub library that i can call from every script i write.

So imgoing to create 2 files
MyLibrary.lua  and ItemMover.lua  

In ItemMover.lua im going to reference mylibrary.lua like so
Code: [Select]
dofile('MyLibrary.lua')
Contents of MyLibrary.lua
Code: [Select]
-------------------------------------------------------
-- Functions (subs) - Ive ripped from others per credits
-------------------------------------------------------
function msgbox(default, prompt, title, button, icon)
   -- Function By Traegon's, Link: http://www.easyuo.com/forum/viewtopic.php?p=376784#376784
  if icon == nil then icon = 2 end
  if default == true then default = 1 else default = 0 end
 
  ConfirmDialog = Obj.Create("TMessageBox")
  ConfirmDialog.Title = title
  ConfirmDialog.Button = button
  ConfirmDialog.Icon = icon
  ConfirmDialog.Default = default
  return ConfirmDialog.Show(prompt)
end

function ENs_GetItemTypeFromItemID(nItemID)
  local nThisType = nil
  local nCnt = UO.ScanItems(true) -- visible only
  local nIndex = 0
  while nIndex < nCnt and nThisType == nil do
    local nID,nType,nKind,nContID,nX,nY,nZ,nStack,nRep,nCol = UO.GetItem(nIndex)
    if nID == nItemID then nThisType = nType end
    nIndex = nIndex + 1
    end
  return nThisType
end

function ENs_MoveItemsFromTo(nFromBag, nToBag, nItemType)  -- pass nitemtype -1 if not by type
 local nMoved = 0
 for nIndex = 0 , UO.ScanItems(true)-1 do
   local nID,nType,nKind,nContID,nX,nY,nZ,nStack,nRep,nCol = UO.GetItem(nIndex)
   if nContID == nFromBag then
     if ( nItemType ~= -1 and nType == nItemType ) or nItemType == -1 then
        nMoved = nMoved + ENs_MoveItemToContainor(nID , nToBag )  end
     end
 end
 return nMoved
end

function ENs_MoveItemToContainor(nID , nContID)
  UO.Drag(nID)
  wait(600)
  UO.DropC(nContID)
  wait(600)
  return 1
end

-----------------------------
-- My Defined Functions (subs)
-----------------------------
function MessageBox(sPrompt, sTitle, sType)
  if sType == 'OK'    then  return msgbox(true, sPrompt, sTitle, 0,4) end
  if sType == 'YESNO' then  return msgbox(true, sPrompt, sTitle, 4,3) end
end

function TargetOpenBag(sMessage)
  UO.LTargetKind = 1 -- object
  MessageBox(sMessage, 'Bag Selection:', 'OK' )  
  UO.TargCurs = true    -- make a target cursor
  while UO.TargCurs == true do  wait(10) end     -- wait until something is clicked (ie notarget cursor)
  UO.LObjectID = UO.LTargetID    -- set last object to the object clicked
  UO.Macro(17,0) -- openbag ( invoke macro use last object which hopefully is a bag inwhich case opens bag )
  return  UO.LTargetID  -- set the return value .. the bagid clicked
end


Contents of ItemMover.lua
Code: [Select]
-----------------------------
--Load Code Librarys
-----------------------------
dofile('MyLibrary.lua')

-----------------------------
-- Script Starts Below
-----------------------------
repeat
  local nSourceBag = TargetOpenBag('Please Target The Source Bag:')           -- step 1
  local nDestinationBag = TargetOpenBag('Please Target The Destination Bag:') -- step 2
  local nResult = MessageBox('Move Items By ItemType ?','Item Type', 'YESNO')
  local nItemTypeToMove = -1   -- not by type
  if nResult == 6 then
    MessageBox('Select Item Type','Item Type', 'OK')
    UO.TargCurs = true
    while UO.TargCurs == true do  wait(10) end
    nItemTypeToMove = ENs_GetItemTypeFromItemID(UO.LTargetID)
    end
  local nItemsMoved = ENs_MoveItemsFromTo(nSourceBag, nDestinationBag, nItemTypeToMove)  -- if nItemTypeToMove = -1 it moves all items in souce bag
  local nResult = MessageBox('Moved '..nItemsMoved..' items. Move more Items ?','Move Item', 'YESNO')
until nResult == 7 -- no
  


EDITED: To fix 2 capitilation typos
« Last Edit: October 14, 2010, 06:41:01 PM by Endless Night »
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: First script - Simple item mover
« Reply #20 on: October 14, 2010, 08:26:42 AM »
+1
Please post a comment and let me know if the tutorial helped or didnt help in any way.
cheers everyone.
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

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: First script - Simple item mover
« Reply #21 on: October 14, 2010, 08:28:42 AM »
+1
Ok, I'll have to go through this completely to try to understand it. I'm not sure I will completely get it though.

No matter what anyone says, this is not easier then EUO.
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 Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: First script - Simple item mover
« Reply #22 on: October 14, 2010, 08:35:07 AM »
+1
Ok, I'll have to go through this completely to try to understand it. I'm not sure I will completely get it though.

No matter what anyone says, this is not easier then EUO.

In the short run no... in the long run yes...   Once the library subs were written look at how short the code became.  So LUA will show its power and ease of use once we have a full set of library subs that do the grunt work and we can just do this

Code: [Select]
dofile('craftingsub.lua')
dofile('imbueingsubs.lua')

Makeitem('leathervest')
imbueitem(dsfdfjdjfd)
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline Paulonius

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +162
  • Referrals: 1
    • View Profile
Re: First script - Simple item mover
« Reply #23 on: October 14, 2010, 08:44:18 AM »
+1
It looks like S7 is working on some of this in his Fluent initiative.

http://www.easyuo.com/forum/viewtopic.php?t=43289
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: First script - Simple item mover
« Reply #24 on: October 14, 2010, 08:48:30 AM »
+1
Fixed a typo   Uppercase L  in Local instead of lowercase l  as in local

This is one thing about lua that drives me nuts...  Local is not a command local is.
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline Paulonius

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +162
  • Referrals: 1
    • View Profile
Re: First script - Simple item mover
« Reply #25 on: October 14, 2010, 08:51:45 AM »
+1
very helpful EN.  I am reading through this with your array discussion and its starting to make sense.  When I look at the code I am not seeing blonde, brunette, red-head yet, but I will keep at it.
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: First script - Simple item mover
« Reply #26 on: October 14, 2010, 09:23:43 AM »
+1
very helpful EN.  I am reading through this with your array discussion and its starting to make sense.  When I look at the code I am not seeing blonde, brunette, red-head yet, but I will keep at it.

Do one bit at a time .. put the code in your openEUO window .. run it see what it does...
After awhile you will see the apples on the trees.... the beauty from the beast ..   

I included quiet a number of advanced concepts...
how to define a function
How to use Finditem (scanitems)
How to make a code library
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

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: First script - Simple item mover
« Reply #27 on: October 14, 2010, 09:37:16 AM »
+1
Do one bit at a time .. put the code in your openEUO window .. run it see what it does...
After awhile you will see the apples on the trees.... the beauty from the beast ..   

I included quiet a number of advanced concepts...
how to define a function
How to use Finditem (scanitems)
How to make a code library


Function.... hmmm... find.... library.... Nope, don't get it at all. I'll continue to look at it as I know what it does. I just have no idea how it's working. Like learning another language, easy to learn to read the words, difficult to know what they mean.
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: First script - Simple item mover
« Reply #28 on: October 14, 2010, 02:53:17 PM »
+1
So uhm... did you ever test this cause I'm trying it and my target cursor comes up, nothing else... and it doesn't do squat.
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: First script - Simple item mover
« Reply #29 on: October 14, 2010, 02:55:31 PM »
+1
Ok, d-loaded the newest? version of OEUO and now it will bring up my target cursor and when I target something it uses it. So opens packs, opens gumps... etc...

Not the first simple example I was looking for. Thus far, I'd have to score it a fail.
« Last Edit: October 14, 2010, 02:58:23 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.

Tags: