Help for ward skill

Please post any questions about developing your plugin here. Please use the search function before posting!
existenz
Member
Posts: 39
Joined: Thu Feb 09, 2017 3:33 pm

Help for ward skill

Postby existenz » Wed Mar 08, 2017 10:00 am

Hey everyone !

I need your help on an idea of skill for warcraft mod.

How it's suppose to work :
Put an area on the ground delimited by a laser ring. If an enemy enters in this ring, he take some damage per second.

For the moment i have the ring one the floor but the damage area follow the player who create the area.
I want that damage area stay in the ring.

This is my code, you can modify it without the system of hero coding i can rewrite it after :

Syntax: Select all

from effects import TempEntity
from engines.precache import Model
from entities.entity import Entity
from filters.players import PlayerIter
from listeners.tick import Delay, Repeat, RepeatStatus
from messages import SayText2

from . import Hero, Skill, events, clientcommands
from ..cooldown import Cooldown

class Test(Hero):
'Test'
name = 'Test'

@Test.skill
class Test_Utlti(Skill):
name = 'Test Utlti'
description = 'Lightbomb.'
max_level = 1

_laser = Model('sprites/laserbeam.vmt')
_on_cooldown_message = 'Light Bomb is on cooldown for {} seconds.'

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._repeater = Repeat(self._to_repeat)
self._is_on = False

@property
def duration(self):
return 30

@property
def tick_time(self):
return 0.5

@property
def damage(self):
return 20

@property
def radius(self):
return 750

def _to_repeat(self):
if not self._is_on:
return
player = self._player

# Create a list of possible enemy victims.
# targets = [victim for victim in PlayerIter(is_filters=['alive', 't' if player.team == 3 else 'ct']) if player.origin.get_distance(victim.origin) <= self.radius]

for victim in PlayerIter(is_filters=['alive', 't' if player.team == 3 else 'ct']):
if victim.origin.get_distance(player.origin) <= self.radius:
victim.take_damage(self.damage, attacker_index=player.index, weapon_index=next(player.weapon_indexes()))

def _effect(self):
red = 0 if self._player.team == 3 else 255
blue = 255 if self._player.team == 3 else 0

self._effect = TempEntity('BeamRingPoint', center=self._player.origin, start_radius=self.radius,
end_radius=self.radius+1, model_index=self._laser.index, halo_index=self._laser.index,
life_time=self.duration, amplitude=0, red=red, green=0, blue=blue, alpha=255, flags=0,
start_width=10, end_width=10)
self._effect.create()

@events('round_start')
def _on_round_start_prepare_cooldown(self, **kwargs):
self._round_started = True

@events('round_end')
def _on_round_end(self, **kwargs):
self._round_started = False
self._repeater.stop()

@events('player_spawn')
def _on_spawn_start_repeat(self, **kwargs):
self.cooldown = Cooldown(10)
if self._repeater.status == RepeatStatus.RUNNING:
return
self._repeater.start(self.tick_time)

@clientcommands('ultimate')
def _on_player_use_ultimate(self, player, **kwargs):
# if self.cooldown.is_over or self._round_started == False:
# SayText2(self._on_cooldown_message.format(self.cooldown.remaining)).send(player.index)
# return

self._is_on = True
self._player = player
self._effect()
Delay(self.duration, self.__setattr__, ('_is_on', False))
self.cooldown = Cooldown(60)


Sincerly Existenz.
User avatar
satoon101
Project Leader
Posts: 2288
Joined: Sat Jul 07, 2012 1:59 am

Re: Help for ward skill

Postby satoon101 » Sat Mar 11, 2017 5:37 pm

I would recommend changing _is_on to _location and defaulting it to None. Then, in the repeated method, return if the _location is None otherwise use that as the starting origin in your if statement in that method. When the ultimate is used, store the player's location as _location. So, something like:

Syntax: Select all

from effects import TempEntity
from engines.precache import Model
from entities.entity import Entity
from filters.players import PlayerIter
from listeners.tick import Delay, Repeat, RepeatStatus
from messages import SayText2

from . import Hero, Skill, events, clientcommands
from ..cooldown import Cooldown

class Test(Hero):
'Test'
name = 'Test'

@Test.skill
class Test_Utlti(Skill):
name = 'Test Utlti'
description = 'Lightbomb.'
max_level = 1

_laser = Model('sprites/laserbeam.vmt')
_on_cooldown_message = 'Light Bomb is on cooldown for {} seconds.'

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._repeater = Repeat(self._to_repeat)
self._location = None

@property
def duration(self):
return 30

@property
def tick_time(self):
return 0.5

@property
def damage(self):
return 20

@property
def radius(self):
return 750

def _to_repeat(self):
if self._location is None:
return
player = self._player

# Create a list of possible enemy victims.
# targets = [victim for victim in PlayerIter(is_filters=['alive', 't' if player.team == 3 else 'ct']) if player.origin.get_distance(victim.origin) <= self.radius]

for victim in PlayerIter(is_filters=['alive', 't' if player.team == 3 else 'ct']):
if victim.origin.get_distance(self._location) <= self.radius:
victim.take_damage(self.damage, attacker_index=player.index, weapon_index=next(player.weapon_indexes()))

def _effect(self):
red = 0 if self._player.team == 3 else 255
blue = 255 if self._player.team == 3 else 0

self._effect = TempEntity('BeamRingPoint', center=self._player.origin, start_radius=self.radius,
end_radius=self.radius+1, model_index=self._laser.index, halo_index=self._laser.index,
life_time=self.duration, amplitude=0, red=red, green=0, blue=blue, alpha=255, flags=0,
start_width=10, end_width=10)
self._effect.create()

@events('round_start')
def _on_round_start_prepare_cooldown(self, **kwargs):
self._round_started = True

@events('round_end')
def _on_round_end(self, **kwargs):
self._round_started = False
self._repeater.stop()

@events('player_spawn')
def _on_spawn_start_repeat(self, **kwargs):
self.cooldown = Cooldown(10)
if self._repeater.status == RepeatStatus.RUNNING:
return
self._repeater.start(self.tick_time)

@clientcommands('ultimate')
def _on_player_use_ultimate(self, player, **kwargs):
# if self.cooldown.is_over or self._round_started == False:
# SayText2(self._on_cooldown_message.format(self.cooldown.remaining)).send(player.index)
# return

self._player = player
self._location = self._player.origin
self._effect()
Delay(self.duration, self.__setattr__, ('_location', None))
self.cooldown = Cooldown(60)
Image
existenz
Member
Posts: 39
Joined: Thu Feb 09, 2017 3:33 pm

Re: Help for ward skill

Postby existenz » Sun Mar 12, 2017 12:40 pm

Thanks for your answer :)
I will try.
existenz
Member
Posts: 39
Joined: Thu Feb 09, 2017 3:33 pm

Re: Help for ward skill

Postby existenz » Sun Mar 12, 2017 2:18 pm

It works fine. Thanks :)

If i want be able to manage more wards i must use a list for the repeater and location ?
User avatar
satoon101
Project Leader
Posts: 2288
Joined: Sat Jul 07, 2012 1:59 am

Re: Help for ward skill

Postby satoon101 » Sun Mar 12, 2017 3:07 pm

I'm not sure I fully understand the question, but I believe you are asking what to do if the same player activates his ultimate more than once and there is overlap. If that is the case, then yes, you will need to store each of them separately in some sort of container like list.
Image
existenz
Member
Posts: 39
Joined: Thu Feb 09, 2017 3:33 pm

Re: Help for ward skill

Postby existenz » Sun Mar 12, 2017 3:51 pm

Ok. And i want also one player can put for example 5 wards.
I must store all effects and repeaters in list to remove it in end round ?

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 1 guest