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 client, int args)
{
SpawnButtonFrontOfMe(client);
return Plugin_Handled;
}
// Get position front of player
void SpawnButtonFrontOfMe(int client)
{
if(client < 1 || client > MaxClients) return;
float pos[3], ang[3], fwd[3];
GetClientEyePosition(client, pos);
GetClientEyeAngles(client, ang);
GetAngleVectors(ang, fwd, NULL_VECTOR, NULL_VECTOR);
ScaleVector(fwd, 100.0);
AddVectors(fwd, pos, fwd);
char origin[100];
Format(origin, sizeof(origin), "%0.1f %0.1f %0.1f", fwd[0], fwd[1], fwd[2]);
// Flip 180
float output[3];
MakeVectorFromPoints(fwd, pos, output);
GetVectorAngles(output, ang);
ang[0] = 0.0;
char targetname[100];
int tick = GetGameTickCount();
Format(targetname, sizeof(targetname), "@glow_%i", tick);
CreateModel(fwd, ang, origin, targetname);
CreateButton(fwd, ang, origin, targetname);
}
// 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(prop, fwd, ang, NULL_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(prop, fwd, ang, NULL_VECTOR);
SetEntityModel(prop, "models/props_lab/freightelevatorbutton.mdl");
float vMins[3] = {-30.0, -30.0, 0.0}, vMaxs[3] = {30.0, 30.0, 200.0};
SetEntPropVector(prop, Prop_Send, "m_vecMins", vMins);
SetEntPropVector(prop, Prop_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(prop, Prop_Send, "m_fEffects");
enteffects |= 32;
SetEntProp(prop, Prop_Send, "m_fEffects", enteffects);
}
__________________