Giter Site home page Giter Site logo

Comments (3)

XavierCHN avatar XavierCHN commented on August 25, 2024

这种写法是没有问题的,如果有问题,大概是哪里的代码没写对,建议附上完整代码
不过有个小问题需要确认,如果是直接创建在单位身上的物品,是不会触发picked up的,这个只有在拾取的时候才会触发

from x-template.

ddddnanana avatar ddddnanana commented on August 25, 2024

这个问题我试了捡东西的时候会触发我自己写的函数 但是现在遇到一个新的问题 完整代码如下
export class BackpackMain {
Player:CDOTAPlayerController
ItemContaineies:Record<number,ItemContainer>

constructor(Player:CDOTAPlayerController){   
    this.Player = Player
    this.registerC2S()
    this.registerofficialEvent()       
}
/**初始化一个背包里的容器情况*/
initItemContainer(){
    Array(backpackConstantTable.defaultnumber).forEach((value,index)=>{
        this.ItemContaineies[index] = new ItemContainer(index,this)
    })
}
s2c(key:BackpackMains2ckey,sendData:send){
    CustomGameEventManager.Send_ServerToPlayer(this.Player,key,sendData)
 
}
c2s_item_exchange(event:CGAMEEVENT['c2s_item_exchange']){

}
c2s_item_discardItems(event:CGAMEEVENT['c2s_item_discardItems']){

}
/**客户端要求发送所有数据*/
c2s_item_get_totalInformation(event:CGAMEEVENT['s2c_item_send_totalInformation']){

}
registerC2S(){
    const registerTable:Record<registerC2S,Function>={
        "c2s_item_exchange":this.c2s_item_exchange,
        "c2s_item_discardItems":this.c2s_item_discardItems,
        "c2s_item_get_totalInformation":this.c2s_item_get_totalInformation
    }
    for(const key in registerTable){
    CustomGameEventManager.RegisterListener(key,(event)=>{
        registerTable[key](event)
    })
    }
}

/**查找最近的空背包容器 */
FindEmptyContainer(){
for(const key in this.ItemContaineies){
if(this.ItemContaineies[key].isNull()){
return this.ItemContaineies[key].index
}
}
return -1
}
/**当物品被拾取时触发 */
dota_item_picked_up(event:GameEventProvidedProperties & DotaItemPickedUpEvent){
const item = EntIndexToHScript(event.ItemEntityIndex) as CDOTA_Item /**转化成实例 */
print(item.GetName())
item.RemoveSelf()
const current_null_index = this.FindEmptyContainer()
if(current_null_index==-1){
return
}
this.ItemContaineies[current_null_index].setItem(new Item(item.GetName()))

}


/**注册官方事件 */
registerofficialEvent(){
    ListenToGameEvent("dota_item_picked_up",(event)=>this.dota_item_picked_up(event),null)
}

}

运行到 for(const key in this.ItemContaineies)这一行 就会报错
Script Runtime Error: scripts\vscripts\package/Main.ts:75: bad argument #1 to 'pairs' (table expected, got nil)

我以前都是这么用的呀 是因为什么原因呀

from x-template.

ddddnanana avatar ddddnanana commented on August 25, 2024

你好 这个问题我解决了 我自己的容器类没有初始化 初始化之后就好了 可以关闭了

from x-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.