Changeset 3237

Show
Ignore:
Timestamp:
01/26/10 14:24:27 (7 months ago)
Author:
ghoulsblade
Message:
new macro tools : MacroCmd_QueuePickObject MacroCmd_QueueStringQueryResponse MacroCmd_RegisterTimeoutListener MacroCmd_PlayerPoisoned, utils for stringquery and objectpicker gump : old, seen on pol shard
Location:
trunk/lua
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/lua/lib.macrolist.lua

    r3234 r3237  
    4444function IsPlayerHidden() local mobile = GetPlayerMobile() return mobile and mobile.flag_hidden end 
    4545 
     46function MacroCmd_PlayerPoisoned () return MacroCmd_MobilePoisoned(GetPlayerMobile()) end 
     47function MacroCmd_PlayerMortaled () return MacroCmd_MobileMortaled(GetPlayerMobile()) end 
    4648function MacroCmd_MobilePoisoned (mobile) return mobile and IsMobilePoisoned(mobile) end 
    4749function MacroCmd_MobileMortaled (mobile) return mobile and IsMobileMortaled(mobile) end 
     
    513515 
    514516function MacroCmd_RiseText (r,g,b,text,serial) 
     517        text = tostring(text) 
     518        print("MacroCmd_RiseText",text) 
    515519    serial = serial or GetPlayerSerial() 
    516520    if (SpellBarRiseTextOnMob) then SpellBarRiseTextOnMob(serial,r,g,b,text) end 
     521        GuiAddChatLine(text,{r,g,b,1},"normal","script") 
    517522end 
    518523 
     
    821826                        for k,text in pairs(textlist) do if (string.find(plaintext,text)) then return k,plaintext,data end end  
    822827                end,timeout_delay or 9000)  
     828end 
     829 
     830 
     831function MacroCmd_JobWaitAndPickObject (index,timeout_delay)  
     832        assert(index)  
     833        return MacroCmd_WaitForListener("Hook_ObjectPicker",function (data) data.SendPickedObject(index) return true end,timeout_delay or 500)  
     834end 
     835 
     836function MacroCmd_JobWaitAndStringQueryResponse (response,timeout_delay) 
     837        assert(response)  
     838        return MacroCmd_WaitForListener("Hook_StringQuery",function (data) data.SendText(response) return true end,timeout_delay or 500) 
     839end 
     840 
     841function MacroCmd_QueuePickObject                       (index,timeout_delay)           job.create(function () MacroCmd_JobWaitAndPickObject(index,timeout_delay) end) end 
     842function MacroCmd_QueueStringQueryResponse      (response,timeout_delay)        job.create(function () MacroCmd_JobWaitAndStringQueryResponse(response,timeout_delay) end) end 
     843 
     844function MacroCmd_RegisterTimeoutListener (listenername,fun,timeout_delay) 
     845        timeout_delay = timeout_delay or 1000 
     846        local timeout = gMyTicks+timeout_delay 
     847        RegisterListener(listenername,function (...)  
     848                if (gMyTicks > timeout) then return true end 
     849                return fun(...) 
     850                end) 
    823851end 
    824852 
  • trunk/lua/lib.objectpicker.lua

    r3092 r3237  
    1111        local b = {} 
    1212        local c = {} 
    13         local rows = { {{type="Label",  text=question},},a,b,c } 
     13        local d = {} 
     14        local e = {} 
     15        local cancelrow = {} 
     16        local rows = { {{type="Label",  text=question},},a,b,c,d,e,cancelrow } 
    1417         
    15         for k,entry in pairs(data.entrylist) do  
     18        function data.SendPickedObject (index) 
     19                if (not data.dialog) then return end 
     20                local entry = data.entrylist[index]  
     21                if (not entry) then print("ObjectPicker:SendPickedObject: entry not found",index) return end 
     22                Send_Picked_Object(data.dialogid,data.menuid,entry.index,entry.artid,entry.hue) 
     23                data.dialog:Destroy() 
     24                data.dialog = nil 
     25        end 
     26        --~ MacroCmd_QueueStringQueryResponse() 
     27         
     28        for k,entry in ipairs(data.entrylist) do  
    1629                table.insert(a  ,MakeUOArtImageForDialog(entry.artid,entry.hue,64,64)) 
    17                 table.insert(b  ,{type="Label", text=entry.name}) 
    18                 table.insert(c  ,{type="Button",onMouseDown=function(widget)  
    19                         Send_Picked_Object(data.dialogid,data.menuid,k,entry.artid,entry.hue) 
    20                         widget.dialog:Destroy() end,text="choose"}) 
     30                table.insert(b  ,{type="Label", text=entry.name.." "}) 
     31                table.insert(c  ,{type="Button",onMouseDown=function(widget) data.SendPickedObject(entry.index) end,text="choose"}) 
     32                table.insert(d  ,{type="Button",onMouseDown=function(widget) data.SendPickedObject(entry.index) MacroCmd_QueueStringQueryResponse("10") end,text="10"}) 
     33                table.insert(e  ,{type="Button",onMouseDown=function(widget) data.SendPickedObject(entry.index) MacroCmd_QueueStringQueryResponse("30") end,text="30"}) 
    2134        end 
     35        table.insert(cancelrow  ,{type="Button",onMouseDown=function(widget) Send_Picked_Object_Cancel() widget.dialog:Destroy() end,text="cancel"}) 
    2236         
    23         local dialog = guimaker.MakeTableDlg(rows,100,10,true,true,gGuiDefaultStyleSet,"window") 
     37        data.dialog = guimaker.MakeTableDlg(rows,100,10,true,true,gGuiDefaultStyleSet,"window") 
     38        NotifyListener("Hook_ObjectPicker",data) 
    2439end 
    2540 
    2641function HandleStringQuery (data) 
    2742        print("HandleStringQuery",data.id,data.parentid,data.buttonid) 
     43        function data.SendText (txt) 
     44                if (not data.dialog) then return end 
     45                txt = tostring(txt) 
     46                print("HandleStringQuery res=",txt) 
     47                Send_String_Query_Response(data.id,data.parentid,data.buttonid,txt) 
     48                data.dialog:Destroy() 
     49                data.dialog = nil 
     50        end 
    2851        local rows = { 
    2952                { {data.text} }, 
    3053                { {type="EditText",controlname="entry",w=200,h=24,text=data.text2} }, 
    31                 { {"OK",function (widget)  
    32                                 local txt = widget.dialog.controls["entry"]:GetText() or "" 
    33                                 print("HandleStringQuery",txt) 
    34                                 Send_String_Query_Response(data.id,data.parentid,data.buttonid,txt) 
    35                                 widget.dialog:Destroy() 
    36                         end} }, 
     54                { {"OK",function (widget) data.SendText(widget.dialog.controls["entry"]:GetText() or "") end}, 
     55                  {"1",function () data.SendText("1") end} , 
     56                  {"5",function () data.SendText("5") end} , 
     57                  {"10",function () data.SendText("10") end} , 
     58                  {"30",function () data.SendText("30") end} , 
     59                  }, 
    3760                } 
    38         local dialog = guimaker.MakeTableDlg(rows,100,100,false,true,gGuiDefaultStyleSet,"window") 
     61        data.dialog = guimaker.MakeTableDlg(rows,100,100,false,true,gGuiDefaultStyleSet,"window") 
     62        NotifyListener("Hook_StringQuery",data) 
    3963end 
  • trunk/lua/net/net.objectpicker.lua

    r3234 r3237  
    1414        out:PushNetUint16(hue) 
    1515        out:SendPacket() 
    16 end 
     16end     
     17function Send_Picked_Object_Cancel () Send_Picked_Object(0,0,0,0,0) end -- 0x7D 
     18 
     19 
    1720 
    1821--[[ 
     
    4851        local sizeleft = size - 1 - 2 - 4 - 2 - 1 - data.questionlen 
    4952        data.entrynum           = input:PopNetUint8() 
     53        sizeleft = sizeleft - 1 
    5054        print("kPacket_Object_Picker",SmartDump(data)) 
    5155        data.entrylist = {} 
     
    5357                if (sizeleft <= 0) then break end 
    5458                local entry = {} 
     59                entry.index             = i 
    5560                entry.artid             = input:PopNetUint16() -- (e.ItemID & 0x3FFF) 
    5661                entry.hue               = 0 
  • trunk/lua/net/net.trade.lua

    r3102 r3237  
    112112                end 
    113113 
    114                 if (false) then -- debug 
     114                if (1 == 1) then -- debug 
    115115                        for k,item in pairs(GetContainerContentList(playerBackpackContainer)) do  
    116                                 printf("item serial=0x%08x artid=0x%04x in backpack\n",item.serial,item.artid) 
     116                                print("item backpack",hex(item.serial),hex(item.artid)) 
    117117                        end 
    118118                        for k,item in pairs(GetMobileEquipmentList(playerMobile)) do  
    119                                 printf("item serial=0x%08x artid=0x%04x equipped\n",item.serial,item.artid) 
     119                                print("item equipped",hex(item.serial),hex(item.artid)) 
    120120                        end 
    121121                end 
     
    135135                        good.item               = GetObjectBySerial(good.itemserial) 
    136136                        --- old : see also get obj with good.itemserial from playerBackpackContainer 
     137                         
     138                        print("kPacket_Shop_Sell",hex(good.itemserial,8),hex(good.itemartid),hex(good.item.artid),good.price,good.name) 
    137139 
    138140                        if (good.item) then -- item is not always available, especially if its in the backpack, and that has not been opened yet 
    139141                                if (good.itemartid ~= good.item.artid)  then 
    140                                         printf("FATAL : kPacket_Shop_Sell : artid mismatch 0x%04x != 0x%04x\n",good.itemartid,good.item.artid) 
    141                                         print("FATAL ! kPacket_Shop_Sell -> forced Crash") 
    142                                         NetCrash() 
     142                                        print("warning : kPacket_Shop_Sell : artid mismatch "..hex(good.itemartid).." != "..good.item.artid,good.name,"amt:",good.itemamount,good.item.amount) 
     143                                        --~ print("FATAL ! kPacket_Shop_Sell -> forced Crash") 
     144                                        --~ NetCrash() 
    143145                                end 
    144146                                if (good.itemamount ~= good.item.amount) then