[HL2:DM] amount of Health to give per broken Prop

A place for requesting new Source.Python plugins to be made for your server.

Please request only one plugin per thread.
User avatar
Painkiller
Senior Member
Posts: 726
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

[HL2:DM] amount of Health to give per broken Prop

Postby Painkiller » Mon Apr 13, 2020 9:04 am

Hello SourcePython Team and Community,

could somebody turn that into SP for me?


Syntax: Select all

block load
{
es_xset orb_health "2" "amount of Health to give per broken Prop"
es_xset orb_rand_hp "1" "give a random amount of hp (1/0)"
es_xset orb_max_hp "5" "max amount of random hp to give per broken prop"
es_xset orb_model_t "effects/redflare.vmt" "Model of effect for Terrorists"
es_xset orb_model_ct "effects/blueflare1.vmt" "Model of effect for Counter Terrorists"
es_xset orb_hight "350" "hight of effect"
es_xset orb_count "5" "effect count"
es_xset orb_speed "50" "speed of effect"
es_xset orb_hud "1" "send a hud message to the player saying they gained HP"
es_xset orb_var 0
es_xset orb_x 0
es_xset orb_y 0
es_xset orb_z 0
es_xset orb_vec 0
es_xset orb_version "2.0 deathmatch by RocKs"
es_xmakepublic orb_version
}

event break_prop
{
es playerget viewcoord event_var(userid) orb_x orb_y orb_z
es_createvectorstring orb_vec server_var(orb_x) server_var(orb_y) server_var(orb_z)
if (event_var(es_userteam) = 2) then es est_effect_14 #a 0 server_var(orb_model_t) server_var(orb_vec) server_var(orb_vec) server_var(orb_hight) server_var(orb_count) server_var(orb_speed)
if (event_var(es_userteam) = 3) then es est_effect_14 #a 0 server_var(orb_model_ct) server_var(orb_vec) server_var(orb_vec) server_var(orb_hight) server_var(orb_count) server_var(orb_speed)
if (event_var(es_userteam) = 0) then es est_effect_14 #a 0 server_var(orb_model_ct) server_var(orb_vec) server_var(orb_vec) server_var(orb_hight) server_var(orb_count) server_var(orb_speed)
if (server_var(orb_rand_hp) = 0) do
{
es playerset healthadd event_var(userid) server_var(orb_health)
if (server_var(orb_hud) = 1) then es_tell event_var(userid) #multi #lightgreen You Gained #green server_var(orb_health) #lightgreenExtra HP.
}
if (server_var(orb_rand_hp) != 0) do
{
es_rand orb_var 1 server_var(orb_max_hp)
es playerset healthadd event_var(userid) server_var(orb_var)
if (server_var(orb_hud) = 1) then es_tell event_var(userid) #multi #lightgreen You Gained #green server_var(orb_var) #lightgreenExtra HP.
}
}


Thanks in Advance.
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [HL2:DM] amount of Health to give per broken Prop

Postby VinciT » Tue Apr 14, 2020 3:54 am

Here you go mate:

Syntax: Select all

# ../prop_orbs/prop_orbs.py

# Python
import random

# Source.Python
from effects.base import TempEntity
from engines.precache import Model
from entities.entity import BaseEntity
from events import Event
from filters.recipients import RecipientFilter
from messages import SayText2
from players.dictionary import PlayerDictionary


# Amount of health gained from breaking a prop.
HEALTH = 2

# Should the amount be random? (0 - no, 1 - yes)
RANDOM = 1

# Maximum amount of health that can be gained from a prop.
# (this requires 'RANDOM' to be enabled)
MAX_HEALTH = 5

# How far up do the orbs go before they get removed?
HEIGHT = 350

# Number of orbs that are spawned after breaking a prop.
COUNT = 5

# Add more orbs based on the size of the prop? (0 - no, 1 - yes)
DYNAMIC_COUNT = 1

# Horizontal speed of the orbs.
SPEED = 50

# Notify the player in chat when they receive extra health.
NOTIFICATION = 1

# Sprites for the effect, based on player's team.
MODEL = {
# Players in free for all. (mp_teamplay 0)
0: Model('effects/yellowflare.vmt'),
# Combine.
2: Model('effects/blueflare1.vmt'),
# Rebels.
3: Model('effects/redflare.vmt')
}

# Hex colors used for the chat notification.
COLOR1 = '\x0780ff80' # Lightgreen
COLOR2 = '\x0700ff00' # Green


player_instances = PlayerDictionary()


@Event('break_prop')
def break_prop(event):
try:
player = player_instances.from_userid(event['userid'])
except ValueError:
# Invalid userid.
return

base_entity = BaseEntity(event['entindex'])
health = random.randint(1, MAX_HEALTH) if RANDOM else HEALTH
player.health += health

if NOTIFICATION:
SayText2(
f'{COLOR1}You gained {COLOR2}{health}{COLOR1} extra HP.'
).send(player.index)

origin = base_entity.origin
# Get the bounding box of the prop.
mins = base_entity.get_datamap_property_vector('m_Collision.m_vecMins')
maxs = base_entity.get_datamap_property_vector('m_Collision.m_vecMaxs')
# Get 18% of the distance between the farthest points of the bounding box.
extra_count = int(mins.get_distance(maxs) * 0.18)

create_bubbles(
model=MODEL[player.team],
height=HEIGHT,
speed=SPEED,
count=COUNT + extra_count if DYNAMIC_COUNT else 0,
mins=origin + mins,
maxs=origin + maxs
)


def create_bubbles(model, height, speed, count, mins, **kwargs):
"""Creates bubbles within the specified points (mins and maxs).

Args:
model (Model): Appearance of the bubbles.
height (float): How far do the bubbles travel upwards before they
are no longer rendered?
speed (float): Horizontal speed of the bubbles.
count (int): Number of bubbles that spawn.
mins (Vector): Origin of the effect.
**kwargs: Additional attributes.
"""
bubbles = TempEntity('Bubbles')
bubbles.model = model
bubbles.height = height
bubbles.speed = speed
bubbles.count = count
bubbles.mins = mins
# If specified, bubbles will spawn within the box defined by 'mins' and
# 'maxs'. Otherwise, they will spawn from a single point.
bubbles.maxs = kwargs.get('maxs', mins)
# Send the TempEntity to everyone if 'recipients' weren't specified.
bubbles.create(kwargs.get('recipients', RecipientFilter()))

I've added another parameter which adds more bubbles/orbs based on the size of the prop.
ImageImageImageImageImage
User avatar
Painkiller
Senior Member
Posts: 726
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

Re: [HL2:DM] amount of Health to give per broken Prop

Postby Painkiller » Tue Apr 14, 2020 2:42 pm

Works good thanks.

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 46 guests