No max function...?

Please post any questions about developing your plugin here. Please use the search function before posting!
arawra
Senior Member
Posts: 149
Joined: Fri Jun 21, 2013 6:51 am

No max function...?

Postby arawra » Wed May 30, 2018 6:57 am

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\plugins\rpgo\rpgo.py", line 619, in _pre_take_damage
    lifesteal = max(1, damage * (attacker.getLevel() * .01))

UnboundLocalError: local variable 'max' referenced before assignment


Last section under attacker.getClass() == 'Warlock':

Syntax: Select all

@EntityPreHook(EntityCondition.is_bot_player, 'on_take_damage')
@EntityPreHook(EntityCondition.is_human_player, 'on_take_damage')
def _pre_take_damage(stack_data):
take_damage_info = make_object(TakeDamageInfo, stack_data[1])
attacker = Entity(take_damage_info.attacker)

if attacker.classname == 'player':
weapon = Weapon(take_damage_info.weapon)
if weapon.classname != 'worldspawn':


victim = make_object(Player, stack_data[0])
victim = rpgPlayer(victim.index)
attacker = rpgPlayer(attacker.index)


damage = take_damage_info.damage
p1 = victim.origin
p2 = attacker.origin
distance = math.sqrt(abs(p2[0]**2 - p1[0]**2) + abs(p2[1]**2 - p1[1]**2) + abs(p2[2]**2 - p1[2]**2))

# Only allow knife damage
#if weapon.classname != 'weapon_knife':
# return

# Increase the damage
#take_damage_info.damage += 100

# Change the type of damage
#take_damage_info.type = DamageTypes.BURN

# Add a damage type
#take_damage_info |= DamageTypes.POISON

if attacker.getClass() == 'Warrior':
take_damage_info.damage += damage * (CLASS_DAMAGE['Warrior bonus'] * attacker.getLevel())
if attacker.data.baseSpeed > 1.0:
if distance < CLASS_DAMAGE['Warrior charge distance']:
take_damage_info.damage += damage * CLASS_DAMAGE['Warrior charge']

if attacker.getClass() == 'Rogue':
if (abs(victim.get_view_angle()[1] - attacker.get_view_angle()[1]) < 45 or
abs((360- victim.get_view_angle()[1]) - attacker.get_view_angle()[1]) < 45 or
abs(victim.get_view_angle()[1] - (360 - attacker.get_view_angle()[1])) < 45):
if distance < CLASS_DAMAGE['Rogue sneak attack distance']:
take_damage_info.damage += damage * (CLASS_DAMAGE['Rogue sneak attack'] * attacker.getLevel())

if attacker.getClass() == 'Druid':
speed = attacker.velocity
if abs(speed[0]) > 300 or abs(speed[1]) > 300 or abs(speed[2]) > 300:
take_damage_info.damage += damage * (CLASS_DAMAGE['Druid pounce damage'] + float(attacker.getLevel() / 10))

if attacker.getClass() == 'Mage':
max = 100 * attacker.getLevel()
if(random.randint(1,100+1)) > 90:
for player in PlayerIter():
if not player.playerinfo.is_dead():
if player.playerinfo.team != attacker.playerinfo.team:
distance = player.origin - victim.origin
if abs(distance[0]) < max and abs(distance[1]) < max and abs(distance[2]) < max:
burnTimer = Repeat(burn, args=(attacker.index, player.index))
timers.append(burnTimer)
burnTimer.start(.1, attacker.getLevel()-1)
player.ignite_lifetime(.1)

if attacker.getClass() == 'Warlock':
lifesteal = max(1, damage * (attacker.getLevel() * .01))
message(lifesteal)
if weapon.classname in ['weapon_m3', 'weapon_xm1014']:
if random.randint(1,100) in range(1,13+1):
attacker.health += lifesteal
else:
attacker.health += lifesteal
User avatar
L'In20Cible
Project Leader
Posts: 1086
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: No max function...?

Postby L'In20Cible » Wed May 30, 2018 7:19 am

You are redefining it on that line:

Syntax: Select all

max = 100 * attacker.getLevel()

Use a different name for your variable.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 3 guests