Page 25 of 25

Grenade smoke

Posted: Thu May 24, 2018 3:21 am
by cieply
I tried to make exploding grenades (in PeasantRevolt) to make a smoke. After all they are made of black powder isn't it?-)

as long as I put it "directly" in the code, it works:
@ $BOD/Maps/PeasantRevolt/WeaponTypes.py::class LooseFireBomb(ItemTypes.PersistantItemType)::def Detonate(self, EntityName):
self.ImpactSound.Position=weapon.Position[0],weapon.Position[1],weapon.Position[2]
self.ImpactSound.PlaySound(0) ## -- place it here --
### generate smoke at position point rather than object/person
x=weapon.Position[0]; z=weapon.Position[1]; y=weapon.Position[2]; sx=50; sz=50; sy=50; pps=64; ptype="DarkSmoke"; t2l=80; t2d=0.70;
# x,z,y - position; sx,sz,sy - dunno; pps - particles/sec; ptype - particle type; t2l - time to live (life span of particle); t2d - time to death - life span of effect
wps = Bladex.CreateEntity("smoke_D3_"+str(int(Bladex.GetTime()*1000)), "Entity Particle System D3", x + sx, y + sy, z + sz)
wps.ParticleType = ptype
wps.PPS = pps
wps.YGravity = -400.0
wps.Friction = 0.1
wps.Velocity = 20.0, -400.0, 20.0
wps.RandomVelocity = 20.0
wps.Time2Live = t2l
wps.DeathTime = Bladex.GetTime()+t2d
but when I tried to be more elegant and enclosed it in class method then it refuses to work.
self.ImpactSound.Position=weapon.Position[0],weapon.Position[1],weapon.Position[2]
self.ImpactSound.PlaySound(0) ## -- place it here --
### generate smoke at position point rather than object/person
self.ps_smoke_D3(weapon.Position[0], weapon.Position[1], weapon.Position[2])

(...)
def ps_smoke_D3(x, y, z, sx=50, sy=50, sz=50, pps=64, ptype="DarkSmoke", t2l=80, t2d=0.70):
       wps = Bladex.CreateEntity("smoke_D3_"+str(int(Bladex.GetTime()*1000)), "Entity Particle System D3", x +sx, z, y + sy)
       (...)
I don't get it - other functions of this class work.
When attempted to debug it and enclosed with try: except: I caught this exception:
Traceback (innermost last):
File ".\WeaponTypes.py", line 1629, in Detonate
self.ps_smoke_D3(weapon.Position[0], weapon.Position[1], weapon.Position[2])
File ".\WeaponTypes.py", line 1711, in ps_smoke_D3
wps = Bladex.CreateEntity("smoke_D3_"+str(int(Bladex.GetTime()*1000)), "Entity Particle System D3", x +sx, z, y + sy)
TypeError: __add__ nor __radd__ defined for these operands
This "TypeError" is somewhat crazy as if I tried to concatenate different types of variables into a string, but I don't. And whether without function clause or even with, in separate file (`exec("my_ps.py"); ps_smoke_D3(1000, 2000, 3000);`) it runs, without problems.

Anyone understands what's going on with it?

PS. I attached .diff file so you can easier check it.

Re: Level Editing: Scripting

Posted: Sat May 26, 2018 12:27 pm
by Sryml
Hi cieply! :)
It is a class member function, the first parameter must be self

wrong:

Code: Select all

def ps_smoke_D3(x, y, z, sx=50, sy=50, sz=50, pps=64, ptype="DarkSmoke", t2l=80, t2d=0.70):
correct:

Code: Select all

def ps_smoke_D3(self, x, y, z, sx=50, sy=50, sz=50, pps=64, ptype="DarkSmoke", t2l=80, t2d=0.70):

self

Posted: Sun May 27, 2018 3:06 am
by cieply
Thanks, that's what I needed. Got me perplexed lot of times but at least I've learned something.