推荐地图:火影无级别混战推荐地图:楚汉争霸推荐地图:魔神推荐地图:人族无敌II
推荐专区:技能创作区推荐专区:WE讨论区推荐专区:模型作区推荐专区:申请公告区
 33 12
发新话题
打印

[教程] 背包切换与物品叠加演示

本主题由 茅山道士 于 2008-12-8 16:57 关闭

背包切换与物品叠加演示

之前看到有人问这个,还是花了点时间做了一下

支持任意设置背包数量
支持物品跨背包叠加
支持背包的前后切换设置。



做的时候遇到一个问题:函数UnitAddItemToSlotById这个函数每次建物品都建在英雄脚下,最后演示不得不先拿个物品占用前面的各自,演示是没有问题,放心使用,不过谁能帮我解答一下这个问题

附件

背包切换与物品叠加演示.w3x (15.25 KB)

2008-10-29 21:33, 下载次数: 19

本帖最近评分记录
东门吹牛的演示不错呀,都很有针对性,以后回答问题方便多了...
我的问题就没有人回答么?

回复 板凳 pbhpbhpbh 的帖子

什么问题?
哦,上面的问题吗?先问一下,是不是用J的?我不会J,所以就不能回答了
其实就是T里面的新建物品到英雄的指定物品栏,不知道为什么每次都建在英雄脚下,英雄物品栏是空的,我看了函数返回值是false

TOP

回复 6楼 pbhpbhpbh 的帖子

那一会儿再下载看一下,先去洗个澡,刚刚加班回来,累了!

PS:其实我查BUG很没有耐心的,所以一般也只等别人来查,不知道为什么工作后脾气变得有点爆了..

TOP

Bug我倒是测试过了,好像没有,不过照橙子的意思用UnitAddItemById返回是个Item型所以可能泄露,而UnitAddItemToSlotById就没有这个问题了
道士竟然不懂JASS,其实我也是刚学JASS的,因为其他编程基础很好,所以学的快,建议道士也去学学

TOP

回复 8楼 pbhpbhpbh 的帖子

嘿嘿,不想学了,我是不会写J,但会用别人的,也能看懂一些简单的J,但要我写就不会了..

TOP

洗澡去了,衣服找到了..

TOP

回复 6楼 pbhpbhpbh 的帖子

不知道你想说什么,为什么我用T给英雄指定的物品栏创建物品时也可以.

TOP

同上```
我的帖子总索引

求工具以及下载属性领取贴

一切都是浮云``对``就是浮云``

TOP

我在用JASS做时用这个函数始终不能创建物品在英雄身上,不知道什么问题,语法绝对没错,就是创建在地上了

TOP

再次试验.
肯定有效.
惟一会出现掉地上的时候.
是因为那格已经有物品了
不管还有没空位 都掉地上
我的帖子总索引

求工具以及下载属性领取贴

一切都是浮云``对``就是浮云``

TOP

但我做演示时已经将那格的物品删了,怎么还会有这个问题?

TOP

你把每个动作都加上debug 和等待1秒.
注意观察下每1步的运行情况
我的帖子总索引

求工具以及下载属性领取贴

一切都是浮云``对``就是浮云``

TOP

即使之前物品栏空的也有错

TOP

你写个你出错的演示 发来看看
我的帖子总索引

求工具以及下载属性领取贴

一切都是浮云``对``就是浮云``

TOP

好的,马上

TOP

COPY JASSCODE
JASS:

function U2I takes unit u returns integer
    return u
    return 0
endfunction
function gc takes nothing returns gamecache
    if udg_gc==null then
        set udg_gc=InitGameCache("DMCN.w3v")
        call StoreInteger(gc(),"Main","BagCount",3)
    endif
    return udg_gc
endfunction
function SetBagCount takes integer i returns nothing
    if i>=1 then
        call StoreInteger(gc(),"Main","BagCount",i)
    endif
endfunction 
function GetBagIndex takes unit u returns integer
    return GetStoredInteger(gc(),"U"+I2S(U2I(u)),"BagIndex")
endfunction
function GetItemId takes unit u,integer i,integer j returns integer
    return GetStoredInteger(gc(),"U"+I2S(U2I(u)),"B"+I2S(i)+"I"+I2S(j))
endfunction
function GetItemCount takes unit u,integer i,integer j returns integer
    return GetStoredInteger(gc(),"U"+I2S(U2I(u)),"B"+I2S(i)+"C"+I2S(j))
endfunction
function FindItemLoc takes unit u,item i returns integer
    local integer j=0
    loop
        exitwhen j>5
        exitwhen UnitItemInSlot(u,j)==i
        set j=j+1
    endloop
    return j
endfunction
function CheckItem takes unit u,item i returns integer
    local integer j=0
    loop
        exitwhen j>5
        if j!=FindItemLoc(u,i) then
            exitwhen GetItemTypeId(UnitItemInSlot(u,j))==GetItemTypeId(i)
        endif
        set j=j+1
    endloop
    return j
endfunction
function SaveBag takes unit u returns nothing
    local integer i=1
    loop
        exitwhen i>6
        call StoreInteger(gc(),"U"+I2S(U2I(u)),"B"+I2S(GetBagIndex(u))+"I"+I2S(i),GetItemTypeId(UnitItemInSlot(u,i-1)))
        call StoreInteger(gc(),"U"+I2S(U2I(u)),"B"+I2S(GetBagIndex(u))+"C"+I2S(i),GetItemCharges(UnitItemInSlot(u,i-1)))
        set i=i+1
    endloop
endfunction
function GetBag takes unit u returns nothing
    local integer j=1
    local integer c
    loop
        exitwhen j>6
        if UnitItemInSlot(u,j-1)!=null then
            call RemoveItem(UnitItemInSlot(u,j-1))
        endif
        set c=GetItemId(u,GetBagIndex(u),j)
        if c!=0 then
            call UnitAddItemToSlotById(u,c,j-1)
            call SetItemCharges(GetLastCreatedItem(),GetItemCount(u,GetBagIndex(u),j))
        endif
        set j=j+1
    endloop
    set j=0
endfunction
//更换包裹,i小于0则反向
function SwapBag takes integer i returns nothing
    local unit u=GetTriggerUnit()
    local integer n=GetBagIndex(u)
    call SaveBag(u)
    if n+i>=GetStoredInteger(gc(),"Main","BagCount") then
        set n=0
    elseif n+i<0 then
        set n=GetStoredInteger(gc(),"Main","BagCount")-1
    else
        set n=n+i
    endif
    call StoreInteger(gc(),"U"+I2S(U2I(u)),"BagIndex",n)
    call DisplayTextToForce(GetForceOfPlayer(GetOwningPlayer(u)),GetUnitName(u)+"|cff00ff00切换到第r"+I2S(n+1)+"|cff00ff00个物品栏|r")
    call GetBag(u)
endfunction
//获得物品时找到原来的物品进行叠加,包括物品不在当前物品栏 
function GetItem takes nothing returns nothing 
    local unit u=GetTriggerUnit()
    local item i=GetManipulatedItem()
    local integer n=GetStoredInteger(gc(),"Main","BagCount")
    local integer j=0
    local integer k=CheckItem(u,i)
    local integer c
    call DisableTrigger(GetTriggeringTrigger())
    if k<6 then
        call SetItemCharges(UnitItemInSlot(u,k),GetItemCharges(UnitItemInSlot(u,k))+GetItemCharges(i))
        call RemoveItem(i)
    else
        loop
            exitwhen j>=n
            if j!=GetBagIndex(u) then
                set k=1
                loop
                    exitwhen k>6
                    if GetItemId(u,j,k)==GetItemTypeId(i) then
                        set c=GetItemCharges(i)+GetItemCount(u,j,k)
                        call StoreInteger(gc(),"U"+I2S(U2I(u)),"B"+I2S(j)+"C"+I2S(k),c)
                        call RemoveItem(i)
                        set k=6
                        set j=n
                    endif
                    set k=k+1
                endloop
            endif
            set j=j+1
        endloop
    endif
    call EnableTrigger(GetTriggeringTrigger())
endfunction

Shingo Jass Highlighter 0.4

TOP

 33 12
发新话题