|
随便分享几个函数
def random_index(self,intt):
"""概率函数"""
#
# 参数intt为int,输入1到100数如输入40那么返回0的概率为40% 返回1的概率为60%
#
rate = [intt,100-intt]
start = 0
randnum = random.randint(1, sum(rate))
for index, item in enumerate(rate):
start += item
if randnum <= start:
break
return index
def effect(self, entityId, effect, time, level,boolc):
"""效果函数 1,id 2,效果名字 3,时间 4,效果等级,5是否显示粒子"""
comp = serverApi.GetEngineCompFactory().CreateEffect(entityId)
res = comp.AddEffectToEntity(effect, time, level, boolc)
return res
def Hurt2(self, idd, entityId, hurt,knocked,y):
"""模拟攻击多个实体 1,创造者ID 2,要攻击的对象ID列表 3,攻击伤害 4,Y轴的瞬时移动"""
for value in entityId:
if value != idd:
# comp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
# entityitemName = comp.GetEntityIdentifier(value)
comp = serverApi.GetEngineCompFactory().CreateEngineType(value)
entityitemName = comp.GetEngineTypeStr()
comp = serverApi.GetEngineCompFactory().CreatePos(value)
pos = comp.GetPos()
if entityitemName != "minecraft:item" and value != idd and pos != None:
comp = serverApi.GetEngineCompFactory().CreateHurt(value)
comp.Hurt(hurt, serverApi.GetMinecraftEnum().ActorDamageCause.EntityAttack, idd, None, knocked)
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(value)
motionComp.SetMotion((0,y, 0))
def zhidingfaswu(self, idd, pos1, pos2,item):
"""指定一个位置发射抛射物 到指定目标位置 1,发射人ID 3,发射物创建位置 3,目标位置"""
x = pos1[0] - pos2[0]
y = pos1[1] - pos2[1]
z = pos1[2] - pos2[2]
ros = (-x,-y,-z)
comp = serverApi.GetEngineCompFactory().CreateProjectile(serverApi.GetLevelId())
param = {
# 'position': (pos[0]+random.randint(-5,5),pos[1]+random.randint(2,8),pos[2]+random.randint(-5,5)), #发射位置
'position': pos1, #发射位置
'direction': ros, #朝向
'power': 1, #投掷的力量值,越大发射的速度越快
'gravity': 0.01, #抛射物重力因子,默认为json配置中的值
'damage': 20, #抛射物伤害值,默认为json配置中的值
# 'targetId': str(item) #抛射物目标(指定了target之后,会和潜影贝生物发射的跟踪导弹的那个投掷物是一个效果),默认不指定
# 'isDamageOwner': False #对创建者是否造成伤害,默认不造成伤害
# 火焰弹minecraft:fireball(ok) 魔影住minecraft:ender_pearl(ok) 箭minecraft:arrow
}
ectileEntityid = comp.CreateProjectileEntity(idd, "zhuzhizi:fireball", param)
return ectileEntityid
def Get_PlayerItemPos(self, idd):
"""返回背包为None的槽位 如果槽位都有物品返回None"""
a = 0
while a < 36:
comp = serverApi.GetEngineCompFactory().CreateItem(idd)
PlayerItem = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, a)
if PlayerItem == None:
return a
if a >= 35:
return None
a = a +1
|
|