Thread: [Solved] Spawn prop_physics
View Single Post
Sreaper
髪を用心
Join Date: Nov 2009
Old 07-16-2022 , 15:54   Re: Spawn prop_physics
Reply With Quote #3

Quote:
Originally Posted by 3ipKa View Post
Ok, I've tried code given in link, but nothing, model doesn't spawn.

Spoiler


I've tried different properties. I mean DispatchKeyValue and SetEntProp with solid type, collision group properties, tried MOVETYPE_VPHYSICS, different spawnflags, tried swapping keys (teleport first than DispatchSpawn).
My goal is to spawn model with physics, I could use another one, but pipebomb fits my needs excellent. It shouldn't be pickable.

Code:
#include <sdktools>

#define PIPE_MODEL	"models/props_c17/oildrum001_explosive.mdl"

public void OnPluginStart()
{
	RegConsoleCmd("sm_spawnphy", spanwCMD);
}

public void OnMapStart()
{
	PrecacheModel( "models/props_c17/oildrum001_explosive.mdl", true );
}

public Action spanwCMD(int client,int args)
{
	float SpawnPosition[3], SpawnAngle[3];
	GetClientAbsOrigin( client, SpawnPosition );
	SpawnPosition[2] += 20; SpawnAngle[0] = 90.0;
	int phymdl = CreateEntityByName("prop_physics");
	if(IsValidEdict(phymdl))
	{		
		PrintToChatAll("phymdl is valid");// fired well
		DispatchKeyValue(phymdl, "model", PIPE_MODEL);
    
		TeleportEntity(phymdl, SpawnPosition, SpawnAngle, NULL_VECTOR);
		DispatchSpawn(phymdl);
        
		DispatchKeyValue(phymdl, "StartDisabled", "false");
		DispatchKeyValue(phymdl, "Solid", "6");
			
		AcceptEntityInput(phymdl, "EnableCollision"); 
		AcceptEntityInput(phymdl, "TurnOn", phymdl, phymdl, 0);
			
		SetEntityMoveType(phymdl, MOVETYPE_VPHYSICS);
		SetEntProp(phymdl, Prop_Data, "m_nSolidType", 6);
		SetEntProp(phymdl, Prop_Data, "m_CollisionGroup", 0);
		SetEntProp(phymdl, Prop_Data, "m_takedamage", 2);

	}
	return Plugin_Handled;
}
This seems to work as intended.

Last edited by Sreaper; 07-16-2022 at 15:55.
Sreaper is offline