// Start position
Vector _GetStartPos(edict_t *pEnt)
{
if( _GetType
(pEnt
) == BEAM_ENTS
)
{
edict_t *pStartEnt = GETEDICT
(_GetStartEntity
(pEnt
));
return pStartEnt->v.origin;
}
return pEnt->v.origin;
}
void _SetStartPos(edict_t *pEnt, const Vector &pos)
{
pEnt->v.origin = pos;
}
// End position
Vector _GetEndPos(edict_t *pEnt)
{
int type = _GetType
(pEnt
);
if (type == BEAM_POINTS || type == BEAM_HOSE
)
return pEnt->v.
angles;
edict_t *pEndEnt = GETEDICT
(_GetEndEntity
(pEnt
));
if (!FNullEnt
(pEndEnt
))
return pEndEnt->v.origin;
return pEnt->v.angles;
}
void _SetEndPos(edict_t *pEnt, const Vector &pos)
{
pEnt->v.angles = pos;
}
static cell AMX_NATIVE_CALL Beam_GetStartPos
(AMX *amx, cell *params
)
{
CHECK_ENTITY_SIMPLE
(params
[1]);
Vector pReturn = _GetStartPos
(GETEDICT
(params
[1]));
cell *vecRet = MF_GetAmxAddr
(amx, params
[2]);
vecRet
[0] = amx_ftoc
(pReturn.
x);
vecRet
[1] = amx_ftoc
(pReturn.
y);
vecRet
[2] = amx_ftoc
(pReturn.
z);
return 1;
}
static cell AMX_NATIVE_CALL Beam_SetStartPos
(AMX *amx, cell *params
)
{
CHECK_ENTITY_SIMPLE
(params
[1]);
cell *vecPosition = MF_GetAmxAddr
(amx, params
[2]);
_SetStartPos(GETEDICT(params[1]), Vector(amx_ctof(vecPosition[0]), amx_ctof(vecPosition[1]), amx_ctof(vecPosition[2])));
return 1;
}
static cell AMX_NATIVE_CALL Beam_GetEndPos
(AMX *amx, cell *params
)
{
CHECK_ENTITY_SIMPLE
(params
[1]);
Vector pReturn = _GetEndPos
(GETEDICT
(params
[1]));
cell *vecRet = MF_GetAmxAddr
(amx, params
[2]);
vecRet
[0] = amx_ftoc
(pReturn.
x);
vecRet
[1] = amx_ftoc
(pReturn.
y);
vecRet
[2] = amx_ftoc
(pReturn.
z);
return 1;
}
static cell AMX_NATIVE_CALL Beam_SetEndPos
(AMX *amx, cell *params
)
{
CHECK_ENTITY_SIMPLE
(params
[1]);
cell *vecPosition = MF_GetAmxAddr
(amx, params
[2]);
_SetEndPos(GETEDICT(params[1]), Vector(amx_ctof(vecPosition[0]), amx_ctof(vecPosition[1]), amx_ctof(vecPosition[2])));
return 1;
}
static cell AMX_NATIVE_CALL Beam_Create
(AMX *amx, cell *params
)
{
edict_t* pEnt = CREATE_NAMED_ENTITY
(ALLOC_STRING
("beam"));
if(FNullEnt
(pEnt
))
return 0;
int iLen;
char *szModel = MF_GetAmxString
(amx, params
[1],
1, &iLen
);
pEnt->v.
flags |= FL_CUSTOMENTITY;
_SetColor
(pEnt,
255,
255,
255);
_SetBrightness
(pEnt,
255.0);
_SetNoise
(pEnt,
0);
_SetFrame
(pEnt,
0.0);
_SetScrollRate
(pEnt,
0.0);
_SetWidth
(pEnt,
10.0);
_SetTexture
(pEnt, MODEL_INDEX
(szModel
));
//SET_MODEL(pEnt, (char*)STRING(ALLOC_STRING(szModel)));
pEnt->v.
model = ALLOC_STRING
(szModel
);
pEnt->v.
skin =
0;
pEnt->v.
sequence =
0;
pEnt->v.
rendermode =
0;
return ENTINDEX
(pEnt
);
}
static cell AMX_NATIVE_CALL Beam_PointsInit
(AMX *amx, cell *params
)
{
CHECK_ENTITY_SIMPLE
(params
[1]);
edict_t *pEnt = GETEDICT
(params
[1]);
cell *vecStart = MF_GetAmxAddr
(amx, params
[2]);
cell *vecEnd = MF_GetAmxAddr
(amx, params
[3]);
_SetType
(pEnt, BEAM_POINTS
);
_SetStartPos(pEnt, Vector(amx_ctof(vecStart[0]), amx_ctof(vecStart[1]), amx_ctof(vecStart[2])));
_SetEndPos(pEnt, Vector(amx_ctof(vecEnd[0]), amx_ctof(vecEnd[1]), amx_ctof(vecEnd[2])));
_SetStartAttachment
(pEnt,
0);
_SetEndAttachment
(pEnt,
0);
_RelinkBeam
(pEnt
);
return 1;
}
static cell AMX_NATIVE_CALL Beam_HoseInit
(AMX *amx, cell *params
)
{
CHECK_ENTITY_SIMPLE
(params
[1]);
edict_t *pEnt = GETEDICT
(params
[1]);
cell *vecStart = MF_GetAmxAddr
(amx, params
[2]);
cell *vecDir = MF_GetAmxAddr
(amx, params
[3]);
_SetType
(pEnt, BEAM_HOSE
);
_SetStartPos(pEnt, Vector(amx_ctof(vecStart[0]), amx_ctof(vecStart[1]), amx_ctof(vecStart[2])));
_SetEndPos(pEnt, Vector(amx_ctof(vecDir[0]), amx_ctof(vecDir[1]), amx_ctof(vecDir[2])));
_SetStartAttachment
(pEnt,
0);
_SetEndAttachment
(pEnt,
0);
_RelinkBeam
(pEnt
);
return 1;
}
static cell AMX_NATIVE_CALL Beam_PointEntInit
(AMX *amx, cell *params
)
{
CHECK_ENTITY_SIMPLE
(params
[1]);
CHECK_ENTITY_SIMPLE
(params
[3]);
edict_t *pEnt = GETEDICT
(params
[1]);
cell *vecPoint = MF_GetAmxAddr
(amx, params
[2]);
_SetType
(pEnt, BEAM_ENTPOINT
);
_SetStartPos(pEnt, Vector(amx_ctof(vecPoint[0]), amx_ctof(vecPoint[1]), amx_ctof(vecPoint[2])));
_SetEndEntity
(pEnt, params
[3]);
_SetStartAttachment
(pEnt,
0);
_SetEndAttachment
(pEnt,
0);
_RelinkBeam
(pEnt
);
return 1;
}
#define CHECK_ENTITY_SIMPLE(x) \
if (x <
0 || x > gpGlobals->maxEntities
) { \
MF_LogError
(amx, AMX_ERR_NATIVE,
"Entity out of range (%d)", x
); \
return 0; \
} else { \
if (x !=
0 && FNullEnt
(INDEXENT
(x
))) { \
MF_LogError
(amx, AMX_ERR_NATIVE,
"Invalid entity %d", x
); \
return 0; \
} \
}