Add an automated chain lighting effect.
Possible parameters:
- normal beam effect parameters excluding second end point (x,y,z,sprite,color,speed,life)
- initial damage
- initial chain radius
- possibly affected players list
Functional parameters (contains some of the regular beam parameters):
- delay between chains nodes
- beam life
- damage reduction
- radius reduction
- color
- sound file to emit on hit
- sound volume
Return: chain lightning identifier (possibly a class instance that holds the required information)
The adjustment function can be set to be called for each beam effect to be drawn. It is to provide new values for the functional parameters. This can be used to dynamically create multiple different behaviors, such as having different algorithms of how damage is calculated based on teams, previous damage and distance.
The function should receive these parameters:
- identifier (the same as received when calling the initial method)
- iteration level
- source userid
- target userid
- distance
- previous damage
- previous radius
- previous color (r,g,b,a)
- previous sound file
- previous sound volume
- previous delay
- previous life
The function should return similar information back:
- new damage
- new radius
- new color
- new sound file
- new sound volume
- new delay
- new life
Or it can also raise StopIteration to force stopping the iteration in this chain.
There should be default values for all of the functional parameters as well, including damage and radius to reduce based on some built-in function.
If the values for functional parameters were set on first call, use those as fall back if the adjustment function returns None for the associated attribute, or if the function itself is not supplied.
Comments welcome.
Possible parameters:
- normal beam effect parameters excluding second end point (x,y,z,sprite,color,speed,life)
- initial damage
- initial chain radius
- possibly affected players list
Functional parameters (contains some of the regular beam parameters):
- delay between chains nodes
- beam life
- damage reduction
- radius reduction
- color
- sound file to emit on hit
- sound volume
- adjustment function
Return: chain lightning identifier (possibly a class instance that holds the required information)
The adjustment function can be set to be called for each beam effect to be drawn. It is to provide new values for the functional parameters. This can be used to dynamically create multiple different behaviors, such as having different algorithms of how damage is calculated based on teams, previous damage and distance.
The function should receive these parameters:
- identifier (the same as received when calling the initial method)
- iteration level
- source userid
- target userid
- distance
- previous damage
- previous radius
- previous color (r,g,b,a)
- previous sound file
- previous sound volume
- previous delay
- previous life
The function should return similar information back:
- new damage
- new radius
- new color
- new sound file
- new sound volume
- new delay
- new life
Or it can also raise StopIteration to force stopping the iteration in this chain.
There should be default values for all of the functional parameters as well, including damage and radius to reduce based on some built-in function.
If the values for functional parameters were set on first call, use those as fall back if the adjustment function returns None for the associated attribute, or if the function itself is not supplied.
Comments welcome.
class commands:
def nearcoord(self, xorigin, yorigin, zorigin, xrange, yrange, zrange, block, team, initiator):
for userid in playerlib.getUseridList(team):
loc = es.getplayerlocation(userid)
if abs(loc[0] - xorigin) <= xrange and abs(loc[1] - yorigin) <= yrange and abs(loc[2] - zorigin) <= zrange:
block(userid, initiator)
def lightning(self, xorigin, yorigin, zorigin, lightningrange, lightningtime, attacker, team):
loc = (xorigin, yorigin, zorigin)
effecttime = 0
effectloop(loc, lightningtime, lightningrange, attacker, effecttime, team)
def effectloop(loc, lightningtime, lightningrange, userid, effecttime, team):
if effecttime <= lightningtime:
random1 = random.randint(lightningrange * -1, lightningrange)
random2 = random.randint(lightningrange * -1, lightningrange)
es.server.queuecmd('esteffect 3 #all 0 sprites/lgtning.vmt %s %s %s %s %s %s 1 10 20 40 250 255 255'%(loc[0] + random1, loc[1] + random2, loc[2], loc[0] + random1, loc[1] + random2, loc[2] + 120))
effecttime += 0.03
commands().nearcoord(loc[0] + random1, loc[1] + random2, loc[2], 45, 45, 45, lightningdamage, team, userid)
gamethread.delayedname(0.03, 'effect%s'&#xus;erid, effectloop, args=(loc, lightningtime, lightningrange, userid, effecttime, team))
def lightningdamage(userid, attacker):
randomnumber = (random.randint(1, 6) * random.randint(1, 6)) - random.randint(1, 10)
randomnumber2 = (random.randint(1, 7) * random.randint(1, 7)) - random.randint(1, 10)
randomnumber3 = (random.randint(1, 7) * random.randint(1, 7)) - random.randint(1, 10)
if randomnumber > 0:
es.server.queuecmd('damage %s %s 32 %s'%(userid, randomnumber3, attacker))
es.tell(attacker, '#multi', '#greenYou have dealt #lightgreen%s #greendamage to #lightgreen%s'%(randomnumber, playerlib.getPlayer(userid).attributes['name']))
else:
if randomnumber2 > 0:
es.server.queuecmd('damage %s %s 32 %s'%(userid, randomnumber3, attacker))
es.tell(attacker, '#multi', '#greenYou have dealt #lightgreen%s #greendamage to #lightgreen%s'%(randomnumber2, playerlib.getPlayer(userid).attributes['name']))
else:
es.server.queuecmd('damage %s %s 32 %s'%(userid, randomnumber3, attacker))
es.tell(attacker, '#multi', '#greenYou have dealt #lightgreen%s #greendamage to #lightgreen%s'%(randomnumber3, playerlib.getPlayer(userid).attributes['name']))
used in a script I had, it uses esteffect, but could be converted if anyone wanted
def nearcoord(self, xorigin, yorigin, zorigin, xrange, yrange, zrange, block, team, initiator):
for userid in playerlib.getUseridList(team):
loc = es.getplayerlocation(userid)
if abs(loc[0] - xorigin) <= xrange and abs(loc[1] - yorigin) <= yrange and abs(loc[2] - zorigin) <= zrange:
block(userid, initiator)
def lightning(self, xorigin, yorigin, zorigin, lightningrange, lightningtime, attacker, team):
loc = (xorigin, yorigin, zorigin)
effecttime = 0
effectloop(loc, lightningtime, lightningrange, attacker, effecttime, team)
def effectloop(loc, lightningtime, lightningrange, userid, effecttime, team):
if effecttime <= lightningtime:
random1 = random.randint(lightningrange * -1, lightningrange)
random2 = random.randint(lightningrange * -1, lightningrange)
es.server.queuecmd('esteffect 3 #all 0 sprites/lgtning.vmt %s %s %s %s %s %s 1 10 20 40 250 255 255'%(loc[0] + random1, loc[1] + random2, loc[2], loc[0] + random1, loc[1] + random2, loc[2] + 120))
effecttime += 0.03
commands().nearcoord(loc[0] + random1, loc[1] + random2, loc[2], 45, 45, 45, lightningdamage, team, userid)
gamethread.delayedname(0.03, 'effect%s'&#xus;erid, effectloop, args=(loc, lightningtime, lightningrange, userid, effecttime, team))
def lightningdamage(userid, attacker):
randomnumber = (random.randint(1, 6) * random.randint(1, 6)) - random.randint(1, 10)
randomnumber2 = (random.randint(1, 7) * random.randint(1, 7)) - random.randint(1, 10)
randomnumber3 = (random.randint(1, 7) * random.randint(1, 7)) - random.randint(1, 10)
if randomnumber > 0:
es.server.queuecmd('damage %s %s 32 %s'%(userid, randomnumber3, attacker))
es.tell(attacker, '#multi', '#greenYou have dealt #lightgreen%s #greendamage to #lightgreen%s'%(randomnumber, playerlib.getPlayer(userid).attributes['name']))
else:
if randomnumber2 > 0:
es.server.queuecmd('damage %s %s 32 %s'%(userid, randomnumber3, attacker))
es.tell(attacker, '#multi', '#greenYou have dealt #lightgreen%s #greendamage to #lightgreen%s'%(randomnumber2, playerlib.getPlayer(userid).attributes['name']))
else:
es.server.queuecmd('damage %s %s 32 %s'%(userid, randomnumber3, attacker))
es.tell(attacker, '#multi', '#greenYou have dealt #lightgreen%s #greendamage to #lightgreen%s'%(randomnumber3, playerlib.getPlayer(userid).attributes['name']))
used in a script I had, it uses esteffect, but could be converted if anyone wanted




bonbon posted on 2008-04-10 20:25:50