Thread: [Solved] help with glow
View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-25-2020 , 11:21   Re: help with glow
Reply With Quote #4

Ok, finally. I had difficulties and I had to make dedicated server also.

Use sm_test to spawn button in front of you.

- prop_dynamic glows when player aim to func_button.
- Will glow through walls, but player need still aim to func_button
- Not sure, does other players see glow when another player aim func_button
- When press button, it stay in (-1) and glow stop when button in.

I guess, this not satisfy you...

PHP Code:
#include <sdktools>

public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"test);
}

public 
Action test(int clientint args)
{

    
SpawnButtonFrontOfMe(client);

    return 
Plugin_Handled;
}


// Get position front of player
void SpawnButtonFrontOfMe(int client)
{
    if(
client || client MaxClients) return;

    
float pos[3], ang[3], fwd[3];

    
GetClientEyePosition(clientpos);
    
GetClientEyeAngles(clientang);


    
GetAngleVectors(angfwdNULL_VECTORNULL_VECTOR);
    
ScaleVector(fwd100.0);
    
AddVectors(fwdposfwd);

    
char origin[100];
    
Format(originsizeof(origin), "%0.1f %0.1f %0.1f"fwd[0], fwd[1], fwd[2]);

    
// Flip 180
    
float output[3];
    
MakeVectorFromPoints(fwdposoutput);
    
GetVectorAngles(outputang);
    
ang[0] = 0.0;

    
char targetname[100];
    
int tick GetGameTickCount();
    
    
Format(targetnamesizeof(targetname), "@glow_%i"tick);

    
CreateModel(fwdangorigintargetname);
    
CreateButton(fwdangorigintargetname);
}



// Create dynamic model
void CreateModel(const float fwd[3], const float ang[3], const char[] origin, const char[] targetname)
{
    
PrecacheModel("models/props_lab/freightelevatorbutton.mdl");
    
    
int prop CreateEntityByName("prop_dynamic");
    
    if(
prop == -1) return;

    
DispatchKeyValue(prop"origin"origin);
    
DispatchKeyValue(prop"targetname"targetname); // important for func_button glow entity

    
DispatchKeyValue(prop"model""models/props_lab/freightelevatorbutton.mdl");
    
DispatchKeyValue(prop"spawnflags""0");
/*
16 = Break on Touch
32 = Break on Pressure
64 = Use Hitboxes for Renderbox
256 = Start with collision disabled
*/

    
DispatchSpawn(prop);
    
    
TeleportEntity(propfwdangNULL_VECTOR);
}



void CreateButton(const float fwd[3], const float ang[3], const char[] origin, const char[] targetname)
{
    
PrecacheModel("models/props_lab/freightelevatorbutton.mdl");

    
int prop CreateEntityByName("func_button");
    
    if(
prop == -1) return;
    
    
DispatchKeyValue(prop"origin"origin); // important or button start flying to 0, 0, 0 coordinates after press
    
DispatchKeyValue(prop"glow"targetname);

    
DispatchKeyValue(prop"wait""-1");    // Default 3 sec, -1 stay. Glowing stop when button OnIn
    
DispatchKeyValue(prop"spawnflags""1025"); // Don't move + Use Activates
/*
1 = Don't move
32 = Toggle
256 = Touch Activates
512 = Damage Activates
1024 = Use Activates
2048 = Starts Locked
4096 = Sparks
*/


    
DispatchSpawn(prop);
    
ActivateEntity(prop);
    

    
TeleportEntity(propfwdangNULL_VECTOR);

    
SetEntityModel(prop"models/props_lab/freightelevatorbutton.mdl");

    
float vMins[3] = {-30.0, -30.00.0}, vMaxs[3] = {30.030.0200.0};
    
SetEntPropVector(propProp_Send"m_vecMins"vMins);
    
SetEntPropVector(propProp_Send"m_vecMaxs"vMaxs);
    

    
// This disable entity error
    // ERROR:  Can't draw studio model models/props_lab/freightelevatorbutton.mdl because CBaseButton is not derived from C_BaseAnimating

    
int enteffects GetEntProp(propProp_Send"m_fEffects");
    
enteffects |= 32;
    
SetEntProp(propProp_Send"m_fEffects"enteffects);

__________________
Do not Private Message @me
Bacardi is offline