Junior Member
|
09-22-2016
, 23:08
Re: Detect entity toutch
|
#5
|
I have this entity (zone by devzones):
Spoiler
PHP Code:
CreateZoneEntity(Float:fMins[3], Float:fMaxs[3], String:sZoneName[64])
{
new Float:fMiddle[3];
new iEnt = CreateEntityByName("trigger_multiple");
DispatchKeyValue(iEnt, "spawnflags", "64");
Format(sZoneName, sizeof(sZoneName), "sm_devzone %s", sZoneName);
DispatchKeyValue(iEnt, "targetname", sZoneName);
DispatchKeyValue(iEnt, "wait", "0");
DispatchSpawn(iEnt);
ActivateEntity(iEnt);
SetEntProp(iEnt, Prop_Data, "m_spawnflags", 64 );
GetMiddleOfABox(fMins, fMaxs, fMiddle);
TeleportEntity(iEnt, fMiddle, NULL_VECTOR, NULL_VECTOR);
SetEntityModel(iEnt, model);
// Have the mins always be negative
fMins[0] = fMins[0] - fMiddle[0];
if(fMins[0] > 0.0)
fMins[0] *= -1.0;
fMins[1] = fMins[1] - fMiddle[1];
if(fMins[1] > 0.0)
fMins[1] *= -1.0;
fMins[2] = fMins[2] - fMiddle[2];
if(fMins[2] > 0.0)
fMins[2] *= -1.0;
// And the maxs always be positive
fMaxs[0] = fMaxs[0] - fMiddle[0];
if(fMaxs[0] < 0.0)
fMaxs[0] *= -1.0;
fMaxs[1] = fMaxs[1] - fMiddle[1];
if(fMaxs[1] < 0.0)
fMaxs[1] *= -1.0;
fMaxs[2] = fMaxs[2] - fMiddle[2];
if(fMaxs[2] < 0.0)
fMaxs[2] *= -1.0;
SetEntPropVector(iEnt, Prop_Send, "m_vecMins", fMins);
SetEntPropVector(iEnt, Prop_Send, "m_vecMaxs", fMaxs);
SetEntProp(iEnt, Prop_Send, "m_nSolidType", 2);
new iEffects = GetEntProp(iEnt, Prop_Send, "m_fEffects");
iEffects |= 32;
SetEntProp(iEnt, Prop_Send, "m_fEffects", iEffects);
//SDKHook(iEnt, SDKHook_Touch, OnBallTouch);
HookSingleEntityOutput(iEnt, "OnStartTouch", EntOut_OnStartTouch);
HookSingleEntityOutput(iEnt, "OnEndTouch", EntOut_OnEndTouch);
}
and i want to detect when this entity (ball) toutch the zone
Spoiler
PHP Code:
void CreateBall()
{
g_Ball = CreateEntityByName("hegrenade_projectile");
Trigger = CreateEntityByName("trigger_multiple");
DispatchKeyValue(g_Ball, "targetname", BALL_ENTITY_NAME);
DispatchSpawn(g_Ball);
SetEntityModel(g_Ball, "models/knastjunkies/soccerball.mdl");
SetEntProp(g_Ball, Prop_Send, "m_usSolidFlags", FSOLID_NOT_SOLID | FSOLID_TRIGGER);
SetEntPropFloat(g_Ball, Prop_Data, "m_flModelScale", 0.60);
Entity_SetMinSize(g_Ball, Float: { -BALL_RADIUS, -BALL_RADIUS, -BALL_RADIUS } );
Entity_SetMaxSize(g_Ball, Float: { BALL_RADIUS, BALL_RADIUS, BALL_RADIUS } );
SetEntityGravity(g_Ball, 0.8);
DispatchKeyValue(Trigger, "spawnflags", "64");
DispatchKeyValue(Trigger, "targetname", "ballTrigger");
DispatchKeyValue(Trigger, "wait", "0");
DispatchSpawn(Trigger);
ActivateEntity(Trigger);
SetEntProp(Trigger, Prop_Data, "m_spawnflags", 64 );
SetEntityModel(Trigger, "models/props/cs_office/vending_machine.mdl");
float vMin[3], vMax[3]
for (int i = 0; i < 3; i++) {
vMin[i] -= 10.0;
}
for (int i = 0; i < 3; i++) {
vMax[i] += 10.0;
}
SetEntPropVector(Trigger, Prop_Send, "m_vecMins", vMin);
SetEntPropVector(Trigger, Prop_Send, "m_vecMaxs", vMax);
SetEntPropEnt(Trigger, Prop_Send, "m_hOwnerEntity", g_Ball);
SetEntProp(Trigger, Prop_Send, "m_nSolidType", 2);
int iEntEffects = GetEntProp(Trigger, Prop_Send, "m_fEffects");
iEntEffects |= 32;
SetEntProp(Trigger, Prop_Send, "m_fEffects", iEntEffects);
SetVariantString("!activator");
AcceptEntityInput(Trigger, "SetParent", g_Ball);
AcceptEntityInput(Trigger, "SetParentAttachmentMaintainOffset");
SDKHook(Trigger, SDKHook_Touch, OnBallTouch);
//HookSingleEntityOutput(Trigger, "OnStartTouch", EntOut_OnStartTouch);
//SDKHook(g_Ball, SDKHook_Touch, OnBallTouch)
}
I am not really shure if this is the right way
|
|