Comments (3)
这种写法是没有问题的,如果有问题,大概是哪里的代码没写对,建议附上完整代码
不过有个小问题需要确认,如果是直接创建在单位身上的物品,是不会触发picked up的,这个只有在拾取的时候才会触发
from x-template.
这个问题我试了捡东西的时候会触发我自己写的函数 但是现在遇到一个新的问题 完整代码如下
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.
你好 这个问题我解决了 我自己的容器类没有初始化 初始化之后就好了 可以关闭了
from x-template.
Related Issues (20)
- 1.0版本的panorama不会自动更新 HOT 1
- yarn dev报错 HOT 1
- npm run dev 时报错 HOT 2
- moddota中关于useState的用例不能显示ToggleButton Slider组件问题 HOT 3
- 关于用less还是scss的问题 HOT 1
- CustomGameEventManager这个类 没有了呀 还发现了几个 HOT 1
- 会导致游戏闪退的情况集合 HOT 4
- node-gyp could not use PowerShell to find Visual Studio 2017 or newer HOT 1
- 无法正常运行 HOT 1
- TS2584: Cannot find name 'console'. Do you need to change your target library? HOT 2
- 能够实现修改dota自走棋的ui界面么 HOT 2
- 请问一下,能从游戏内存中拿到秘钥嘛? HOT 2
- XState吞错
- Excel to KV 报错:herolist.txt is duplicated HOT 1
- yarn install 报错`C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe` failed with exit code: 1 HOT 2
- 为什么本地调试没问题,一发到游廊上地图都打不开 HOT 1
- 新手 一个关于UI的问题
- yarn dev 后出现如下报错 HOT 1
- CustomGameEventManager类函数泛型推断问题 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from x-template.