3 new classes (Model, Decal, Generic)

Official Announcements about Source.Python.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

3 new classes (Model, Decal, Generic)

Postby satoon101 » Tue Oct 07, 2014 11:09 pm

We're excited to inform you all that there are now 3 new classes at your disposal. The Model, Decal, and Generic classes are used for 2 purposes. First, if you are using a custom file, the classes can automatically add your file to the downloadables table and remove it when your script is unloaded. Second, and the main purpose behind these classes, is that they automatically handle precaching.

Syntax: Select all

from engines.precache import Decal
from engines.precache import Generic
from engines.precache import Model

# Get an instance of each
my_decal = Decal('<path/to/decal>')
my_generic = Generic('<path/to/generic>')
my_model = Model('<path/to/model>')

# Instead of just getting an instance, add it to the downloadables table
my_decal = Decal('<path/to/decal>', True)
my_generic = Generic('<path/to/generic>', True)
my_model = Model('<path/to/model>', True)

# To get the precached index
decal_index = my_decal.index
generic_index = my_generic.index
model_index = my_model.index


As an example of usage (untested):

Syntax: Select all

from engines.precache import Model
from events import Event
from filters.players import PlayerIter

my_model = Model('models/characters/hostage_02.mdl')

@Event
def player_say(game_event):
for player in PlayerIter(return_types='player'):
start_color = player.color
player.get_server_entity().set_model_index(my_model.index)
player.color = start_color



Also, please note that you must use the entire path from the ../<gamename>/ directory. We do not append models/ to the front or the .mdl extension.
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Dec 01, 2014 7:12 pm

I forgot to post an update here when this happened, but we have fixed an issue with these classes where the object does not get precached when using the string value. The classes have been updated to precache on __init__ and again each time the server_spawn event is fired (map change). You still need to use the <object>.index property to get the index of the object.
Image

Return to “News & Announcements”

Who is online

Users browsing this forum: No registered users and 16 guests