PDA

View Full Version : Spawning custom weapons with trigger_createentity doesn't work properly.



Nero
08-05-2016, 05:04 AM
I have a part in my map where I need a weapon to spawn after a while, so I'm using trigger_createentity to spawn a weapon I made.
However, when picking it up it's like the weapon does not have a weapon_name.txt to define the UI sprites. And it won't fire.

But if I spawn it/give it via console commands, it works normally.

Solokiller
08-05-2016, 05:26 AM
Set developer to 1 or higher, set sv_report_unknown_entities to 1, set as_log_level to 2 or higher.

Is there any output in the console reporting problems of any kind?

What keyvalues are you setting in the createentity entity?

Nero
08-05-2016, 10:17 AM
I always have developer and as_log_level @ 2, but that is a new one :o
I'll check once I get home~
No keyvalues, I'm just setting what item to spawn :o

Nero
08-05-2016, 12:46 PM
Aight, I noticed I had forgotten to remove two includes which gives "WARNING: Failed to add include file" but the script worked anyway.

m_rgAmmo isn't being used in the script with the left-over includes.

After picking up the weapon, I get "WARNING: CBasePlayer::m_rgAmmo: index is invalid!"
Dropping the weapon causes an invisible weapon to be dropped.


edit: Keyvalues set:
targetname, m_iszCrtEntChildClass, and m_iszCrtEntChildName

Solokiller
08-05-2016, 01:59 PM
This is a problem that can only be solved by a programmer. OnScriptClassReady isn't being called for the weapon since trigger_createentity doesn't use DispatchSpawn. As a workaround, you can spawn it in a script. Calling g_EntityFuncs.DispatchSpawn on the weapon after creating it should fix the problems you've been having.

Nero
08-05-2016, 02:41 PM
Aight, thanks! :3

Nero
08-05-2016, 03:06 PM
WARNING: trigger_script (targetname: nero_spawn_bosskiller): Function with signature 'void SpawnWeapon(CBaseEntity@, CBaseEntity@, USE_TYPE, float)' does not exist!

I realize I need to enter all those inputs (I have void SpawnWeapon() atm) but I'd like to know what their names are so I know what they do :3

edit: UseFunction(CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float flValue)

Is this the one? :o

Nero
08-05-2016, 03:19 PM
Aight, that works!
But the weapon isn't getting deleted :S
I'm killtargetting the weapon and ammo with a trigger_relay

When the weapon respawns, I think the targetname is reset to nothing. Is there an easy way around this? :S
edit: I'll just remove it with AS.

The ammo is getting removed though. o.O

Solokiller
08-05-2016, 04:24 PM
When weapons respawn some keyvalues are copied over. Perhaps the targetname isn't getting copied over?

Nero
08-05-2016, 05:13 PM
Aye, I noticed this when playing around with the displacer and placing info_teleport_destination in game.

So I tried this instead:


void RemoveWeapon( CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float flValue )
{
CBaseEntity@ pEntity1;
CBaseEntity@ pEntity2;

while( ( @pEntity1 = g_EntityFuncs.FindEntityInSphere( pEntity1, Vector(4800, 7360, -704), 16384, "weapon_scientist", "classname" ) ) !is null )
{
g_EntityFuncs.Remove( pEntity1 );
}

while( ( @pEntity2 = g_EntityFuncs.FindEntityInSphere( pEntity2, Vector(4800, 7360, -704), 16384, "ammo_scientist", "classname" ) ) !is null )
{
g_EntityFuncs.Remove( pEntity2 );
}
}


This doesn't work if the items are in the process of waiting to respawn. :[
Any way to fix dis? :S