Drop not removing

All other Source.Python topics and issues.
User avatar
daren adler
Member
Posts: 43
Joined: Sat May 18, 2019 7:42 pm
Contact:

Drop not removing

Postby daren adler » Wed May 22, 2019 6:14 pm

this works but the gift dont go away unless you grab it,,could i get this for the gift to be removed after a time?


Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
# Python
from collections import defaultdict

# Source.Python
from engines.precache import Model
from entities.entity import Entity
from entities.hooks import EntityCondition, EntityPreHook
from events import Event
from filters.weapons import WeaponClassIter
from listeners.tick import Delay
from memory import make_object
from players.entity import Player
from weapons.entity import Weapon
from weapons.manager import weapon_manager


# =============================================================================
# >> CONFIGURATION
# =============================================================================
# Set to the model to use for the dropped pack
pack_model = 'models/fortnite_crafting/fortnite_crafting_materials/moonglow_crystal.mdl'

# Set to the number of seconds before the pack is removed
kill_time = 120

# =============================================================================
# >> END OF CONFIGURATION
# =============================================================================


# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
ini_weapons = weapon_manager.ini['weapons']

# Get the weapons to not store in the pack
skip_weapons = [
weapon.name for weapon in
list(WeaponClassIter('melee')) + list(WeaponClassIter('tool'))
]

# Get the weapons that do not have a clip
ammo_only_weapons = [
weapon.name for weapon in weapon_manager.values() if weapon.clip is None
]

# Get the weapons that have a secondary fire
secondary_ammo_weapons = [
weapon_manager[weapon].name for weapon, values in
ini_weapons.items()
if values.get('secondary_fire_ammoprop') is not None
]

pack_entity = 'weapon_slam'

weapon_packs = defaultdict(dict)


# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('player_death')
def _drop_pack(game_event):
# Loop through the victim's weapons
player = Player.from_userid(game_event['userid'])
player_weapons = {}
for weapon in player.weapons():

# Skip any weapons that should not be stored
if weapon.classname in skip_weapons:
continue

# Store the weapon with its ammo and secondary fire ammo
primary_ammo = weapon.ammo
if weapon.classname not in ammo_only_weapons:
primary_ammo += weapon.clip
secondary_ammo = 0
if weapon.classname in secondary_ammo_weapons:
secondary_ammo = weapon.secondary_fire_ammo
player_weapons[weapon.classname] = {
'ammo': primary_ammo,
'secondary': secondary_ammo,
}

# Were any weapons found on the victim?
if not player_weapons:
return

# Create the pack
entity = Entity.create(pack_entity)
entity.spawn()
entity.world_model_index = Model(pack_model).index
origin = player.origin
origin.z += 15
entity.teleport(origin)
weapon_packs[entity.index] = player_weapons
entity.delay(kill_time, _remove_entity, (entity.index,))


# =============================================================================
# >> ENTITY HOOKS
# =============================================================================
@EntityPreHook(EntityCondition.is_player, 'bump_weapon')
def _touch_pack(stack_data):
entity = make_object(Entity, stack_data[1])

# Is the entity a pack?
if entity.index not in weapon_packs:
return

# Verify the entity is still of the correct type
if entity.classname != pack_entity:
return

# Verify the entity is still of the correct model
if entity.world_model_index != Model(pack_model).index:
return

# Loop through all of the weapons in the pack
player = make_object(Player, stack_data[0])
Delay(0, _give_weapons, (player.userid, entity.index))

# Remove the pack
_remove_entity(entity.index)
return False


# =============================================================================
# >> HELPER FUNCTIONS
# =============================================================================
def _give_weapons(userid, index):
player = Player.from_userid(userid)
player_weapons = [weapon.classname for weapon in player.weapons()]
for weapon, values in weapon_packs.pop(index).items():

# Give the player the weapon if they don't already own one
if weapon not in player_weapons:
weapon_entity = make_object(Weapon, player.give_named_item(weapon))
if weapon in ammo_only_weapons:
weapon_entity.ammo = values['ammo']
else:
value = values['ammo'] - weapon_entity.clip
if value >= 0:
weapon_entity.ammo = value
else:
weapon_entity.clip -= abs(value)
if values['secondary']:
weapon_entity.secondary_fire_ammo = values['secondary']

# Increase the player's ammo if they already own the weapon
else:
weapon_entity = player.get_weapon(weapon)
weapon_entity.ammo = min([
weapon_entity.ammo + values['ammo'],
weapon_manager[weapon].maxammo,
])
if values['secondary']:
value = ini_weapons[weapon_manager[weapon].basename]
weapon_entity.secondary_fire_ammo = min([
weapon_entity.secondary_fire_ammo + values['secondary'],
value['secondary_fire_ammoprop'],
])


def _remove_entity(index):
entity = Entity(index)
if entity.classname == pack_entity:
entity.remove()
Last edited by Ayuto on Thu May 23, 2019 4:11 pm, edited 1 time in total.
Reason: Added missing python code tags
User avatar
daren adler
Member
Posts: 43
Joined: Sat May 18, 2019 7:42 pm
Contact:

Re: Drop not removing

Postby daren adler » Wed May 22, 2019 7:45 pm

OK,,i teasted it again,,and yes it does go away,but it comes right back after it clears away.
User avatar
Ayuto
Project Leader
Posts: 2022
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Drop not removing

Postby Ayuto » Thu May 23, 2019 4:24 pm

Please post the source where you copied this code. There is no need to have it posted multiple times on the forum.
User avatar
daren adler
Member
Posts: 43
Joined: Sat May 18, 2019 7:42 pm
Contact:

Re: Drop not removing

Postby daren adler » Thu May 23, 2019 4:36 pm

OK,,i am confussed i guess,,when i have trouble with a script i got from here,,where do i put where i need help on somthing?
User avatar
Ayuto
Project Leader
Posts: 2022
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Drop not removing

Postby Ayuto » Thu May 23, 2019 4:42 pm

If you have trouble with a script, this is the correct forum.

However, I just want to know where exactly you have found the script here on the forum. Actually, it's already sufficient to post a link to the code. You don't need to copy the code. Ideally, you would even post your question/problem in the same thread, where you have found the code. So, the forum stays organized.
User avatar
daren adler
Member
Posts: 43
Joined: Sat May 18, 2019 7:42 pm
Contact:

Re: Drop not removing

Postby daren adler » Thu May 23, 2019 4:44 pm

Ok

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests