CreateEntity function #6
Replies: 6 comments 2 replies
-
|
Can you give examples of what entities and properties you'd want to spawn and where using ForceSpawn from templates isn't suitable |
Beta Was this translation helpful? Give feedback.
-
|
Some examples of entities created from script: Creating Hud Hints: const hint = Instance.CreateEntity("env_hudhint",{targetname :"player_timer", message:"Time Left: 0:10"});
Instance.EntFireAtTarget(hint, "Display");
// after some time
hint.Kill();Creating Particles //lets assume we have 30 different particles for each day of the spooky season and it would be very tedious to set up templates for in hammer
const now = new Date();
const day = now.getDay();
const pcf = Instance.CreateEntity("info_particle_system", {targetname: "festivedeco_${day}", effect_name: "particles/hud/spooky/spooky_day_${i}.vpcf", start_active: false});
Instance.EntFireAtTarget(pcf , "Start");
// after some time
Instance.EntFireAtTarget(pcf , "destroyimmediately");Creating Triggers (currently not possible with ent_create mayhaps a separate method similar to old Lua api's const trigger = Instance.CreateEntity("trigger_multiple", {targetname: "some_trigger", min: {0, 0, 0}, max {100, 100, 100});
Instance.ConnectOutput(trigger , "OnStartTouch", (inputData) => {
//something
}); |
Beta Was this translation helpful? Give feedback.
-
|
The shortcoming of point_template is that you're stuck with whatever templates and keyvalues that have been compiled in the map. Allowing you to spawn anything whenever with whatever keyvalues makes things a whole lot more versatile. Girlglock's examples should be more than enough for its potential. Trigger-creation is a huge plus too. See #23 |
Beta Was this translation helpful? Give feedback.
-
|
Another example use-case of a rope-physics lantern, created with the old lua API a few years ago. The entity-spawning would look something like this in JS, using a lot of different keyvalues: const model = Instance.CreateEntity("prop_physics_override",{
model : "models/props/de_dust/hr_dust/dust_lights/dust_ornate_lantern_03.vmdl",
disableshadows : 1,
targetname : "slave_phys",
spawnflags : 4,
});
const light = Instance.CreateEntity("light_omni2",{
targetname : "ropelantern_child",
parentname : "slave_phys",
color : "255 161 0 255",
brightness_lumens : 5000,
brightnessscale : 2.00,
directlight : 2,
skirt : 1.0,
range : 1024,
enabled : 1,
outer_angle : 180,
inner_angle : 180,
});
const ropetarget = Instance.CreateEntity("light_omni2",{
targetname : "slave_ropetarget",
parentname : "slave_phys",
color : "255 161 0 255",
directlight : 2,
castshadows : 0,
brightness_lumens : 100,
skirt : 1,
range : 300,
enabled : 1,
outer_angle : 180,
inner_angle : 180,
});
const rope = Instance.CreateEntity("phys_lengthconstraint",{
targetname : "ropelantern_child",
attach1 : "slave_phys",
spawnflags : 0,
forcelimit : 99999,
torquelimit : 99999,
enablecollision : 1,
attachpoint : "" + rope_pos.x + " " + rope_pos.y + " " + rope_pos.z,
});
const visualrope = Instance.CreateEntity("env_beam",{
targetname : "slave_beam",
spawnflags : 1,
renderamt : 255,
rendercolor : "20 20 20 255",
life : 0,
BoltWidth : 1,
texture : "materials/sprites/laserbeam.vmat",
LightningStart : "slave_beam",
LightningEnd : "slave_ropetarget",
}); |
Beta Was this translation helpful? Give feedback.
-
|
Playable chess in CS:GO, back in 2021. This did use templates, since CS:GO didn't properly dispatch entities via its The entire chess-game is scalable, so you can create large or small boards where everything else matches up. Including the triggers in red outline. #23 is relevant for this. It was controlled with WASD+LMB using the game_ui entity which is now gone from CS2. #16 is relevant for this. chess_csgo_2021.mp4 |
Beta Was this translation helpful? Give feedback.
-
|
I think the previous rope-physics lantern show perfectly why creating entities dynamically without a point_template is very useful. Here are two more examples: |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Creating any entity by classname, without the need for pre-compiled templates.
Also allowing to set initial keyvalues.
Beta Was this translation helpful? Give feedback.
All reactions