AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Attach Dynamic Light to Model (https://forums.alliedmods.net/showthread.php?t=92893)

SamuraiBarbi 05-21-2009 18:01

Attach Dynamic Light to Model
 
Hello thar! I'm trying to attach a dynamic light to a model so that they light will move around with the model, but it's not attaching to the model when I try setparent. Both entities spawn, but the light just won't attach to the prop I spawned. Can anyone spot what I may be doing incorrectly or give some pointers? Here's my code:

Code:

        new String:target_entityCoord[50];
        Format(target_entityCoord, sizeof(target_entityCoord), "%f %f %f", target_entityCoordX, target_entityCoordY, target_entityCoordZ);

        /**
        * Make the prop
        */
       
        new target_propIndex = CreateEntityByName("prop_physics_override");

        SetEntityModel(target_propIndex, "models/weapons/w_eq_smokegrenade.mdl");
        DispatchKeyValue(target_propIndex, "origin", target_entityCoord);
        DispatchSpawn(target_propIndex);

        SetEntProp(target_propIndex, Prop_Data, "m_CollisionGroup", 2);

        SetEntityMoveType(target_propIndex, MOVETYPE_VPHYSICS);
        SetEntProp(target_propIndex, Prop_Data, "m_nSolidType", 6);
        SetEntProp(target_propIndex, Prop_Data, "m_takedamage", 0);

        /**
        * Make the flare
        */
       
        new Float:brightness = 6.0;

        new String:brightness_s[20];
        FloatToString(brightness, brightness_s, sizeof(brightness_s));


        new target_flareIndex = CreateEntityByName("light_dynamic");
        AcceptEntityInput(target_flareIndex, "SetParent", target_propIndex, target_flareIndex, 0);
       


        DispatchKeyValue(target_flareIndex, "_light", "245 0 0");
        DispatchKeyValue(target_flareIndex, "origin", target_entityCoord);
        DispatchKeyValue(target_flareIndex, "brightness", brightness_s);
        DispatchKeyValue(target_flareIndex, "distance", "256");
        DispatchKeyValue(target_flareIndex, "style", "6");
        DispatchSpawn(target_flareIndex);


SamuraiBarbi 05-22-2009 13:02

Re: Attach Dynamic Light to Model
 
I also tried to dispatch key value parentname on the light and that didn't seem to do anything either.

strontiumdog 05-22-2009 14:25

Re: Attach Dynamic Light to Model
 
Give the smoke grenade a targetname.

e.g
Code:

new String:targ[64];
Format(targ, sizeof(targ), "nade%i", target_propIndex);
DispatchKeyValue(target_propIndex, "targetname", targ);

Then you need to attach it to that targetname

Code:

AcceptEntityInput(target_flareIndex, "SetParent", targ);

SamuraiBarbi 05-22-2009 16:09

Re: Attach Dynamic Light to Model
 
Quote:

Originally Posted by strontiumdog (Post 832558)
Give the smoke grenade a targetname.

e.g
Code:

new String:targ[64];
Format(targ, sizeof(targ), "nade%i", target_propIndex);
DispatchKeyValue(target_propIndex, "targetname", targ);

Then you need to attach it to that targetname

Code:

AcceptEntityInput(target_flareIndex, "SetParent", targ);

That should have worked but when I add that the light still isn't attaching to the model I've spawned. Here's my code:

Code:

        new String:target_entityCoord[50];
        Format(target_entityCoord, sizeof(target_entityCoord), "%f %f %f", target_entityCoordX, target_entityCoordY, target_entityCoordZ);

        /**
        * Make the prop
        */
       
        new target_propIndex = CreateEntityByName("prop_physics_override");

        SetEntityModel(target_propIndex, "models/weapons/w_eq_smokegrenade.mdl");
        DispatchKeyValue(target_propIndex, "origin", target_entityCoord);
       
        new String:prop[64];
        Format(prop, sizeof(prop), "prop%i", target_propIndex);
        DispatchKeyValue(target_propIndex, "targetname", prop);

        DispatchSpawn(target_propIndex);

        SetEntProp(target_propIndex, Prop_Data, "m_CollisionGroup", 2);

        SetEntityMoveType(target_propIndex, MOVETYPE_VPHYSICS);
        SetEntProp(target_propIndex, Prop_Data, "m_nSolidType", 6);
        SetEntProp(target_propIndex, Prop_Data, "m_takedamage", 0);

       
       
        /**
        * Make the flare
        */
       
        new Float:brightness = 6.0;

        new String:brightness_s[20];
        FloatToString(brightness, brightness_s, sizeof(brightness_s));

        new target_flareIndex = CreateEntityByName("light_dynamic");
        DispatchKeyValue(target_flareIndex, "_light", "245 0 0");
        DispatchKeyValue(target_flareIndex, "origin", target_entityCoord);
        DispatchKeyValue(target_flareIndex, "brightness", brightness_s);
        DispatchKeyValue(target_flareIndex, "distance", "256");
        DispatchKeyValue(target_flareIndex, "style", "6");
       
        new String:flare[64];
        Format(flare, sizeof(flare), "flare%i", target_flareIndex);
        DispatchKeyValue(target_flareIndex, "targetname", flare);
       
        DispatchKeyValue(target_flareIndex, "paretname", prop);
        DispatchSpawn(target_flareIndex);
        AcceptEntityInput(target_flareIndex, "SetParent", prop);


Fyren 05-22-2009 21:14

Re: Attach Dynamic Light to Model
 
Does that even compile?

PHP Code:

SetVariantString(targetname);
AcceptEntityInput(child"SetParent"); 


SamuraiBarbi 05-24-2009 16:41

Re: Attach Dynamic Light to Model
 
OMFG, I love you! That was exactly what I needed to get it to work. :D

10 million internets to you!


All times are GMT -4. The time now is 05:13.

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