Неверный раздел форума
здравствуйте у меня такая проблема пушками такая,она весит воздухе,поеди оно должно спуститься на ящик я выложи скрины помогите решить пробелму. ReHLDS version: 3.7.0.692-dev
Код:
#include <amxmodx>
#include <engine>
#include <fun>
#include <cstrike>
#include <fakemeta>
#include <dhudmessage>
#include <hamsandwich>
/* #define UL_COMPAT */
#if defined UL_COMPAT
#include <money_ul>
#endif
// Compatibility with Unlimited Money
#if defined UL_COMPAT
#define get_user_money(%1) cs_get_user_money_ul(%1)
#define set_user_money(%1,%2) cs_set_user_money_ul(%1,%2)
#else
#define set_user_money(%1,%2) cs_set_user_money(%1,%2)
#define get_user_money(%1) cs_get_user_money(%1)
#endif
//#define NEW_SENTRIES //закомментировать если нужны старые модели
#define is_valid_player(%1) ((%1) && (%1) <= g_iMaxPlayers)
#define is_valid_team(%1) ( 0 < %1 < 3 )
#define is_entity_on_ground(%1) ( entity_get_int ( %1, EV_INT_flags ) & FL_ONGROUND )
// сколько пушек у игрока уже построено
#define GetSentryCount(%1) g_iPlayerSentries[%1]
#define MAXUPGRADERANGE 25.0 // дистанция в пределах которой возможна установка/улучшения
#define SENTRYEXPLODERADIUS 250.0 // радиус отброса при взрыве
#define SENTRYTILTRADIUS 830.0 // likely you won't need to touch this. it's how accurate the cannon will aim at the target vertically (up/down, just for looks, aim is calculated differently)
const MAX_SENTRIES_LEVELS = 3; //макс кол-во уровней
const MAX_PL_SENTRIES = 4; //макс кол-во пушек у одного игрока. Менять здесь, автоматичеси заменится везде
const MAXSENTRIES = 32 * MAX_PL_SENTRIES;
#define PEV_SENTRY_TILT_TURRET pev_controller_1
#define PEV_SENTRY_TILT_LAUNCHER pev_controller_2
#define SENTRY_INT_PEOPLE EV_INT_iuser2 // max 5 users using 6 bits!
#define SENTRY_PEOPLE_BITS 6
#define OWNER 0
#define UPGRADER_1 1
#define UPGRADER_2 2
#define TARGET 3
#define MASK_OWNER 0xFFFFFFC0 // 11111111111111111111111111000000
#define MASK_UPGRADER_1 0xFFFFF03F // 11111111111111111111000000111111
#define MASK_UPGRADER_2 0xFFFC0FFF // 11111111111111000000111111111111
#define MASK_TARGET 0xFF03FFFF // 11111111000000111111111111111111
//unused mask: 0xC0FFFFFF // 11000000111111111111111111111111
new const MASKS_PEOPLE[4] = {MASK_OWNER, MASK_UPGRADER_1, MASK_UPGRADER_2, MASK_TARGET}
GetSentryPeople(const SENTRY, const WHO) {
new data = entity_get_int(SENTRY, SENTRY_INT_PEOPLE)
data |= MASKS_PEOPLE[WHO]
data ^= MASKS_PEOPLE[WHO]
data = (data>>(WHO*SENTRY_PEOPLE_BITS))
return data
}
SetSentryPeople(const SENTRY, const WHO, const IS) {
new data = entity_get_int(SENTRY, SENTRY_INT_PEOPLE)
data &= MASKS_PEOPLE[WHO] // nullify the setting
data |= (IS<<(WHO*SENTRY_PEOPLE_BITS)) // set the setting
entity_set_int(SENTRY, SENTRY_INT_PEOPLE, data) // store
}
#define SENTRY_INT_SETTINGS EV_INT_iuser1
#define SENTRY_SETTINGS_BITS 2
#define SENTRY_SETTING_FIREMODE 0
#define SENTRY_SETTING_TEAM 1
#define SENTRY_SETTING_LEVEL 2
#define SENTRY_SETTING_PENDDIR 3
#define MASK_FIREMODE 0xFFFFFFFC // 11111111111111111111111111111100 = FFFFFFFC
#define MASK_TEAM 0xFFFFFFF3 // 11111111111111111111111111110011 = FFFFFFF3
#define MASK_LEVEL 0xFFFFFFCF // 11111111111111111111111111001111 = FFFFFFCF
#define MASK_PENDDIR 0xFFFFFF3F // 11111111111111111111111100111111 = FFFFFF3F
new const MASKS_SETTINGS[4] = {MASK_FIREMODE, MASK_TEAM, MASK_LEVEL, MASK_PENDDIR}
GetSentrySettings(const SENTRY, const SETTING) {
new data = entity_get_int(SENTRY, SENTRY_INT_SETTINGS)
data |= MASKS_SETTINGS[SETTING]
data ^= MASKS_SETTINGS[SETTING]
//data = (data>>(SETTING*SENTRY_SETTINGS_BITS))
return (data>>(SETTING*SENTRY_SETTINGS_BITS))
}
SetSentrySettings(const SENTRY, const SETTING, const VALUE) {
new data = entity_get_int(SENTRY, SENTRY_INT_SETTINGS)
data &= MASKS_SETTINGS[SETTING] // nullify the setting
//data |= (VALUE<<(SETTING*SENTRY_SETTINGS_BITS)) // set the setting
entity_set_int(SENTRY, SENTRY_INT_SETTINGS, data | (VALUE<<(SETTING*SENTRY_SETTINGS_BITS))) // store
}
GetSentryFiremode(const SENTRY) {
return GetSentrySettings(SENTRY, SENTRY_SETTING_FIREMODE)
}
SetSentryFiremode(const SENTRY, const MODE) {
SetSentrySettings(SENTRY, SENTRY_SETTING_FIREMODE, MODE)
}
CsTeams:GetSentryTeam(const SENTRY) {
return CsTeams:GetSentrySettings(SENTRY, SENTRY_SETTING_TEAM)
}
SetSentryTeam(const SENTRY, const CsTeams:TEAM) {
SetSentrySettings(SENTRY, SENTRY_SETTING_TEAM, int:TEAM)
}
GetSentryLevel(const SENTRY) {
return GetSentrySettings(SENTRY, SENTRY_SETTING_LEVEL)
}
SetSentryLevel(const SENTRY, const LEVEL) {
SetSentrySettings(SENTRY, SENTRY_SETTING_LEVEL, LEVEL)
}
GetSentryPenddir(const SENTRY) {
return GetSentrySettings(SENTRY, SENTRY_SETTING_PENDDIR)
}
SetSentryPenddir(const SENTRY, const PENDDIR) {
SetSentrySettings(SENTRY, SENTRY_SETTING_PENDDIR, PENDDIR)
}
#define SENTRY_ENT_BASE EV_ENT_euser1
#define SENTRY_FL_ANGLE EV_FL_fuser1
#define SENTRY_FL_SPINSPEED EV_FL_fuser2
#define SENTRY_FL_MAXSPIN EV_FL_fuser3
#define SENTRY_FL_LASTTHINK EV_FL_fuser4
#define SENTRY_DIR_CANNON 0
#define BASE_ENT_SENTRY EV_ENT_euser1
#define BASE_INT_TEAM EV_INT_iuser1
#define SENTRY_LEVEL_1 0
#define SENTRY_LEVEL_2 1
#define SENTRY_LEVEL_3 2
#define SENTRY_FIREMODE_NO 0
#define SENTRY_FIREMODE_YES 1
#define SENTRY_FIREMODE_NUTS 2
#define TARGETUPMODIFIER 18.0 // if player ducks on ground, traces don't hit...
#define DMG_BULLET (1<<1) //выстрел
#define DMG_BLAST (1<<6) // explosive blast damage
#define TE_EXPLFLAG_NONE 0
#define TE_EXPLOSION 3
#define TE_TRACER 6
#define TE_BREAKMODEL 108
#define PENDULUM_MAX 45.0 // how far sentry turret turns in each direction when idle, before turning back
#define PENDULUM_INCREMENT 10.0 // speed of turret turning...
#define SENTRYSHOCKPOWER 3.0 // multiplier, increase to make exploding sentries throw stuff further away
#define CANNONHEIGHTFROMFEET 20.0 // tweakable to make tracer originate from the same height as the sentry's cannon. Also traces rely on this Y-wise offset.
#define PLAYERORIGINHEIGHT 36.0 // this is the distance from a player's EV_VEC_origin to ground, if standing up
#define HEIGHTDIFFERENCEALLOWED 20.0 // increase value to allow building in slopes with higher angles. You can set to 0.0 and you will only be able to build on exact flat ground. note: mostly applies to downhill building, uphill is still likely to "collide" with ground...
#define PLACE_RANGE 45.0
#define SENTRY_RADAR 20 // use as high as possible but should still be working (ie be able to see sentries plotted on radar while in menu, too high values doesn't seem to work)
#define SENTRY_RADAR_TEAMBUILT 21 // same as above
#if !defined NEW_SENTRIES
#define COLOR_BOTTOM_CT 160 // цвет нижней части для CT:s sentries
#define COLOR_TOP_CT 150 // цвет верхней части для CT:s sentries
#define COLOR_BOTTOM_T 0 // dцвет нижней части для T:s sentries
#define COLOR_TOP_T 0 // dцвет верхней части для T:s sentries
#endif
new const szModels[][] =
{
#if defined NEW_SENTRIES
"models/dmsentries/base.mdl",
"models/dmsentries/sentry1_t.mdl",
"models/dmsentries/sentry2_t.mdl",
"models/dmsentries/sentry3_t.mdl",
"models/dmsentries/sentry1_ct.mdl",
"models/dmsentries/sentry2_ct.mdl",
"models/dmsentries/sentry3_ct.mdl",
#else
"models/sentries/base.mdl",
"models/sentries/sentry1.mdl",
"models/sentries/sentry2.mdl",
"models/sentries/sentry3.mdl",
#endif
"models/computergibs.mdl"
}
new const szSounds[][] =
{
"debris/bustmetal1.wav",
"debris/bustmetal2.wav",
"debris/metal1.wav",
"debris/metal3.wav",
#if defined NEW_SENTRIES
"dmsentries/turridle.wav",
"dmsentries/turrset.wav",
"dmsentries/turrspot.wav",
"dmsentries/building.wav",
"dmsentries/fire.wav"
#else
"sentries/turridle.wav",
"sentries/turrset.wav",
"sentries/turrspot.wav",
"sentries/building.wav",
"weapons/m249-1.wav"
#endif
}
new const g_SENTRYFRAGREWARDS[MAX_SENTRIES_LEVELS] = {300, 150, 150} // как много денег получит за фраг от пушки тот, кто построил ее, а также прокачал
new const g_DMG[MAX_SENTRIES_LEVELS] = {5, 7, 10} // количество урона от пушки в зависимости от ее уровня
new const Float:g_THINKFREQUENCIES[MAX_SENTRIES_LEVELS] = {2.0, 1.5, 1.0} // через сколько захватывается цель
new const Float:g_HITRATIOS[MAX_SENTRIES_LEVELS] = {0.6, 0.75, 0.85} // разброс
new const Float:g_HEALTHS[MAX_SENTRIES_LEVELS] = {2000.0, 5000.0, 8000.0} // сколько хп у пушки в зависимости от ее уровня (верхняя часть)
new const g_COST[MAX_SENTRIES_LEVELS] = {5000, 200, 300} // стоимость установки/улучшения пушек
new const g_SENTRYCOST[MAX_PL_SENTRIES] = {2000, 4000, 5000} // стоимость установки/улучшения пушек
#define g_sentriesNum (g_teamsentriesNum[0]+g_teamsentriesNum[1])
new g_teamsentriesNum[2]
new g_sentries[MAXSENTRIES]
new g_iPlayerSentries[33]
new g_iPlayerSentriesEdicts[33][MAX_PL_SENTRIES]
new g_sModelIndexFireball
new g_msgDamage
new g_msgDeathMsg
new g_msgScoreInfo
new g_msgHostagePos
new g_msgHostageK
new g_iMaxPlayers
new Float:g_ONEEIGHTYTHROUGHPI
new Float:g_sentryOrigins[32][3]
new bool:g_inBuilding[33]
new sentries_num[33]
new gMsgID
public plugin_init() {
register_plugin("Sentry guns", "1.1", "JGHG & miRror")
register_event ( "Spectator", "ev_Spectation", "a")
register_clcmd ("sentry_build", "cmd_CreateSentry", 0, "- build a sentry gun where you are")
register_clcmd ("say /sgstats", "sgstats", 0, "- stats sentry")
RegisterHam (Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
register_forward ( FM_TraceLine, "fw_TraceLine_Post", 1 )
RegisterHam ( Ham_TakeDamage, "func_breakable", "fw_TakeDamage" )
register_touch ( "sentry", "player", "fw_TouchSentry" )
register_message (23, "msg_TempEntity")
register_think ("sentrybase", "think_sentrybase")
register_think ("sentry", "fw_ThinkSentry")
g_msgDamage = get_user_msgid("Damage")
g_msgDeathMsg = get_user_msgid("DeathMsg")
g_msgScoreInfo = get_user_msgid("ScoreInfo")
g_msgHostagePos = get_user_msgid("HostagePos")
g_msgHostageK = get_user_msgid("HostageK")
gMsgID = get_user_msgid("StatusIcon")
g_iMaxPlayers = get_global_int(GL_maxClients)
g_ONEEIGHTYTHROUGHPI = 180.0 / 3.141592654
//set_task ( 120.0, "checkhero", .flags = "b" )
}
public plugin_precache() {
for(new i=0;i<sizeof(szModels);i++)
precache_model(szModels[i])
for(new i=0;i<sizeof(szSounds);i++)
precache_sound(szSounds[i])
g_sModelIndexFireball = precache_model("sprites/zerogxplode.spr")
}
public sgstats(id)
{
ChatColor ( id, "^1Пушек у КТ: [ ^4%d ^1] | ТТ: [ ^4%d ^1], у всех: [ ^4%d ^1]", g_teamsentriesNum[1],g_teamsentriesNum[0],g_sentriesNum)
}
public ev_Spectation ()
{
new id = read_data ( 1 )
if ( is_user_connected ( id ) && cs_get_user_team ( id ) == CS_TEAM_SPECTATOR )
while ( GetSentryCount ( id ) > 0 )
sentry_detonate_by_owner ( id )
}
public fw_TakeDamage ( ent, idinflictor, idattacker, Float:damage, damagebits )
{
if ( !pev_valid ( ent ) )
return HAM_IGNORED
new sClassname[11]
pev ( ent, pev_classname, sClassname, charsmax ( sClassname ) )
if ( equal ( sClassname, "sentry" ) || equal ( sClassname, "sentrybase" ) )
{
if ( sClassname[6] == 'b' )
ent = entity_get_edict(ent, BASE_ENT_SENTRY)
if ( pev_valid ( ent ) )
{
new iOwner = GetSentryPeople ( ent, OWNER )
if ( !is_user_connected ( iOwner ) || !is_valid_player ( iOwner ) || !is_user_connected ( idattacker ) || !is_valid_player ( idattacker ) )
return HAM_SUPERCEDE
if ( cs_get_user_team ( iOwner ) == cs_get_user_team ( idattacker ) && idattacker != iOwner )
return HAM_SUPERCEDE
}
}
return HAM_IGNORED
}
public cmd_CreateSentry ( id )
{
new iSentry = AimingAtSentry (id)
if ( iSentry && entity_range ( iSentry, id ) <= MAXUPGRADERANGE )
SentryUpgrade (id, iSentry)
else
SentryBuild (id)
return PLUGIN_HANDLED
}
public SentryBuild ( id )
{
if ( !is_user_alive ( id ) )
{
//ChatColor ( id, "^3[^4Информация^3]^1 Убитым нельзя ставить пушку!" )
return
}
new iSentryCount = GetSentryCount (id)
if (iSentryCount == MAX_PL_SENTRIES ){
//ChatColor ( id, "^3[^4Информация^3]^1 Нельзя установить более 3 пушек!")
return
}
if ( g_inBuilding[id] )
{
//ChatColor ( id, "^3[^4Информация^3]^1 Эй, не так быстро..." )
return
}
if ( !is_entity_on_ground ( id ) )
{
//ChatColor ( id, "^3[^4Информация^3]^1 Встань на землю, чтобы установить пушку!" )
return
}
if (get_user_money (id) < g_SENTRYCOST[iSentryCount])
{
//ChatColor ( id, "^3[^4Информация^3]^1 У тебя не хватает денег! (нужно ^4%d$^1)", g_SENTRYCOST[iSentryCount] )
return
}
new Float:fPlayerOrigin[3], Float:fOrigin[3], Float:fAngle[3]
pev ( id, pev_origin, fPlayerOrigin )
pev ( id, pev_angles, fAngle )
fOrigin = fPlayerOrigin
fOrigin[0] += floatcos ( fAngle[1], degrees ) * PLACE_RANGE
fOrigin[1] += floatsin ( fAngle[1], degrees ) * PLACE_RANGE
fOrigin[0] += floatcos ( fAngle[0], degrees) * PLACE_RANGE
fOrigin[1] += floatcos ( fAngle[1], degrees )
fOrigin[0] -= floatsin ( fAngle[1], degrees )
fOrigin[1] += floatcos ( fAngle[2], degrees )
fOrigin[1] -= floatsin ( fAngle[2], degrees ) * PLACE_RANGE
fOrigin[0] -= floatsin ( fAngle[0], degrees ) * PLACE_RANGE
fOrigin[0] -= PLACE_RANGE
if ( pev ( id, pev_flags ) & FL_DUCKING )
fOrigin[2] += 18.0, fPlayerOrigin[2] += 18.0
new tr = 0, Float:fFraction
engfunc ( EngFunc_TraceLine, fPlayerOrigin, fOrigin, 0, id, tr )
get_tr2 ( tr, TR_flFraction, fFraction )
if ( fFraction != 1.0 )
{
//ChatColor ( id, "^3[^4Информация^3]^1 Здесь не получается установить пушку!" )
return
}
if ( CreateSentryBase ( fOrigin, id ) )
{
set_user_money ( id, get_user_money ( id ) - g_SENTRYCOST[iSentryCount] )
ammo_hud ( id, 0 )
sentries_num[id] += 1
ammo_hud ( id, 1 )
}
//else
//ChatColor ( id, "^3[^4Информация^3]^1 Здесь не получается установить пушку!" )
}
IncreaseSentryCount ( id, sentry )
{
g_iPlayerSentriesEdicts[id][g_iPlayerSentries[id]] = sentry
g_iPlayerSentries[id]++
new Float:fSentryOrigin[3], iSentryOrigin[3], iPlayerOrigin[3]
entity_get_vector ( sentry, EV_VEC_origin, fSentryOrigin )
FVecIVec ( fSentryOrigin, iSentryOrigin )
new sName[32]
get_user_name ( id, sName, charsmax ( sName ) )
new CsTeams:iTeam = cs_get_user_team ( id )
for ( new i = 1; i <= g_iMaxPlayers; i++ )
{
if ( !is_user_connected ( i ) || !is_user_alive ( i ) || cs_get_user_team ( i ) != iTeam || id == i )
continue
get_user_origin ( i, iPlayerOrigin )
client_print ( i, print_center, "%s установил пушку в %d юнитах от вас", sName, get_distance ( iPlayerOrigin, iSentryOrigin ) )
message_begin ( MSG_ONE_UNRELIABLE, g_msgHostagePos, .player = i )
write_byte ( i )
write_byte ( SENTRY_RADAR_TEAMBUILT )
write_coord ( iSentryOrigin[0] )
write_coord ( iSentryOrigin[1] )
write_coord ( iSentryOrigin[2] )
message_end ()
message_begin ( MSG_ONE_UNRELIABLE, g_msgHostageK, .player = i )
write_byte ( SENTRY_RADAR_TEAMBUILT )
message_end ()
}
}
DecreaseSentryCount ( id, sentry )
{
for ( new i; i < g_iPlayerSentries[id]; i++ )
{
if ( g_iPlayerSentriesEdicts[id][i] == sentry )
{
g_iPlayerSentriesEdicts[id][i] = g_iPlayerSentriesEdicts[id][g_iPlayerSentries[id] - 1]
g_iPlayerSentriesEdicts[id][g_iPlayerSentries[id] - 1] = 0
break
}
}
g_iPlayerSentries[id]--
}
stock bool:CreateSentryBase ( Float:origin[3], creator, level = SENTRY_LEVEL_1 )
{
if ( !CheckLocation ( origin ) )
return false
new Float:hitPoint[3], Float:originDown[3]
originDown = origin
originDown[2] = -5000.0 // dunno the lowest possible height...
trace_line(0, origin, originDown, hitPoint)
new Float:baDistanceFromGround = vector_distance(origin, hitPoint)
new Float:difference = PLAYERORIGINHEIGHT - baDistanceFromGround
if (difference < -1 * HEIGHTDIFFERENCEALLOWED || difference > HEIGHTDIFFERENCEALLOWED) return false
new entbase = create_entity("func_breakable") // func_wall
if (!entbase)
return false
#if defined NEW_SENTRIES
#define SIZE 16.0
new Float:fTraceEnds[5][3], Float:fTraceHit[3], iType, tr = create_tr2 ()
fTraceEnds[0][0] = origin[0] - SIZE
fTraceEnds[0][1] = origin[1] - SIZE
fTraceEnds[0][2] = origin[2] + SIZE + SIZE
fTraceEnds[1][0] = origin[0] + SIZE
fTraceEnds[1][1] = origin[1] - SIZE
fTraceEnds[1][2] = origin[2] + SIZE + SIZE
fTraceEnds[2][0] = origin[0] - SIZE
fTraceEnds[2][1] = origin[1] + SIZE
fTraceEnds[2][2] = origin[2] + SIZE + SIZE
fTraceEnds[3][0] = origin[0] + SIZE
fTraceEnds[3][1] = origin[1] + SIZE
fTraceEnds[3][2] = origin[2] + SIZE + SIZE
fTraceEnds[4][0] = origin[0]
fTraceEnds[4][1] = origin[1]
fTraceEnds[4][2] = origin[2] + SIZE + SIZE
for ( new i; i < 5; i++ )
{
fTraceHit = fTraceEnds[i]
fTraceHit[2] += 40.0
engfunc ( EngFunc_TraceLine, fTraceEnds[i], fTraceHit, 0, 0, tr )
get_tr2 ( tr, TR_vecEndPos, fTraceHit )
if ( fTraceHit[2] - fTraceEnds[i][2] != 40.0 )
{
iType = 1
break
}
}
if ( iType )
{
fTraceEnds[0][0] = origin[0] - SIZE
fTraceEnds[0][1] = origin[1] - SIZE
fTraceEnds[0][2] = origin[2] - SIZE - SIZE
fTraceEnds[1][0] = origin[0] + SIZE
fTraceEnds[1][1] = origin[1] - SIZE
fTraceEnds[1][2] = origin[2] - SIZE - SIZE
fTraceEnds[2][0] = origin[0] - SIZE
fTraceEnds[2][1] = origin[1] + SIZE
fTraceEnds[2][2] = origin[2] - SIZE - SIZE
fTraceEnds[3][0] = origin[0] + SIZE
fTraceEnds[3][1] = origin[1] + SIZE
fTraceEnds[3][2] = origin[2] - SIZE - SIZE
fTraceEnds[4][0] = origin[0]
fTraceEnds[4][1] = origin[1]
fTraceEnds[4][2] = origin[2] - SIZE - SIZE
new Float:fMinDistance, Float:fDistance
for ( new i; i < 5; i++ )
{
fTraceHit[0] = fTraceEnds[i][0]
fTraceHit[1] = fTraceEnds[i][1]
fTraceHit[2] = -8192.0
engfunc ( EngFunc_TraceLine, fTraceEnds[i], fTraceHit, IGNORE_MONSTERS, 0, tr )
get_tr2 ( tr, TR_vecEndPos, fTraceHit )
fDistance = vector_distance ( fTraceEnds[i], fTraceHit )
if ( fDistance < fMinDistance || fMinDistance <= 0.0 )
{
fMinDistance = fDistance
origin[2] = fTraceHit[2]
}
}
}
free_tr2 ( tr )
#endif
new healthstring[16]
num_to_str(floatround(g_HEALTHS[0]), healthstring, 15)
DispatchKeyValue(entbase, "health", healthstring)
DispatchKeyValue(entbase, "material", "6")
DispatchSpawn(entbase)
entity_set_string(entbase, EV_SZ_classname, "sentrybase")
#if defined NEW_SENTRIES
entity_set_model(entbase, "models/dmsentries/base.mdl")
#else
entity_set_model(entbase, "models/sentries/base.mdl")
#endif
new Float:mins[3], Float:maxs[3]
mins[0] = -16.0
mins[1] = -16.0
mins[2] = 0.0
maxs[0] = 16.0
maxs[1] = 16.0
maxs[2] = 1000.0 // Set to 16.0 later.
entity_set_size(entbase, mins, maxs)
entity_set_origin(entbase, origin)
entity_set_int(entbase, EV_INT_solid, SOLID_SLIDEBOX)
#if defined NEW_SENTRIES
entity_set_int(entbase, EV_INT_movetype, iType ? MOVETYPE_FLY : MOVETYPE_TOSS) // head flies base falls
#else
entity_set_int(entbase, EV_INT_movetype, MOVETYPE_TOSS)
#endif
entity_set_int(entbase, BASE_INT_TEAM, _:cs_get_user_team(creator))
new parms[4]
parms[0] = entbase
parms[1] = creator
parms[2] = level
#if defined NEW_SENTRIES
parms[3] = iType
if ( iType ) origin[2] += 16.0
#endif
g_sentryOrigins[creator - 1] = origin
emit_sound(creator, CHAN_AUTO, "sentries/building.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
set_task(2.0, "createsentryhead", 0, parms, 4)
g_inBuilding[creator] = true
return true
}
public createsentryhead(parms[4])
{
new entbase = parms[0]
new level = parms[2]
new creator = parms[1]
#if defined NEW_SENTRIES
new iType = parms[3]
#endif
if ( !is_user_connected ( creator ) || !g_inBuilding[creator] )
{
if (is_valid_ent(entbase))
remove_entity(entbase)
return
}
if ( !is_valid_team ( _:cs_get_user_team ( creator ) ) )
{
if (is_valid_ent(entbase))
remove_entity(entbase)
sentries_num[creator]--
return
}
new Float:origin[3]
origin = g_sentryOrigins[creator - 1]
new ent = create_entity("func_breakable")
if (!ent)
{
if (is_valid_ent(entbase))
{
remove_entity(entbase)
}
return
}
new Float:mins[3], Float:maxs[3]
if (is_valid_ent(entbase)) {
mins[0] = -16.0
mins[1] = -16.0
mins[2] = 0.0
maxs[0] = 16.0
maxs[1] = 16.0
maxs[2] = 16.0
entity_set_size(entbase, mins, maxs)
entity_set_edict(ent, SENTRY_ENT_BASE, entbase)
entity_set_edict(entbase, BASE_ENT_SENTRY, ent)
}
g_sentries[g_sentriesNum] = ent
new healthstring[16]
num_to_str(floatround(g_HEALTHS[0]), healthstring, 15)
DispatchKeyValue(ent, "health", healthstring)
DispatchKeyValue(ent, "material", "6")
DispatchSpawn(ent)
entity_set_string(ent, EV_SZ_classname, "sentry")
#if defined NEW_SENTRIES
switch(_:cs_get_user_team(creator))
{
case 1:
{
switch(level)
{
case SENTRY_LEVEL_1: entity_set_model(ent, "models/dmsentries/sentry1_t.mdl")
case SENTRY_LEVEL_2: entity_set_model(ent, "models/dmsentries/sentry2_t.mdl")
case SENTRY_LEVEL_3: entity_set_model(ent, "models/dmsentries/sentry3_t.mdl")
}
}
case 2:
{
switch(level)
{
case SENTRY_LEVEL_1: entity_set_model(ent, "models/dmsentries/sentry1_ct.mdl")
case SENTRY_LEVEL_2: entity_set_model(ent, "models/dmsentries/sentry2_ct.mdl")
case SENTRY_LEVEL_3: entity_set_model(ent, "models/dmsentries/sentry3_ct.mdl")
}
}
}
#else
switch(level)
{
case SENTRY_LEVEL_1: entity_set_model(ent, "models/sentries/sentry1.mdl")
case SENTRY_LEVEL_2: entity_set_model(ent, "models/sentries/sentry2.mdl")
case SENTRY_LEVEL_3: entity_set_model(ent, "models/sentries/sentry3.mdl")
}
#endif
mins[0] = -16.0
mins[1] = -16.0
mins[2] = 0.0
maxs[0] = 16.0
maxs[1] = 16.0
maxs[2] = 48.0
entity_set_size(ent, mins, maxs)
entity_set_origin(ent, origin)
entity_get_vector(creator, EV_VEC_angles, origin)
origin[0] = 0.0
origin[1] += 180.0
entity_set_float(ent, SENTRY_FL_ANGLE, origin[1])
origin[2] = 0.0
entity_set_vector(ent, EV_VEC_angles, origin)
entity_set_int(ent, EV_INT_solid, SOLID_SLIDEBOX) // SOLID_SLIDEBOX
#if defined NEW_SENTRIES
entity_set_int(ent, EV_INT_movetype, iType ? MOVETYPE_FLY : MOVETYPE_TOSS) // head flies, base doesn't
#else
entity_set_int(ent, EV_INT_movetype, MOVETYPE_TOSS)
set_pev(ent, PEV_SENTRY_TILT_TURRET, 127)
set_pev(ent, PEV_SENTRY_TILT_LAUNCHER, 127)
#endif
SetSentryPeople(ent, OWNER, creator)
new CsTeams:crteam = cs_get_user_team(creator)
SetSentryTeam ( ent, crteam )
SetSentryLevel ( ent, level )
g_teamsentriesNum[_:crteam-1]++
#if !defined NEW_SENTRIES
new topColor = crteam == CS_TEAM_CT ? COLOR_TOP_CT : COLOR_TOP_T
new bottomColor = crteam == CS_TEAM_CT ? COLOR_BOTTOM_CT : COLOR_BOTTOM_T
new map = topColor | (bottomColor<<8)
entity_set_int(ent, EV_INT_colormap, map)
emit_sound(ent, CHAN_AUTO, "sentries/turrset.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
#else
emit_sound(ent, CHAN_AUTO, "dmsentries/turrset.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
#endif
IncreaseSentryCount(creator, ent)
new directions = (random_num(0, 1)<<SENTRY_DIR_CANNON)
SetSentryPenddir ( ent, directions )
g_inBuilding[creator] = false
if (!is_valid_ent(entbase))
SetSentryFiremode ( ent, SENTRY_FIREMODE_NUTS )
entity_set_float ( ent, SENTRY_FL_LASTTHINK, get_gametime () + g_THINKFREQUENCIES[0] )
entity_set_float ( ent, EV_FL_nextthink, get_gametime () + 0.01 )
/*static bool:bHamRegistred
if ( !bHamRegistred )
{
RegisterHamFromEntity ( Ham_Think, ent, "fw_ThinkSentry", 1 )
bHamRegistred = true
}*/
}
stock bool:CheckLocation ( const Float:origin[3] )
{
if ( engfunc ( EngFunc_PointContents, origin ) != CONTENTS_EMPTY )
return false
new tr = create_tr2 ()
engfunc ( EngFunc_TraceHull, origin, origin, 0, HULL_HEAD/*HUMAN*/, 0, tr )
if ( !get_tr2 ( tr, TR_InOpen ) || get_tr2 ( tr, TR_StartSolid ) || get_tr2 ( tr, TR_AllSolid ) )
{
free_tr2 ( tr )
return false
}
#define SIZE 16.0
new Float:fTraceEnds[9][3], Float:fTraceHit[3], iHitEnt
fTraceEnds[0][0] = origin[0]
fTraceEnds[0][1] = origin[1]
fTraceEnds[0][2] = origin[2] - SIZE - SIZE
fTraceEnds[1][0] = origin[0] - SIZE
fTraceEnds[1][1] = origin[1] - SIZE
fTraceEnds[1][2] = origin[2] - SIZE - SIZE
fTraceEnds[2][0] = origin[0] + SIZE
fTraceEnds[2][1] = origin[1] - SIZE
fTraceEnds[2][2] = origin[2] - SIZE - SIZE
fTraceEnds[3][0] = origin[0] - SIZE
fTraceEnds[3][1] = origin[1] + SIZE
fTraceEnds[3][2] = origin[2] - SIZE - SIZE
fTraceEnds[4][0] = origin[0] + SIZE
fTraceEnds[4][1] = origin[1] + SIZE
fTraceEnds[4][2] = origin[2] - SIZE - SIZE
fTraceEnds[5][0] = origin[0] - SIZE
fTraceEnds[5][1] = origin[1] - SIZE
fTraceEnds[5][2] = origin[2] + SIZE + SIZE
fTraceEnds[6][0] = origin[0] + SIZE
fTraceEnds[6][1] = origin[1] - SIZE
fTraceEnds[6][2] = origin[2] + SIZE + SIZE
fTraceEnds[7][0] = origin[0] - SIZE
fTraceEnds[7][1] = origin[1] + SIZE
fTraceEnds[7][2] = origin[2] + SIZE + SIZE
fTraceEnds[8][0] = origin[0] + SIZE
fTraceEnds[8][1] = origin[1] + SIZE
fTraceEnds[8][2] = origin[2] + SIZE + SIZE
for (new i = 0, b = 0; i < 9; i++)
{
if ( engfunc ( EngFunc_PointContents, fTraceEnds[i] ) != CONTENTS_EMPTY )
{
free_tr2 ( tr )
return false
}
engfunc ( EngFunc_TraceLine, origin, fTraceEnds[i], 0, 0, tr )
iHitEnt = get_tr2 ( tr, TR_pHit )
if ( iHitEnt != -1 )
{
free_tr2 ( tr )
return false
}
get_tr2 ( tr, TR_vecEndPos, fTraceHit )
for ( b = 0; b < 3; b++ )
{
if ( fTraceEnds[i][b] != fTraceHit[b] )
{
free_tr2 ( tr )
return false
}
}
if ( i < 5 )
{
fTraceHit[0] = fTraceEnds[i][0]
fTraceHit[1] = fTraceEnds[i][1]
fTraceHit[2] = -8192.0
engfunc ( EngFunc_TraceLine, fTraceEnds[i], fTraceHit, 0, 0, tr )
//get_tr2 ( tr, TR_vecEndPos, fTraceHit )
iHitEnt = get_tr2 ( tr, TR_pHit )
if ( pev_valid ( iHitEnt ) )
{
new sClassname[7]
pev ( iHitEnt, pev_classname, sClassname, charsmax ( sClassname ) )
if ( equal ( sClassname, "sentry" ) )
{
free_tr2 ( tr )
return false
}
}
}
}
free_tr2 ( tr )
return true
}
bool:sentry_pendulum ( sentry )
{
switch ( GetSentryFiremode ( sentry ) )
{
case SENTRY_FIREMODE_NO:
{
new Float:fAngles[3]
entity_get_vector ( sentry, EV_VEC_angles, fAngles )
new Float:fBaseAngle = entity_get_float ( sentry, SENTRY_FL_ANGLE )
new iDirections = GetSentryPenddir ( sentry )
if ( iDirections & (1<<SENTRY_DIR_CANNON) )
{
fAngles[1] -= ( PENDULUM_INCREMENT * 0.01 )
if ( fAngles[1] < fBaseAngle - PENDULUM_MAX )
{
fAngles[1] = fBaseAngle - PENDULUM_MAX
iDirections &= ~(1<<SENTRY_DIR_CANNON)
SetSentryPenddir ( sentry, iDirections )
}
}
else
{
fAngles[1] += ( PENDULUM_INCREMENT * 0.01 )
if ( fAngles[1] > fBaseAngle + PENDULUM_MAX )
{
fAngles[1] = fBaseAngle + PENDULUM_MAX
iDirections |= (1<<SENTRY_DIR_CANNON)
SetSentryPenddir ( sentry, iDirections )
}
}
entity_set_vector ( sentry, EV_VEC_angles, fAngles )
return true
}
case SENTRY_FIREMODE_NUTS:
{
new Float:fAngles[3]
entity_get_vector ( sentry, EV_VEC_angles, fAngles )
new Float:fSpinSpeed = entity_get_float ( sentry, SENTRY_FL_SPINSPEED )
if ( GetSentryPenddir ( sentry ) & (1<<SENTRY_DIR_CANNON) )
{
fAngles[1] -= ( fSpinSpeed * 0.01 )
if ( fAngles[1] < 0.0 )
fAngles[1] = 360.0 + fAngles[1]
}
else
{
fAngles[1] += ( fSpinSpeed * 0.01 )
if ( fAngles[1] > 360.0 )
fAngles[1] = fAngles[1] - 360.0
}
entity_set_float ( sentry, SENTRY_FL_SPINSPEED, ( fSpinSpeed += random_float ( 1.0, 2.0 ) ) )
new Float:fMaxSpin = entity_get_float ( sentry, SENTRY_FL_MAXSPIN )
if ( fMaxSpin == 0.0 )
{
entity_set_float ( sentry, SENTRY_FL_LASTTHINK, 0.5 )
entity_set_float ( sentry, SENTRY_FL_MAXSPIN, fMaxSpin = random_float ( 500.0, 750.0 ) )
}
else if ( fSpinSpeed >= fMaxSpin )
{
sentry_detonate ( sentry, false, false )
return false
}
entity_set_vector ( sentry, EV_VEC_angles, fAngles )
return true
}
}
return true
}
//#define TE_TRACER 6 // tracer effect from point to point
tracer(Float:start[3], Float:end[3]) {
new start_[3], end_[3]
FVecIVec(start, start_)
FVecIVec(end, end_)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY) // MSG_PAS MSG_BROADCAST
write_byte(TE_TRACER)
write_coord(start_[0])
write_coord(start_[1])
write_coord(start_[2])
write_coord(end_[0])
write_coord(end_[1])
write_coord(end_[2])
message_end()
}
stock create_explosion(Float:origin_[3]) {
new origin[3]
FVecIVec(origin_, origin)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY, origin) // MSG_PAS not really good here
write_byte(TE_EXPLOSION)
write_coord(origin[0])
write_coord(origin[1])
write_coord(origin[2])
write_short(g_sModelIndexFireball)
write_byte(random_num(0, 20) + 50) // scale * 10 // random_num(0, 20) + 20
write_byte(12) // framerate
write_byte(TE_EXPLFLAG_NONE)
message_end()
KnockBack ( origin_ )
new Float:playerOrigin[3], Float:distance, Float:flDmgToDo, Float:dmgbase = 90.0, newHealth
for (new i = 1; i <= g_iMaxPlayers; i++) {
if (!is_user_alive(i) || get_user_godmode(i))
continue
entity_get_vector(i, EV_VEC_origin, playerOrigin)
distance = vector_distance(playerOrigin, origin_)
if (distance <= SENTRYEXPLODERADIUS) {
flDmgToDo = dmgbase - (dmgbase * (distance / SENTRYEXPLODERADIUS))
newHealth = get_user_health(i) - floatround(flDmgToDo)
if (newHealth <= 0) {
set_task(0.0, "TicketToHell", i)
continue
}
set_user_health(i, newHealth)
message_begin(MSG_ONE_UNRELIABLE, g_msgDamage, {0,0,0}, i)
write_byte(floatround(flDmgToDo))
write_byte(floatround(flDmgToDo))
write_long(DMG_BLAST)
write_coord(origin[0])
write_coord(origin[1])
write_coord(origin[2])
message_end()
}
}
}
public TicketToHell(player) {
if (!is_user_connected(player))
return
new frags = get_user_frags(player)
user_kill(player, 1) // don't decrease frags
new parms[4]
parms[0] = player
parms[1] = frags
parms[2] = cs_get_user_deaths(player)
parms[3] = int:cs_get_user_team(player)
set_task(0.0, "DelayedScoreInfoUpdate", 0, parms, 4)
}
public DelayedScoreInfoUpdate(parms[4]) {
scoreinfo_update(parms[0], parms[1], parms[2], parms[3])
}
KnockBack ( Float:origin[3] )
{
new iEntList[32]
new iEntsFound = find_sphere_class ( 0, "player", SENTRYEXPLODERADIUS, iEntList, g_iMaxPlayers, origin )
if ( !iEntsFound )
return
new Float:fOriginEnt[3]
new Float:fVelocity[3]
new Float:fOriginEnd[3]
new Float:fDistance
new iPlayer
for ( new i; i < iEntsFound; i++ )
{
iPlayer = iEntList[i]
if ( !is_user_alive ( iPlayer ) )
continue
entity_get_vector ( iPlayer, EV_VEC_origin, fOriginEnt )
fDistance = vector_distance ( fOriginEnt, origin )
if ( is_entity_on_ground ( iPlayer ) && fOriginEnt[2] < origin[2] )
fOriginEnt[2] = origin[2] + fDistance
entity_get_vector ( iPlayer, EV_VEC_velocity, fVelocity )
fOriginEnd[0] = ( fOriginEnt[0] - origin[0] ) * SENTRYEXPLODERADIUS / fDistance + origin[0]
fOriginEnd[1] = ( fOriginEnt[1] - origin[1] ) * SENTRYEXPLODERADIUS / fDistance + origin[1]
fOriginEnd[2] = ( fOriginEnt[2] - origin[2] ) * SENTRYEXPLODERADIUS / fDistance + origin[2]
fVelocity[0] += ( fOriginEnd[0] - fOriginEnt[0] ) * SENTRYSHOCKPOWER
fVelocity[1] += ( fOriginEnd[1] - fOriginEnt[1] ) * SENTRYSHOCKPOWER
fVelocity[2] += ( fOriginEnd[2] - fOriginEnt[2] ) * SENTRYSHOCKPOWER
entity_set_vector ( iPlayer, EV_VEC_velocity, fVelocity )
}
}
public msg_TempEntity ()
{
if ( get_msg_args () != 15 && get_msg_arg_int ( 1 ) != TE_BREAKMODEL )
return PLUGIN_CONTINUE
for ( new i; i < g_sentriesNum; i++ )
{
if ( entity_get_float ( g_sentries[i], EV_FL_health ) <= 0.0 )
{
sentry_detonate ( i, false, true )
i--
}
}
return PLUGIN_CONTINUE
}
public fw_ThinkSentry ( ent )
{
if ( !is_valid_ent ( ent ) )
return
/*static iOwner; iOwner = GetSentryPeople ( ent, OWNER )
if ( !is_user_connected ( iOwner ) )
return
if ( cs_get_user_team ( iOwner ) == CS_TEAM_SPECTATOR )
{
sentry_detonate ( ent, true, false )
return
}*/
if ( !sentry_pendulum ( ent ) )
return
static Float:fGameTime; fGameTime = get_gametime ()
if ( entity_get_float ( ent, SENTRY_FL_LASTTHINK ) <= fGameTime )
{
new Float:fOriginSentry[3], Float:fOriginHit[3], iHitEnt
entity_get_vector ( ent, EV_VEC_origin, fOriginSentry )
fOriginSentry[2] += CANNONHEIGHTFROMFEET // Move up some, this should be the Y origin of the cannon
new firemode = GetSentryFiremode ( ent )
new target = GetSentryPeople ( ent, TARGET )
if ( firemode == SENTRY_FIREMODE_YES && is_valid_ent ( target ) && is_user_alive ( target ) && cs_get_user_team ( target ) != GetSentryTeam ( ent ) )
{
new sentryLevel = GetSentryLevel ( ent )
new Float:fOriginTarget[3]
entity_get_vector ( target, EV_VEC_origin, fOriginTarget )
if ( entity_get_int ( target, EV_INT_flags ) & FL_DUCKING )
fOriginTarget[2] += TARGETUPMODIFIER
iHitEnt = trace_line ( ent, fOriginSentry, fOriginTarget, fOriginHit )
if ( iHitEnt == entity_get_edict ( ent, SENTRY_ENT_BASE ) )
iHitEnt = trace_line ( iHitEnt, fOriginHit, fOriginTarget, fOriginHit )
if ( iHitEnt != target && is_user_alive ( iHitEnt ) && GetSentryTeam ( ent ) != cs_get_user_team ( iHitEnt ) )
{
target = iHitEnt
SetSentryPeople(ent, TARGET, iHitEnt)
}
if ( iHitEnt == target )
{
SentryTurnToTarget ( ent, fOriginSentry, fOriginTarget )
emit_sound ( ent, CHAN_WEAPON, "weapons/m249-1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM )
new Float:fHitRatio = random_float ( 0.0, 1.0 ) - g_HITRATIOS[sentryLevel] // ie 0.5 - 0.7 = -0.2, a hit and 0.8 - 0.7 = a miss by 0.1
if ( !get_user_godmode ( target ) && fHitRatio <= 0.0 )
sentry_damagetoplayer ( ent, sentryLevel, fOriginSentry, target )
else
{
new Float:fSentryAngle[3] = {0.0, 0.0, 0.0}
new Float:x = fOriginHit[0] - fOriginSentry[0]
new Float:z = fOriginHit[1] - fOriginSentry[1]
new Float:radians = floatatan ( z/x, radian )
fSentryAngle[1] = radians * g_ONEEIGHTYTHROUGHPI
if ( fOriginHit[0] < fOriginSentry[0] )
fSentryAngle[1] -= 180.0
new Float:h = fOriginHit[2] - fOriginSentry[2]
new Float:b = vector_distance ( fOriginSentry, fOriginHit )
radians = floatatan ( h/b, radian )
fSentryAngle[0] = radians * g_ONEEIGHTYTHROUGHPI
fSentryAngle[0] += random_float ( -10.0 * fHitRatio, 10.0 * fHitRatio ) // aim is a little off here :-)
fSentryAngle[1] += random_float ( -10.0 * fHitRatio, 10.0 * fHitRatio ) // aim is a little off here :-)
engfunc ( EngFunc_MakeVectors, fSentryAngle )
new Float:vector[3]
get_global_vector ( GL_v_forward, vector )
for ( new i = 0; i < 3; i++ )
vector[i] *= 1000
new Float:traceEnd[3]
for ( new i = 0; i < 3; i++ )
traceEnd[i] = vector[i] + fOriginSentry[i]
new iHitEnt2 = ent
static lolcheck = 0
while ( ( iHitEnt2 = trace_line ( iHitEnt2, fOriginHit, traceEnd, fOriginHit ) ) )
if ( lolcheck++ > 700 ) break
}
tracer ( fOriginSentry, fOriginHit )
entity_set_float ( ent, SENTRY_FL_LASTTHINK, fGameTime + 0.1 )
entity_set_float ( ent, EV_FL_nextthink, fGameTime + 0.01 )
return
}
else
SetSentryFiremode ( ent, SENTRY_FIREMODE_NO )
}
else if ( firemode == SENTRY_FIREMODE_NUTS )
{
new iHitEnt2 = EntViewHitPoint ( ent, fOriginSentry, fOriginHit )
#if defined NEW_SENTRIES
emit_sound(ent, CHAN_WEAPON, "sentries/fire.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
#else
//emit_sound(ent, CHAN_WEAPON, "weapons/m249-1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
#endif
tracer(fOriginSentry, fOriginHit)
if (is_user_connected(iHitEnt2) && is_user_alive(iHitEnt2) && !get_user_godmode(iHitEnt2))
{
sentry_damagetoplayer(ent, GetSentryLevel ( ent ), fOriginSentry, iHitEnt2)
}
entity_set_float ( ent, SENTRY_FL_LASTTHINK, fGameTime + 0.1 )
entity_set_float ( ent, EV_FL_nextthink, fGameTime + 0.01 )
return
}
if ( random_num ( 0, 99 ) < 10 )
#if defined NEW_SENTRIES
emit_sound (ent, CHAN_AUTO, "dmsentries/turridle.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
#else
emit_sound (ent, CHAN_AUTO, "sentries/turridle.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
#endif
new closestTarget = 0, Float:closestDistance, Float:distance, Float:closestOrigin[3], Float:playerOrigin[3], CsTeams:sentryTeam = GetSentryTeam ( ent )
for ( new i = 1; i <= g_iMaxPlayers; i++ )
{
if ( !is_user_connected ( i ) || !is_user_alive ( i ) || cs_get_user_team ( i ) == sentryTeam )
continue
entity_get_vector ( i, EV_VEC_origin, playerOrigin )
if ( entity_get_int ( i, EV_INT_flags ) & FL_DUCKING )
playerOrigin[2] += TARGETUPMODIFIER
iHitEnt = trace_line ( ent, fOriginSentry, playerOrigin, fOriginHit )
if ( iHitEnt == entity_get_edict ( ent, SENTRY_ENT_BASE ) )
iHitEnt = trace_line(iHitEnt, fOriginHit, playerOrigin, fOriginHit)
if ( iHitEnt == i )
{
distance = vector_distance ( fOriginSentry, playerOrigin )
closestOrigin = playerOrigin
if ( distance < closestDistance || closestTarget == 0 )
{
closestTarget = i
closestDistance = distance
}
}
}
if ( closestTarget )
{
#if defined NEW_SENTRIES
emit_sound ( ent, CHAN_AUTO, "dmsentries/turrspot.wav", 1.0, ATTN_NORM, 0, PITCH_NORM )
#else
emit_sound ( ent, CHAN_AUTO, "sentries/turrspot.wav", 1.0, ATTN_NORM, 0, PITCH_NORM )
#endif
SentryTurnToTarget ( ent, fOriginSentry, closestOrigin )
SetSentryFiremode ( ent, SENTRY_FIREMODE_YES )
SetSentryPeople ( ent, TARGET, closestTarget )
}
else
SetSentryFiremode ( ent, SENTRY_FIREMODE_NO )
entity_set_float ( ent, SENTRY_FL_LASTTHINK, fGameTime + g_THINKFREQUENCIES[GetSentryLevel ( ent )] )
}
entity_set_float ( ent, EV_FL_nextthink, fGameTime + 0.01 )
}
public think_sentrybase(sentrybase) {
sentrybase_broke(sentrybase)
return PLUGIN_CONTINUE
}
sentrybase_broke(sentrybase) {
new sentry = entity_get_edict(sentrybase, BASE_ENT_SENTRY)
if (is_valid_ent(sentrybase))
remove_entity(sentrybase)
if (sentry == 0)
return
SetSentryFiremode ( sentry, SENTRY_FIREMODE_NUTS )
}
sentry_detonate(sentry, bool:quiet, bool:isIndex) {
new i
if (isIndex)
{
i = sentry
sentry = g_sentries[sentry]
if (!is_valid_ent(sentry))
return
}
else
{
if (!is_valid_ent(sentry))
return
for (new j = 0; j < g_sentriesNum; j++) {
if (g_sentries[j] == sentry) {
i = j
break
}
}
}
entity_set_float ( sentry, EV_FL_nextthink, 0.0 )
new owner = GetSentryPeople(sentry, OWNER)
if (!quiet) {
new Float:origin[3]
entity_get_vector(sentry, EV_VEC_origin, origin)
create_explosion(origin)
ChatColor ( owner, "^3[^4ВНИМАНИЕ^3]^1 Твоя пушка взорвана!")
ammo_hud(owner, 0)
sentries_num[owner] -= 1
ammo_hud(owner, 1)
}
DecreaseSentryCount(owner, sentry)
// Remove base first
if (GetSentryFiremode ( sentry ) != SENTRY_FIREMODE_NUTS)
set_task ( 0.1, "DelayRemoveEntity", entity_get_edict ( sentry, SENTRY_ENT_BASE ) )
//remove_entity(entity_get_edict(sentry, SENTRY_ENT_BASE))
new CsTeams:iSentryTeam = GetSentryTeam ( sentry )
set_task ( 0.1, "DelayRemoveEntity", sentry )
//remove_entity(sentry)
// Put the last sentry in the deleted entity's place
if(0 > (g_sentriesNum - 1) > MAXSENTRIES) return
g_sentries[i] = g_sentries[g_sentriesNum - 1]
g_teamsentriesNum[_:iSentryTeam-1]--
}
public DelayRemoveEntity ( ent )
{
if ( pev_valid ( ent ) )
remove_entity ( ent )
}
sentry_detonate_by_owner(owner, bool:quiet = false) {
for(new i = 0; i < g_sentriesNum; i++) {
if (GetSentryPeople(g_sentries[i], OWNER) == owner) {
sentry_detonate(i, quiet, true)
break
}
}
}
public client_disconnect(id) {
while (GetSentryCount(id) > 0)
sentry_detonate_by_owner(id)
}
// урон игроку
stock sentry_damagetoplayer(sentry, sentryLevel, Float:sentryOrigin[3], target) {
new newHealth = get_user_health(target) - g_DMG[sentryLevel]
if (newHealth <= 0) {
new targetFrags = get_user_frags(target) + 1
new owner = GetSentryPeople(sentry, OWNER)
new ownerFrags = get_user_frags(owner) + 1
set_user_frags(target, targetFrags) // otherwise frags are subtracted from victim for dying (!!)
set_user_frags(owner, ownerFrags)
new contributors[3], moneyRewards[33] = {0, ...}
contributors[0] = owner
contributors[1] = GetSentryPeople(sentry, UPGRADER_1)
contributors[2] = GetSentryPeople(sentry, UPGRADER_2)
for (new i = SENTRY_LEVEL_1; i <= sentryLevel; i++) {
moneyRewards[contributors[i]] += g_SENTRYFRAGREWARDS[i]
}
for (new i = 1; i <= g_iMaxPlayers; i++) {
if(!moneyRewards[i] || !is_user_connected(i) || cs_get_user_team(owner)!=cs_get_user_team(i)) continue
if((get_user_money(i) + moneyRewards[i]) <= 16000)
set_user_money(i, get_user_money(i) + moneyRewards[i])
}
message_begin(MSG_ALL, g_msgDeathMsg, {0, 0, 0} ,0)
write_byte(owner)
write_byte(target)
write_byte(0)
write_string("sentry gun")
message_end()
scoreinfo_update(owner, ownerFrags, cs_get_user_deaths(owner), int:cs_get_user_team(owner))
set_msg_block(g_msgDeathMsg, BLOCK_ONCE)
}
set_user_health(target, newHealth)
message_begin(MSG_ONE_UNRELIABLE, g_msgDamage, {0,0,0}, target)
write_byte(g_DMG[sentryLevel])
write_byte(g_DMG[sentryLevel])
write_long(DMG_BULLET)
write_coord(floatround(sentryOrigin[0]))
write_coord(floatround(sentryOrigin[1]))
write_coord(floatround(sentryOrigin[2]))
message_end()
}
scoreinfo_update(id, frags, deaths, team) {
message_begin(MSG_ALL, g_msgScoreInfo)
write_byte(id)
write_short(frags)
write_short(deaths)
write_short(0)
write_short(team)
message_end()
}
SentryTurnToTarget ( ent, Float:sentry_origin[3], Float:closest_origin[3] )
{
new Float:fAngle[3]
entity_get_vector ( ent, EV_VEC_angles, fAngle )
new Float:x = closest_origin[0] - sentry_origin[0]
new Float:z = closest_origin[1] - sentry_origin[1]
new Float:fRadians = floatatan ( z/x, radian )
fAngle[1] = fRadians * g_ONEEIGHTYTHROUGHPI
if ( closest_origin[0] < sentry_origin[0] )
fAngle[1] -= 180.0
entity_set_float ( ent, SENTRY_FL_ANGLE, fAngle[1] )
#if !defined NEW_SENTRIES
// Set tilt
new Float:h = closest_origin[2] - sentry_origin[2]
new Float:b = vector_distance(sentry_origin, closest_origin)
fRadians = floatatan(h/b, radian)
new Float:degs = fRadians * g_ONEEIGHTYTHROUGHPI;
// Now adjust EV_BYTE_controller1
// Each degree corresponds to about 100/256 "bytes", = ~0,39 byte / degree (ok this is not entirely true, just tweaked for now with SENTRYTILTRADIUS)
new Float:RADIUS = SENTRYTILTRADIUS // get_cvar_float("sentry_tiltradius");
new Float:degreeByte = RADIUS/256.0; // tweak radius later
new Float:tilt = 127.0 - degreeByte * degs; // 127 is center of 256... well, almost
//client_print(GetSentryPeople(ent, OWNER), print_chat, "%d: Setting tilt to %d", ent, floatround(tilt))
set_pev(ent, PEV_SENTRY_TILT_TURRET, floatround(tilt)) //entity_set_byte(ent, SENTRY_TILT_TURRET, floatround(tilt))
#endif
entity_set_vector ( ent, EV_VEC_angles, fAngle )
}
AimingAtSentry ( id )
{
if ( !is_user_alive ( id ) )
return 0
new hitEnt, bodyPart
if (get_user_aiming(id, hitEnt, bodyPart) == 0.0)
return 0
if ( is_valid_ent ( hitEnt ) )
{
new classname[32], l_sentry
entity_get_string(hitEnt, EV_SZ_classname, classname, 31)
if (equal(classname, "sentry_base"))
l_sentry = entity_get_edict(hitEnt, BASE_ENT_SENTRY)
else if (equal(classname, "sentry"))
l_sentry = hitEnt
else
l_sentry = 0
return l_sentry
}
return 0
}
// улучшение уровня пушки
bool:SentryUpgrade (id, sentry)
{
if ( GetSentryFiremode ( sentry ) == SENTRY_FIREMODE_NUTS )
return false
new iLevel = GetSentryLevel (sentry)
if (iLevel == SENTRY_LEVEL_3)
return false
if (cs_get_user_team ( id ) != GetSentryTeam (sentry))
{
//ChatColor ( id, "^3[^4Информация^3]^1 Можно качать только пушки своей команды!")
return false
}
if (cs_get_user_team (GetSentryPeople (sentry, OWNER)) == CS_TEAM_SPECTATOR)
return false
new isAdmin = get_user_flags(id) & ADMIN_LEVEL_H
new user_money = get_user_money (id)
if (isAdmin){
if (user_money - g_COST[SENTRY_LEVEL_3] < 0){
if(user_money - g_COST[SENTRY_LEVEL_2] < 0){
if(user_money - g_COST[SENTRY_LEVEL_1] < 0){
ChatColor ( id, "^3[^4Информация^3]^1 У тебя не хватает денег (нужно ^4%d$^1)", g_COST[SENTRY_LEVEL_1] )
return false
}
else
iLevel = SENTRY_LEVEL_1
}
else
iLevel = SENTRY_LEVEL_2
}
else
iLevel = SENTRY_LEVEL_3
}
else {
if (iLevel == SENTRY_LEVEL_1 && GetSentryPeople (sentry, OWNER) == id)
return false
if (iLevel == SENTRY_LEVEL_2 && GetSentryPeople (sentry, UPGRADER_1) == id)
return false
iLevel++
if (user_money - g_COST[iLevel] < 0) {
ChatColor ( id, "^3[^4Информация^3]^1 У тебя не хватает денег (нужно ^4%d$^1)", g_COST[iLevel] )
return false
}
}
set_user_money (id, user_money - g_COST[iLevel])
#if defined NEW_SENTRIES
new iTeam = _:cs_get_user_team ( id ), iUpgraderField
switch ( iLevel )
{
case SENTRY_LEVEL_2:
{
switch (iTeam)
{
case 1:entity_set_model ( sentry, "models/dmsentries/sentry2_t.mdl" )
case 2:entity_set_model ( sentry, "models/dmsentries/sentry2_ct.mdl" )
}
iUpgraderField = UPGRADER_1
}
case SENTRY_LEVEL_3:
{
switch (iTeam)
{
case 1:entity_set_model ( sentry, "models/dmsentries/sentry3_t.mdl" )
case 2:entity_set_model ( sentry, "models/dmsentries/sentry3_ct.mdl" )
}
iUpgraderField = UPGRADER_2
}
}
#else
new iUpgraderField;
switch (iLevel) {
case SENTRY_LEVEL_2: {
entity_set_model(sentry, "models/sentries/sentry2.mdl")
iUpgraderField = UPGRADER_1
}
case SENTRY_LEVEL_3: {
entity_set_model(sentry, "models/sentries/sentry3.mdl")
iUpgraderField = UPGRADER_2
}
}
#endif
new Float:fMins[3], Float:fMaxs[3]
fMins[0] = -16.0
fMins[1] = -16.0
fMins[2] = 0.0
fMaxs[0] = 16.0
fMaxs[1] = 16.0
fMaxs[2] = 48.0 // 4.0
entity_set_size ( sentry, fMins, fMaxs )
#if defined NEW_SENTRIES
emit_sound ( sentry, CHAN_AUTO, "dmsentries/turrset.wav", 1.0, ATTN_NORM, 0, PITCH_NORM )
#else
emit_sound ( sentry, CHAN_AUTO, "sentries/turrset.wav", 1.0, ATTN_NORM, 0, PITCH_NORM )
#endif
SetSentryLevel ( sentry, iLevel )
entity_set_float ( sentry, EV_FL_health, g_HEALTHS[iLevel] )
entity_set_float ( entity_get_edict ( sentry, SENTRY_ENT_BASE ), EV_FL_health, g_HEALTHS[0] )
SetSentryPeople ( sentry, iUpgraderField, id )
new sName[32]
get_user_name ( id, sName, charsmax ( sName ) )
client_print ( GetSentryPeople ( sentry, OWNER ), print_center, "%s прокачал твою пушку до уровня %d", sName, iLevel + 1 )
return true
}
stock EntViewHitPoint ( index, Float:origin[3], Float:hitorigin[3] )
{
if ( !is_valid_ent ( index ) )
return 0
new Float:angle[3], Float:vec[3], Float:f_dest[3]
entity_get_vector(index, EV_VEC_angles, angle)
engfunc(EngFunc_AngleVectors, angle, vec, 0, 0)
f_dest[0] = origin[0] + vec[0] * 9999
f_dest[1] = origin[1] + vec[1] * 9999
f_dest[2] = origin[2] + vec[2] * 9999
return trace_line(index, origin, f_dest, hitorigin)
}
public fw_PlayerSpawn_Post ( id )
{
if ( !is_user_alive ( id ) )
return
g_inBuilding[id] = false
while ( GetSentryCount ( id ) > 0 )
sentry_detonate_by_owner ( id, true )
ammo_hud ( id, 0 )
sentries_num[id] = 0
}
public fw_TraceLine_Post ( Float:start[3], Float:end[3], noMonsters, id )
{
if ( !is_valid_player ( id ) || !is_user_alive ( id ) )
return FMRES_IGNORED
new iHitEnt = get_tr ( TR_pHit )
if ( iHitEnt <= g_iMaxPlayers )
return FMRES_IGNORED
new sClassName[11], sentry, base
pev ( iHitEnt, pev_classname, sClassName, charsmax ( sClassName ) )
if ( equal ( sClassName, "sentrybase" ) )
{
base = iHitEnt
sentry = entity_get_edict ( iHitEnt, BASE_ENT_SENTRY )
}
else if ( equal ( sClassName, "sentry" ) )
{
sentry = iHitEnt
base = entity_get_edict ( sentry, SENTRY_ENT_BASE )
}
if ( !pev_valid ( sentry ) || !base )
return FMRES_IGNORED
if ( GetSentryFiremode ( sentry ) == SENTRY_FIREMODE_NUTS )
return FMRES_IGNORED
new Float:health = entity_get_float ( sentry, EV_FL_health )
if ( health <= 0 )
return FMRES_IGNORED
new Float:basehealth = entity_get_float ( base, EV_FL_health )
if ( basehealth <= 0 )
return FMRES_IGNORED
new CsTeams:team = GetSentryTeam ( sentry )
if ( team != cs_get_user_team ( id ) )
return FMRES_IGNORED
new level = GetSentryLevel ( sentry )
static tempStatusBuffer[192], tempStatusBuffer2[192]
new OwnName[33]
get_user_name ( GetSentryPeople ( sentry, OWNER ), OwnName, 32 )
formatex ( tempStatusBuffer, charsmax ( tempStatusBuffer ), "Установил: %s^nЗдоровье: %d/%d", OwnName, floatround(health), floatround(g_HEALTHS[level]) )
formatex ( tempStatusBuffer2, charsmax ( tempStatusBuffer2 ), "^n^nЗдоровье основания: %d/%d^nУровень: %d", floatround(basehealth), floatround(g_HEALTHS[0]), level + 1 )
set_dhudmessage ( _:team == 1 ? 150 : 0, 0, _:team == 2 ? 150 : 0, -1.0, 0.35, 0, 0.0, 0.6, 0.0, 0.0 )
show_dhudmessage(id, tempStatusBuffer)
show_dhudmessage(id, tempStatusBuffer2)
return FMRES_IGNORED
}
// прикосновение к пушке игрока
public fw_TouchSentry ( sentry, player ) { SentryUpgrade ( player, sentry ); }
ammo_hud(id, sw)
{
if(is_user_bot(id)||!is_user_alive(id)||!is_user_connected(id))
return
new s_sprite[33]
format(s_sprite, 32, "number_%d", sentries_num[id])
if(sw)
{
message_begin( MSG_ONE, gMsgID, {0,0,0}, id )
write_byte( 1 ) // status
write_string( s_sprite ) // sprite name
write_byte( 250 ) // red
write_byte( 250 ) // green
write_byte( 250 ) // blue
message_end()
}
else
{
message_begin( MSG_ONE, gMsgID, {0,0,0}, id )
write_byte( 0 ) // status
write_string( s_sprite ) // sprite name
write_byte( 250 ) // red
write_byte( 250 ) // green
write_byte( 250 ) // blue
message_end()
}
if(sentries_num[id] <= 0)
{
message_begin( MSG_ONE, gMsgID, {0,0,0}, id )
write_byte( 0 ) // status
write_string( s_sprite ) // sprite name
write_byte( 250 ) // red
write_byte( 250 ) // green
write_byte( 250 ) // blue
message_end()
}
}
stock ChatColor(const id, const input[], any:...)
{
new count = 1, players[32]
static msg[191]
vformat(msg, 190, input, 3)
replace_all(msg, 190, "!g", "^4") // Green Color
replace_all(msg, 190, "!y", "^1") // Default Color
replace_all(msg, 190, "!team", "^3") // Team Color
replace_all(msg, 190, "!team2", "^0") // Team2 Color
if (id) players[0] = id; else get_players(players, count, "ch")
{
for (new i = 0; i < count; i++)
{
if (is_user_connected(players[i]))
{
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
write_byte(players[i]);
write_string(msg);
message_end();
}
}
}
}