[HL2:DM] SP Modelchooser

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Painkiller
Senior Member
Posts: 490
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany
Contact:

[HL2:DM] SP Modelchooser

Postby Painkiller » Sun Jun 02, 2019 7:10 am

I noted that for some time now my modelchooser hasn't been working properly.

Unfortunately, there are no errors output.
Probably it's just outdated and someone could update it.

Many thanks in advance




Syntax: Select all

from players.entity import Player
from players.helpers import index_from_playerinfo
from players.helpers import index_from_userid
from players.helpers import playerinfo_from_index

from events import Event

from engines.precache import Model

from menus import PagedMenu
from menus import PagedOption

from commands.say import SayCommand

from supermod import functions
from supermod.modules import admin
from supermod.cfg.modelchooser import models
from supermod.cfg.modelchooser import admin_models
import core
core.console_message("\n[Supermod] Modelchooser loaded!")
player_models = {}

@Event('player_spawn')
def player_spawn(game_event):
userid = game_event.get_int('userid')
index = index_from_userid(userid)
player = Player(index)
if player.steamid not in player_models:
if admin.isadmin(player.steamid):
if 'Admin Rebell' in admin_models:
player_models[player.steamid] = 'Admin Rebell'
if player.steamid in player_models:
model = player_models[player.steamid]
if model in models:
player.set_model(Model(models[model]))
elif model in admin_models:
player.set_model(Model(admin_models[model]))

@SayCommand('!model')
def model_command(command, index, teamonly):
model_menu(index)

def model_menu(index):
player = Player(index)
m = PagedMenu(title='Choose a Model')
if admin.isadmin(player.steamid):
for model in sorted(admin_models):
m.append(PagedOption(model, model))
for model in sorted(models):
m.append(PagedOption(model, model))
m.select_callback = model_callback
m.send(index)

def model_callback(menu, index, option):
player = Player(index)
player_models[player.steamid] = option.value
if option.value in models:
player.set_model(Model(models[option.value]))
elif option.value in admin_models:
player.set_model(Model(admin_models[option.value]))
functions.tell(index, 'You have set your model to: %s'%option.value)






The same when replacing model.
It causes exchange of barrels, medics suit etc.

Syntax: Select all

from listeners import OnEntityCreated
from listeners import OnLevelInit
from entities.entity import Entity
import core
from engines.precache import Model
from supermod.cfg.modelreplacement import modelreplacement
from listeners.tick import Delay
from filters.entities import EntityIter

global map_start
map_start = 1

@OnLevelInit
def level_init(map_name):
global map_start
map_start = 1
Delay(2.0, set_start, (0,))

def set_start(value):
global map_start
map_start = value
for entity in EntityIter():
if entity.classname in modelreplacement:
Delay(0.1, set_entity, (entity,))


@OnEntityCreated
def on_entity_created(base_entity):
global map_start
if map_start == 0:
try:
entity = Entity(base_entity.index)
except:
return
if entity != None:
if entity.classname in modelreplacement:
Delay(0.1, set_entity, (entity,))



def set_entity(entity):
if entity.model.path in modelreplacement[entity.classname]:
if modelreplacement[entity.classname][entity.model.path] != "":
change_model = Model(modelreplacement[entity.classname][entity.model.path])
entity.model = change_model

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 7 guests