AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Spawn prop_physics (https://forums.alliedmods.net/showthread.php?t=338586)

3ipKa 07-14-2022 07:43

Spawn prop_physics
 
Hi guys! What's the propper way to spawn prop_physics(override/multiplayer)? Now my goal is just spawn prop_physics with model i interested in. Model has .phy file but it doesn't spawn at all... I've already tried numerous methods. prop_dynamic works, but without physics and that's not what i need.
Game - l4d2, model - pipebomb, if it's important.

3ipKa 07-16-2022 13:03

Re: Spawn prop_physics
 
Ok, I've tried code given in link, but nothing, model doesn't spawn.

Code:

#define PIPE_MODEL        "models/w_models/weapons/w_eq_pipebomb.mdl"

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

public void OnMapStart()
{
        PrecacheModel( "models/w_models/weapons/w_eq_pipebomb.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");//prop_physics_multiplayer - no effect too
        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");
                       
                // DispatchKeyValue(phymdl, "spawnflags", "8");
                // SetEntProp(phymdl, Prop_Data, "m_CollisionGroup", 5);
                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", 2);
                SetEntProp(phymdl, Prop_Data, "m_takedamage", 0); 
        }
        return Plugin_Handled;
}

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.

Sreaper 07-16-2022 15:54

Re: Spawn prop_physics
 
Quote:

Originally Posted by 3ipKa (Post 2783916)
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.

3ipKa 07-16-2022 16:49

Re: Spawn prop_physics
 
Unfortunately but it doesn't work. Maybe on my end only...? Tried different models...

Sreaper 07-16-2022 17:37

Re: Spawn prop_physics
 
Quote:

Originally Posted by 3ipKa (Post 2783929)
Unfortunately but it doesn't work. Maybe on my end only...? Tried different models...

I used the command and spawned an explosive barrel on TF2 using it. I was able to walk into the barrel to move it as well as shoot the barrel causing it to explode. If you have Silvers dev cmds plugin check the default values of a regular prop physics in L4d to see if any values are different. Especially the m_CollisionGroup

3ipKa 07-17-2022 10:45

Re: Spawn prop_physics
 
I managed to spawn oildrum001.mdl, but not w_eq_pipebomb.mdl...
I don't understant why, it has also .phy file and others... Tried some other models - dont work too.
For burrel i used m_CollisionGroup 1 and m_nSolidType 6 just for test, works fine. IDK is the reason in properties.

Silvers 07-17-2022 11:18

Re: Spawn prop_physics
 
Try prop_physics_override

3ipKa 07-17-2022 11:48

Re: Spawn prop_physics
 
Quote:

Originally Posted by Silvers (Post 2783971)
Try prop_physics_override

It didn't help :(

Silvers 07-17-2022 12:22

Re: Spawn prop_physics
 
PHP Code:

#include <sourcemod>
#include <sdkhooks>
#include <sdktools>

#define MODEL_PIPE    "models/w_models/weapons/w_eq_pipebomb.mdl"

bool g_bLeft4Dead2;

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
EngineVersion test GetEngineVersion();
    if( 
test == Engine_Left4Dead g_bLeft4Dead2 false;
    else if( 
test == Engine_Left4Dead2 g_bLeft4Dead2 true;
    else
    {
        
strcopy(errorerr_max"Plugin only supports Left 4 Dead 1 & 2.");
        return 
APLRes_SilentFailure;
    }
    return 
APLRes_Success;
}

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_pipe"CmdPipeADMFLAG_ROOT);
}

public 
void OnMapStart()
{
    
PrecacheModel(MODEL_PIPE);
}

Action CmdPipe(int clientint args)
{
    
float vPos[3], vAng[3];
    if( 
SetTeleportEndPoint(clientvPos) )
    {
        
int entity CreateEntityByName("weapon_pipe_bomb");

        
vAng[0] = 90.0;
        
vPos[2] += 10;
        
TeleportEntity(entityvPosNULL_VECTORNULL_VECTOR);
        
DispatchSpawn(entity);

        
// Block +USE
        
SDKHook(entitySDKHook_UseOnUse);

        
// Remove glow
        
if( g_bLeft4Dead2 )
        {
            
SetEntProp(entityProp_Send"m_iGlowType"3);
            
SetEntProp(entityProp_Send"m_glowColorOverride"1);
            
SetEntProp(entityProp_Send"m_nGlowRange"0);
        }
    }

    return 
Plugin_Handled;
}

Action OnUse(int entity)
{
    return 
Plugin_Handled;
}

bool SetTeleportEndPoint(int clientfloat vPos[3])
{
    
GetClientEyePosition(clientvPos);
    
float vAng[3];
    
GetClientEyeAngles(clientvAng);

    
Handle trace TR_TraceRayFilterEx(vPosvAngMASK_SHOTRayType_InfiniteExcludeSelf_Filterclient);

    if( 
TR_DidHit(trace) )
    {
        
TR_GetEndPosition(vPostrace);
    }
    else
    {
        
delete trace;
        return 
false;
    }

    
delete trace;
    return 
true;
}

bool ExcludeSelf_Filter(int entityint contentsMaskany client)
{
    if( 
entity == client )
        return 
false;
    return 
true;



3ipKa 07-19-2022 08:07

Re: Spawn prop_physics
 
Thank you Silver! It's a bit hackish in my view, but it does the trick and gives some advantages :) Thank you guys! You're all awesome )


All times are GMT -4. The time now is 21:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.