Post by ShaunCraft15 on Feb 11, 2022 9:56:12 GMT
Hello guys thnaks for reading this so i have problem in my rc bomb i change spawn system but if i spawn rc the rc doesn't spawn
Here my code
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#include <fun>
#include <xs>
#include <zp50_core>
#include <zp50_class_survivor>
#include <zp50_class_sniper>
#include <zp50_items>
#include <bulletdamage>
#include <zp50_colorchat>
#include <zombieplague>
#include <beams>
#include <zp50_ammopacks>
#include <crxranks>
#include <cstrike>
#include <zp50_item_zombie_madness>
#define eDirection 4
#define eTurnAngle 0
#define eEngineForce 1
#define eGear 2
#define eVelocity_x 3
#define eVelocity_y 4
#define eVelocity_z 5
#define eJumpForce 6
#define eLastTime 7
#define eNextSoundTime 9
#define eNextPitchTime 10
//#define fm_drop_to_floor(%1) engfunc(EngFunc_DropToFloor,%1)
new const SAVAGE_CLASSNAME[] = "FakeSavage"
const OFFSET_CSMENUCODE = 205
new Ham:Ham_Player_ResetMaxSpeed = Ham_Item_PreFrame
new modelname[] = "models/zp_lgk/MonsterTruck.mdl"
new boom
new Pev_Value[33]
new dSavages[33][5], Float:fSavages[33][11],
Float:Accel, Float:MaxForce,
Float:MaxGrip, Float:Drag, Gravity,
g_iItem, g_iHasSavage[33],
g_iSavageEntity[33], g_iSavageCamEntity[33],
bool:g_bIsSvgMenuOpened[33], bool:g_bIsSpawningCar[33],
bool:g_bHasSpawned[33], g_CanPlaced[33], g_pSB[33]
new g_pCvarAccel,
g_pCvarMaxForce,
g_pCvarMaxGrip,
g_pCvarDrag,
g_pCvarChaseCam,
g_pCvarSavageCarHP,
g_pCvarSavageDamage,
g_pCvarSavageRadius,
g_pCvarSavageKnockback
const DMG_GRENADE = (1<<24)
new g_pBeam[33]
new gAlreadyBought[33];
new iTeamLimit;
public plugin_precache()
{
precache_model(modelname)
precache_model("models/rpgrocket.mdl") // For the camera
precache_sound("zombie_plague/savage_engine.wav")
precache_sound("debris/bustglass1.wav")
boom = precache_model("sprites/zerogxplode.spr")
}
public plugin_init()
{
register_plugin("RC Monster Trcuk", "3.00", "K-OS")
RegisterHam(Ham_Killed,"player", "fw_Killed_Post", 1)
register_think(SAVAGE_CLASSNAME, "SB_Think");
RegisterHam(Ham_Player_ResetMaxSpeed, "player", "fw_ResetMaxSpeed_Post", 1)
register_forward(FM_OnFreeEntPrivateData, "OnFreeEntPrivateData");
register_think("rcbomb", "savage_think")
register_think("camera", "camera_think")
register_clcmd("say /rc", "OpenSavageMenu")
g_pCvarAccel = register_cvar("savage_accel", "7500")
g_pCvarMaxForce = register_cvar("savage_maxforce", "500.0")
g_pCvarMaxGrip = register_cvar("savage_maxgrip", "2.0")
g_pCvarDrag = register_cvar("savage_drag", "2.0")
g_pCvarChaseCam = register_cvar("savage_chasecam", "1")
g_pCvarSavageCarHP = register_cvar("savage_health", "200.0")
g_pCvarSavageDamage = register_cvar("savage_damage", "1300")
g_pCvarSavageRadius = register_cvar("savage_radius", "1000.0")
g_pCvarSavageKnockback = register_cvar("savage_knockback", "1000.0")
g_iItem = zp_items_register("RC-Bomb", 60)
}
public fw_Killed_Post(victim_id, attacker_id)
{
if (g_bHasSpawned[victim_id])
RemoveSavages(victim_id)
}
public OnFreeEntPrivateData(this)
{
if (!FClassnameIs(this, SAVAGE_CLASSNAME))
return FMRES_IGNORED;
new pOwner = pev(this, pev_owner);
if ((1 <= pOwner <= get_maxplayers()))
{
if (g_pBeam[pOwner] && is_valid_ent(g_pBeam[pOwner]))
remove_entity(g_pBeam[pOwner]);
g_pBeam[pOwner] = 0;
g_pSB[pOwner] = 0;
}
return FMRES_IGNORED;
}
public Ham_SavageTakeDamage_Pre(victim_id, inflictor_id, attacker_id, Float:fDamage, iDamageBits)
{
static szNameCheck[32]
pev(victim_id, pev_classname, szNameCheck, charsmax(szNameCheck))
if (!equal("rcbomb", szNameCheck))
return HAM_IGNORED
if(!is_user_connected(victim_id))
return HAM_IGNORED;
if(!is_user_connected(attacker_id))
return HAM_IGNORED;
if (pev(victim_id, pev_iuser1) == attacker_id || !zp_core_is_zombie(attacker_id))
return HAM_SUPERCEDE
return HAM_IGNORED
}
public fw_ResetMaxSpeed_Post(id)
{
// Dead or not frozen
if (!is_user_alive(id) || !g_bHasSpawned[id])
return;
// Prevent from moving
set_user_maxspeed(id, 1.0)
}
public Ham_SavageTakeDamage_Post( victim_id, inflictor_id, attacker_id, Float:fDamage, iDamageBits)
{
static szNameCheck[32]
pev(victim_id, pev_classname, szNameCheck, charsmax(szNameCheck))
if (!equal("rcbomb", szNameCheck))
return HAM_IGNORED
if (pev(victim_id, pev_health) <= 0.0)
{
new ownerid = pev(victim_id, pev_owner)
DamageNearby(ownerid)
client_printcolor(ownerid, "!y[!gLgK!y] Your RC Car Got !tDestroyed")
set_user_maxspeed(ownerid, 250.0)
return HAM_IGNORED
}
return HAM_IGNORED
}
public plugin_natives()
{
register_native("free_racecar","give_rc", 1)
}
public give_rc(id)
{
g_iHasSavage[id] += 1
OpenSavageMenu(id)
}
public zp_user_infected_post(id)
{
if (g_pSB[id] && is_valid_ent(g_pSB[id]))
remove_entity(g_pSB[id]);
if (g_pBeam[id] && is_valid_ent(g_pBeam[id]))
remove_entity(g_pBeam[id])
}
public zp_fw_items_select_pre(id, itemid)
{
if(itemid != g_iItem) return ZP_ITEM_AVAILABLE;
if(zp_core_is_zombie(id)) return ZP_ITEM_DONT_SHOW;
if(zp_class_survivor_get(id)) return ZP_ITEM_DONT_SHOW;
if(zp_class_sniper_get(id)) return ZP_ITEM_DONT_SHOW;
if(crxranks_get_user_level(id) <= 1)
{
zp_items_menu_text_add(" \r[Level 2 Needed]")
return ZP_ITEM_NOT_AVAILABLE;
}
else zp_items_menu_text_add(" \y[Available For You]")
if(g_bHasSpawned[id])
{
zp_items_menu_text_add("\r[Spawned]")
return ZP_ITEM_NOT_AVAILABLE;
}
return ZP_ITEM_AVAILABLE;
}
public zp_fw_items_select_post(id, itemid, ignorecost)
{
if (itemid != g_iItem)
return
gAlreadyBought[id]++
iTeamLimit++
g_iHasSavage[id] += 1
OpenSavageMenu(id)
}
public Count(id)
{
client_print(id, print_chat, "%d %d %d %d", g_iHasSavage[id], g_bIsSpawningCar[id], g_bHasSpawned[id], g_bIsSvgMenuOpened[id])
}
public OpenSavageMenu(id)
{
new iMenu = menu_create("[LgK | Savage]", "SavageMenu_Handler")
menu_additem(iMenu, "Spawn RC From Extra Items", "")
if (g_bHasSpawned[id])
menu_additem(iMenu, "Return RC", "")
else
menu_additem(iMenu, "\dReturn RC", "")
//menu_additem(iMenu, "Switch Pov", "")
menu_addtext(iMenu, "\rPress \y1 \rto start the RC ^nPress \yW/S \rto move forward/backward^nPress \yA/D \rto move Left/Right^nPress \yLeft Mouse/Space \rto Explode RC/Jump", 1)
//client_printcolor(id, "!y[!gLgK!y] Press !g1 !yTo Start RC, !gW !yand !gS !yTo Move !tforward!g/!tbackward!y, !gA !yAnd !gD !yTo Move !gLeft And Right")
if (is_user_alive(id) && !zp_core_is_zombie(id))
{
if(g_iHasSavage[id])
{
g_bIsSvgMenuOpened[id] = true
g_bIsSpawningCar[id] = true
CreateFakeSavage(id)
set_pdata_int(id, OFFSET_CSMENUCODE, 0)
menu_setprop(iMenu, MPROP_EXIT, MEXIT_ALL)
menu_display(id, iMenu, 0)
}
}
if(!zp_core_is_zombie(id) && !g_iHasSavage[id])
{
if(gAlreadyBought[id] < 1)
{
if(zp_ammopacks_get(id) > 20)
{
g_iHasSavage[id]++
gAlreadyBought[id]++
}
}
}
}
public SavageMenu_Handler(id, iMenu, iItem)
{
if (!is_user_alive(id) || zp_core_is_zombie(id))
return
new iEntity = FM_NULLENT
if (!g_iHasSavage[id])
{
client_printcolor(id, "!y[!gLgK!y] You don't any remote cars.")
return
}
if (iItem == MENU_EXIT)
{
g_bIsSvgMenuOpened[id] = false
g_bIsSpawningCar[id] = false
g_bHasSpawned[id] = false
remove_preview(id)
RemoveSavages(id)
menu_destroy(iMenu)
return
}
switch (iItem)
{
case 0:
{
if (g_CanPlaced[id] == 2)
{
client_printcolor(id, "!y[!gLgK!y] You can't place Remote car here.")
set_task(0.1,"OpenSavageMenu", id)
}
SpawnSavage(id)
zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + -60)
OpenSavageMenu(id)
while ((iEntity = engfunc(EngFunc_FindEntityByString, iEntity, "classname", SAVAGE_CLASSNAME)) != 0)
engfunc(EngFunc_RemoveEntity, iEntity)
}
case 1:
{
if (g_bHasSpawned[id])
TakeSavageBack(id),
OpenSavageMenu(id)
else
client_printcolor(id, "!y[!gLgK!y] You haven't spawned any remote cars"),
OpenSavageMenu(id)
}
}
g_bIsSvgMenuOpened[id] = false
menu_destroy(iMenu)
}
public zp_fw_gamemodes_end()
{
new iEntity = FM_NULLENT
iTeamLimit = 0
while ((iEntity = engfunc(EngFunc_FindEntityByString, iEntity, "classname", "rcbomb")) != 0)
engfunc(EngFunc_RemoveEntity, iEntity)
while ((iEntity = engfunc(EngFunc_FindEntityByString, iEntity, "classname", SAVAGE_CLASSNAME)) != 0)
engfunc(EngFunc_RemoveEntity, iEntity)
for (new id = 1; id <= get_maxplayers(); id++)
{
if (!is_user_connected(id))
continue
g_iSavageEntity[id] = g_iSavageCamEntity[id] = FM_NULLENT
g_iHasSavage[id] = 0
gAlreadyBought[id] = 0
g_bIsSpawningCar[id] = g_bHasSpawned[id] = false
remove_preview(id)
}
}
public zp_fw_core_infect_post(id, attacker_id)
{
if (is_user_connected(id))
RemoveSavages(id)
if (g_pBeam[id] && pev_valid(g_pBeam[id]))
engfunc(EngFunc_RemoveEntity, g_pBeam[id]);
}
TakeSavageBack(id)
{
if (!is_user_alive(id) || zp_core_is_zombie(id))
return PLUGIN_CONTINUE
if (!g_bHasSpawned[id])
{
zp_colored_print(id, "You don't have any Remote cars")
RemoveSavages(id)
return PLUGIN_HANDLED
}
RemoveSavages(id)
g_iHasSavage[id] += 1
g_bIsSpawningCar[id] = false
client_printcolor(id, "!y[!gLgK!y] You took your Remote car back")
return PLUGIN_CONTINUE
}
public CreateFakeSavage(id)
{
if (g_pBeam[id] && is_valid_ent(g_pBeam[id]))
remove_entity(g_pBeam[id]);
new iSB = create_entity("info_target")
if (!iSB)
return;
static Float:vecAngles[3], Float:vecOrigin[3]
engfunc(EngFunc_SetModel, iSB, modelname)
engfunc(EngFunc_SetSize, iSB, {-4.0, -4.0, 0.0}, {4.0, 4.0, 4.0})
GetOriginAimEndEyes(id, 128, vecOrigin, vecAngles)
engfunc(EngFunc_SetOrigin, iSB, vecOrigin);
set_pev(iSB, pev_classname, SAVAGE_CLASSNAME);
set_pev(iSB, pev_owner, id);
set_pev(iSB, pev_rendermode, kRenderTransAdd);
set_pev(iSB, pev_renderamt, 200.0);
set_pev(iSB, pev_body, 1);
set_pev(iSB, pev_frame, 1)
set_pev(iSB, pev_sequence, 0)
set_pev(iSB, pev_framerate, 1)
set_pev(iSB, pev_takedamage, 0.0)
set_pev(iSB, pev_controller_0, 125)
set_pev(iSB, pev_controller_1, 125)
set_pev(iSB, pev_controller_2, 125)
set_pev(iSB, pev_nextthink, get_gametime());
set_pev(iSB,pev_movetype,MOVETYPE_FLYMISSILE); // Movestep <- for Preview
new pBeam = Beam_Create("sprites/laserbeam.spr", 6.0);
if (pBeam != FM_NULLENT)
{
Beam_EntsInit(pBeam, iSB, id);
Beam_SetColor(pBeam, Float:{150.0, 0.0, 0.0});
Beam_SetScrollRate(pBeam, 255.0);
Beam_SetBrightness(pBeam, 200.0);
}
else
{
pBeam = 0;
}
g_pBeam[id] = pBeam;
g_pSB[id] = iSB;
}
public SpawnSavage(id)
{
if (!is_user_alive(id) || zp_core_is_zombie(id))
return PLUGIN_CONTINUE
new SavEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
set_pev(SavEnt, pev_classname, "rcbomb");
if (!pev_valid(SavEnt))
return PLUGIN_HANDLED
static Float:vecAngles[3], Float:vecOrigin[3]
GetOriginAimEndEyes(id, 128, vecOrigin, vecAngles)
engfunc(EngFunc_SetModel, SavEnt, modelname)
engfunc(EngFunc_SetSize, SavEnt, {-4.0, -4.0, 0.0}, {4.0, 4.0, 4.0})
engfunc(EngFunc_SetOrigin, SavEnt, vecOrigin);
set_pev(SavEnt, pev_framerate, 0.0)
set_pev(SavEnt, pev_solid, SOLID_SLIDEBOX)
set_pev(SavEnt, pev_movetype, MOVETYPE_PUSHSTEP)
set_pev(SavEnt, pev_friction, 0.0000001)
set_pev(SavEnt, pev_takedamage, 1.0)
set_pev(SavEnt, pev_health, get_pcvar_float(g_pCvarSavageCarHP))
set_pev(SavEnt, pev_sequence, 0)
set_pev(SavEnt, pev_framerate, 0)
set_pev(SavEnt, pev_framerate, 20.0)
set_pev(SavEnt, pev_frame, 0)
set_pev(SavEnt, pev_controller_0, 125)
set_pev(SavEnt, pev_controller_1, 125)
set_pev(SavEnt, pev_controller_2, 125)
set_pev(SavEnt, pev_body, random_num(2, 12));
g_iHasSavage[id] -= 1
g_bHasSpawned[id] = true
g_bIsSpawningCar[id] = false
remove_preview(id)
RegisterHamFromEntity(Ham_TakeDamage, SavEnt, "Ham_SavageTakeDamage_Pre", false)
RegisterHamFromEntity(Ham_TakeDamage, SavEnt, "Ham_SavageTakeDamage_Post", true)
new Float:StartAngle[3]
static szNameCheck[32]
pev(id, pev_classname, szNameCheck, charsmax(szNameCheck))
if (!equal("rcbomb", szNameCheck))
pev(id, pev_angles, StartAngle)
//StartAngle[1] = 270.0
//StartAngle[0] = 90.0 //get_pcvar_float(g_pcvarSavageAngel)
StartAngle[0] = 0.0
set_pev(SavEnt, pev_angles, StartAngle)
set_pev(SavEnt, pev_v_angle, StartAngle)
set_pev(SavEnt, pev_nextthink, halflife_time() + 0.01)
Camera(id, StartAngle)
new Float:time = halflife_time()
fSavages[id][eLastTime] = time
fSavages[id][eNextSoundTime] = time
fSavages[id][eNextPitchTime] = time
Accel = get_pcvar_float(g_pCvarAccel)
MaxForce = get_pcvar_float(g_pCvarMaxForce)
MaxGrip = get_pcvar_float(g_pCvarMaxGrip)
MaxGrip *= MaxGrip
Drag = get_pcvar_float(g_pCvarDrag)
if (MaxGrip > 1.0) MaxGrip = 1.0
if (Drag > 1.0) Drag = 1.0
Gravity = get_cvar_num("sv_gravity")
ExecuteHamB(Ham_Player_ResetMaxSpeed, id)
set_rendering(SavEnt)
//fm_drop_to_floor(SavEnt)
//g_bHasSpawned[id] = true
new szName[32]
get_user_name(id, szName, charsmax(szName))
//ColorChat(0,GREEN,"^03 %s ^01 Spawned a ^04 Race Car", szName)
client_printcolor(0, "!y[!gLgK!y] !g%s !ySpawned Race Car", szName)
SavEnt = g_iSavageEntity[id]
return PLUGIN_HANDLED
}
public Camera(id, Float:StartAngle[3])
{
if (get_pcvar_num(g_pCvarChaseCam))
{
new CamEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
if (!pev_valid(CamEnt))
return PLUGIN_HANDLED
g_iSavageCamEntity[id] = CamEnt
set_pev(CamEnt, pev_classname, "camera")
set_pev(CamEnt, pev_owner, id)
set_pev(CamEnt, pev_rendermode, kRenderTransColor)
engfunc(EngFunc_SetModel, CamEnt, "models/rpgrocket.mdl")
set_pev(CamEnt, pev_solid, SOLID_NOT)
set_pev(CamEnt, pev_movetype, MOVETYPE_NOCLIP)
set_pev(CamEnt, pev_angles, StartAngle)
new Float:StartOrigin[3], Float:Angle = StartAngle[1] / 180 * M_PI
pev(id, pev_origin, StartOrigin)
StartOrigin[0] -= floatcos(Angle) * 110
StartOrigin[1] -= floatsin(Angle) * 110
StartOrigin[2] += 50
set_pev(CamEnt, pev_origin, StartOrigin)
set_pev(CamEnt, pev_nextthink, halflife_time() + 0.05)
attach_view(id, CamEnt)
}
return PLUGIN_CONTINUE
}
public client_PreThink(id)
{
if (!is_user_alive(id) || zp_core_is_zombie(id))
return
if (pev(id, pev_button) & IN_ATTACK && g_bHasSpawned[id] && !g_bIsSvgMenuOpened[id] && g_iSavageEntity[id])
DamageNearby(g_iSavageEntity[id])
}
DamageNearby(iEntity)
{
static Float:origin[3], Float:originVictim[3]
pev(iEntity, pev_origin, origin)
new ownerid = pev(iEntity, pev_owner)
if (!pev_valid(g_iSavageEntity[ownerid]))
return;
new Float:distance_diff, victim = -1
while ((victim = engfunc(EngFunc_FindEntityInSphere, victim, origin, get_pcvar_float(g_pCvarSavageRadius))) != 0)
{
if (!is_user_connected(victim))
continue
if (!is_user_alive(victim) || !zp_core_is_zombie(victim) || zp_item_zombie_madness_get(victim))
continue
pev(victim, pev_origin, originVictim)
distance_diff = get_distance_f(origin, originVictim)
if (get_user_health(victim) > 0)
{
ExecuteHam(Ham_TakeDamage, victim, iEntity, ownerid, (get_pcvar_float(g_pCvarSavageDamage) - distance_diff), DMG_GRENADE)
Set_Knockback(victim, origin, (get_pcvar_float(g_pCvarSavageKnockback) - distance_diff))
log_kill(ownerid, victim, "rcbomb_exp", 0)
}
else
ExecuteHam(Ham_Killed, victim, ownerid)
}
DestroySavage(ownerid, true)
}
stock log_kill(killer, victim, weapon[], headshot)
{
// code from MeRcyLeZZ
set_msg_block(get_user_msgid("DeathMsg"), BLOCK_SET)
ExecuteHamB(Ham_Killed, victim, killer, 2) // set last param to 2 if you want victim to gib
set_msg_block(get_user_msgid("DeathMsg"), BLOCK_NOT)
message_begin(MSG_BROADCAST, get_user_msgid("DeathMsg"))
write_byte(killer)
write_byte(victim)
write_byte(headshot)
write_string(weapon)
message_end()
//
if(get_user_team(killer)!=get_user_team(victim))
set_user_frags(killer,get_user_frags(killer) +1)
if(get_user_team(killer)==get_user_team(victim))
set_user_frags(killer,get_user_frags(killer) -1)
new kname[32], vname[32], kauthid[32], vauthid[32], kteam[10], vteam[10]
get_user_name(killer, kname, 31)
get_user_team(killer, kteam, 9)
get_user_authid(killer, kauthid, 31)
get_user_name(victim, vname, 31)
get_user_team(victim, vteam, 9)
get_user_authid(victim, vauthid, 31)
log_message("^"%s<%d><%s><%s>^" killed ^"%s<%d><%s><%s>^" with ^"%s^"",
kname, get_user_userid(killer), kauthid, kteam,
vname, get_user_userid(victim), vauthid, vteam, weapon)
return PLUGIN_CONTINUE;
}
Set_Knockback(ent, Float:VicOrigin[3], Float:speed)
{
static Float:fl_Velocity[3]
static Float:EntOrigin[3]
pev(ent, pev_origin, EntOrigin)
static Float:distance_f
distance_f = get_distance_f(EntOrigin, VicOrigin)
new Float:fl_Time = distance_f / speed
fl_Velocity[0] = ((EntOrigin[0] - VicOrigin[0]) / fl_Time) * 1.5
fl_Velocity[1] = ((EntOrigin[1] - VicOrigin[1]) / fl_Time) * 1.5
fl_Velocity[2] = (EntOrigin[2] - VicOrigin[2]) / fl_Time
set_pev(ent, pev_velocity, fl_Velocity)
}
public client_disconnect(id)
{
DestroySavage(id)
}
DestroySavage(id, bool:effect = false)
{
if (pev_valid(g_iSavageCamEntity[id]))
{
if (is_user_alive(id))
attach_view(id, id)
engfunc(EngFunc_RemoveEntity, g_iSavageCamEntity[id])
g_iSavageCamEntity[id] = -1
remove_preview(id)
}
if (effect)
{
if (!pev_valid(g_iSavageEntity[id]))
return
new Float:vOrigin[3]
pev(g_iSavageEntity[id], pev_origin, vOrigin)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(3)
write_coord(floatround(vOrigin[0]))
write_coord(floatround(vOrigin[1]))
write_coord(floatround(vOrigin[2] + 10))
write_short(boom)
write_byte(40)
write_byte(15)
write_byte(0)
message_end()
}
if (pev_valid(g_iSavageEntity[id]))
{
emit_sound(g_iSavageEntity[id], CHAN_VOICE, "zombie_plague/savage_engine.wav", VOL_NORM, ATTN_NORM, SND_STOP, PITCH_NORM)
engfunc(EngFunc_RemoveEntity, g_iSavageEntity[id])
g_iSavageEntity[id] = -1
}
g_bHasSpawned[id] = false
set_user_maxspeed(id, 250.0)
}
RemoveSavages(id)
{
if (!is_user_connected(id))
return
DestroySavage(id)
}
public savage_think(SavEnt)
{
new SavID = pev(SavEnt, pev_owner)
if (!is_user_alive(SavID) || zp_core_is_zombie(SavID))
{
RemoveSavages(SavID)
return
}
static Float:vecColor[3]
new Float:FrameTime = (halflife_time() - fSavages[SavID][eLastTime])
fSavages[SavID][eLastTime] = halflife_time()
new Float:vOrigin[3]
pev(SavEnt, pev_origin, vOrigin)
xs_vec_set(vecColor, 250.0, 0.0, 0.0);
// Health handling
if (pev(SavEnt, pev_health) < 0.0)
{
DestroySavage(SavID, true)
client_print(SavID, print_center, "Your Car got destroyed")
return
}
if (g_pBeam[SavID] && is_valid_ent(g_pBeam[SavID]))
{
Beam_RelinkBeam(g_pBeam[SavID]);
Beam_SetColor(g_pBeam[SavID], vecColor);
}
new Float:vVelocity[3]
pev(SavEnt, pev_velocity, vVelocity)
// That stupid collision box gets stuck behind every little bump , so force it to keep moving
vVelocity[0] = fSavages[SavID][eVelocity_x] * 0.8 + vVelocity[0] * 0.2
vVelocity[1] = fSavages[SavID][eVelocity_y] * 0.8 + vVelocity[1] * 0.2
// Input handling
new buttonpress = 0
if (g_iSavageCamEntity[SavID] && g_iSavageEntity[SavID])
buttonpress = pev(SavID, pev_button)
new Float:EngineForce = fSavages[SavID][eEngineForce]
new Float:TurnAngle = fSavages[SavID][eTurnAngle]
new Float:BrakeForce = 0.0
new Float:JumpForce = fSavages[SavID][eJumpForce]
if (buttonpress & IN_ATTACK2 && JumpForce > -1.0) // Jump
{
JumpForce += 5.0 * FrameTime
if (JumpForce > 3.0) JumpForce = 3.0
}
else if (buttonpress & IN_FORWARD) // Forward
{
EngineForce += Accel * FrameTime
if (EngineForce > MaxForce)
EngineForce = MaxForce
}
else if (buttonpress & IN_BACK) // Back
{
EngineForce -= Accel * FrameTime
if (EngineForce < MaxForce * -0.7)
EngineForce = MaxForce * -0.7
}
else
EngineForce = 0.0
if (buttonpress & IN_MOVELEFT) // Left
{
TurnAngle += 1.5 * FrameTime
if (TurnAngle > 0.5)
TurnAngle = 0.5
}
else if (buttonpress & IN_MOVERIGHT) // Right
{
TurnAngle -= 1.5 * FrameTime
if (TurnAngle < -0.5)
TurnAngle = -0.5
}
else
{
if (floatabs(TurnAngle) < 0.2)
TurnAngle = 0.0
else if (TurnAngle > 0.0)
TurnAngle -= 1.5 * FrameTime
else if (TurnAngle < 0.0)
TurnAngle += 1.5 * FrameTime
}
// dynamics handling
new Float:vAngles[3]
pev(SavEnt, pev_angles, vAngles)
new Float:Angle = vAngles[1] / 180 * M_PI
new Float:Speed = floatsqroot( vVelocity[0]*vVelocity[0] +vVelocity[1]*vVelocity[1] )
new Float:VelocityAngle = floatatan2( vVelocity[1], vVelocity[0], radian )
new Float:Grip = 0.0
new Float:Accel_x = -1 * Drag * vVelocity[0]
new Float:Accel_y = -1 * Drag * vVelocity[1]
new Float:vAVelocity[3]
pev(SavEnt, pev_avelocity, vAVelocity)
if (!pev(SavEnt, pev_flags))
{
// Set angle startpoint for stunts calculations
if (JumpForce > -1.0 && !(buttonpress & IN_ATTACK2))
{
set_pev(SavEnt, pev_startpos, vAngles)
JumpForce = -1.0
}
set_pev(SavEnt, pev_endpos, vAngles)
if (buttonpress & IN_FORWARD)
{
vAVelocity[0] += 800.0 * FrameTime
if (vAVelocity[0] > 500.0)
vAVelocity[0] = 500.0
}
else if (buttonpress & IN_BACK)
{
vAVelocity[0] -= 800.0 * FrameTime
if (vAVelocity[0] < -500.0)
vAVelocity[0] = -500.0
}
else
{
if (floatabs(vAVelocity[0]) < 80.0)
vAVelocity[0] = 0.0
else if (vAVelocity[0] > 0.0)
vAVelocity[0] -= 800.0 * FrameTime
else if (vAVelocity[0] < 0.0)
vAVelocity[0] += 800.0 * FrameTime
}
if (buttonpress & IN_MOVELEFT)
{
vAVelocity[1] += 800.0 * FrameTime * dSavages[SavID][eDirection]
if (vAVelocity[1] > 500.0)
vAVelocity[1] = 500.0
}
else if (buttonpress & IN_MOVERIGHT)
{
vAVelocity[1] -= 800.0 * FrameTime * dSavages[SavID][eDirection]
if (vAVelocity[1] < -500.0)
vAVelocity[1] = -500.0
}
else
{
if (floatabs(vAVelocity[1]) < 80.0)
vAVelocity[1] = 0.0
else if (vAVelocity[1] > 0.0)
vAVelocity[1] -= 800.0 * FrameTime
else if (vAVelocity[1] < 0.0)
vAVelocity[1] += 800.0 * FrameTime
}
}
else if ((pev(SavEnt, pev_flags) & FL_INWATER) && (engfunc(EngFunc_PointContents, vOrigin) == CONTENTS_SKY))
{
new Float:vBump[3]
vBump[0] = vOrigin[0] - vVelocity[0] * FrameTime
vBump[1] = vOrigin[1] - vVelocity[1] * FrameTime
vBump[2] = vOrigin[2] - vVelocity[2] * FrameTime
set_pev(SavEnt, pev_origin, vBump)
vVelocity[0] *= -0.5
vVelocity[1] *= -0.5
vVelocity[2] *= -0.5
set_pev(SavEnt, pev_velocity, vVelocity)
}
else
{
if (floatcos(vAngles[0], degrees) < -0.1) // Upside down in the ground, so crashed
{
TakeSavageBack(SavID)
client_print(SavID, print_center, "Your car was almost crashed, write /rc to spawn it again")
return
}
// Just landed, check stunts
if (JumpForce < 0.0)
JumpForce = 0.0
if (Speed > 0.1)
Grip = floatsin(Angle - VelocityAngle)
new Float:TireGrip = Grip
if (TireGrip < MaxGrip*-1.0) TireGrip = MaxGrip*-1.0
else if (TireGrip > MaxGrip) TireGrip = MaxGrip
// 3-speed gearbox
if (Speed > MaxForce * 1.1)
{
if(fSavages[SavID][eGear] < 1.5)
EngineForce *= 0.5
fSavages[SavID][eGear] = 1.6
TireGrip *= 0.6
}
else if (Speed > MaxForce * 0.7 && Speed < MaxForce * 0.9)
{
if (fSavages[SavID][eGear] < 1.2 || fSavages[SavID][eGear] > 1.4 )
EngineForce *= 0.5
fSavages[SavID][eGear] = 1.3
TireGrip *= 0.8
}
else if (Speed < MaxForce * 0.5)
fSavages[SavID][eGear] = 1.0
// Check direction the car is going
if (floatcos(Angle - VelocityAngle) > 0.0)
dSavages[SavID][eDirection] = 1
else
dSavages[SavID][eDirection] = -1
//Acceleration
Accel_x += floatcos(Angle) * EngineForce * fSavages[SavID][eGear]
Accel_y += floatsin(Angle) * EngineForce * fSavages[SavID][eGear]
//Braking
Accel_x -= floatcos(Angle) * BrakeForce * Speed * dSavages[SavID][eDirection]
Accel_y -= floatsin(Angle) * BrakeForce * Speed * dSavages[SavID][eDirection]
//Sideways friction ( drifting)
Accel_x -= floatcos( Angle - M_PI/2 ) * TireGrip * Speed * 10 // Cheap but working tracktion
Accel_y -= floatsin( Angle - M_PI/2 ) * TireGrip * Speed * 10
new Float:vNewAngle[3]
vector_to_angle(vVelocity, vNewAngle)
vAngles[0] = vNewAngle[0] * dSavages[SavID][eDirection]
vVelocity[0] += Accel_x * FrameTime// * floatcos(CurAng[1], degrees)
vVelocity[1] += Accel_y * FrameTime// * floatcos(CurAng[1], degrees)
// Rotational force doesn't excists, but i got it right here :)
vAVelocity[0] = 0.0
vAVelocity[1] = Speed * floatsin(TurnAngle) * (1-floatabs(Grip)) * dSavages[SavID][eDirection]
vAVelocity[2] = 0.0
if (!(buttonpress & IN_ATTACK2) && JumpForce > 0.0)
{
vVelocity[2] += JumpForce * 100
JumpForce = 0.0
entity_set_byte(SavEnt, EV_BYTE_controller1, 127)
entity_set_byte(SavEnt, EV_BYTE_controller2, 127)
}
else
vVelocity[2] -= Gravity * FrameTime // To stop him from riding up the wall, almost
set_pev(SavEnt, pev_velocity, vVelocity)
entity_set_byte(SavEnt, EV_BYTE_controller1, floatround((EngineForce-Speed*0.1)/MaxForce *-32)+127)
entity_set_byte(SavEnt, EV_BYTE_controller2, floatround(TireGrip*(Speed/MaxForce)*32)+127)
}
entity_set_byte(SavEnt, EV_BYTE_controller3, floatround(TurnAngle*192)+127)
set_pev(SavEnt, pev_framerate, dSavages[SavID][eDirection]*Speed/100)
vAngles[0] += vAVelocity[0] * FrameTime
vAngles[1] += vAVelocity[1] * FrameTime
vAngles[2] += vAVelocity[2] * FrameTime
set_pev(SavEnt, pev_angles, vAngles)
set_pev(SavEnt, pev_avelocity, vAVelocity)
fSavages[SavID][eEngineForce] = EngineForce
fSavages[SavID][eTurnAngle] = TurnAngle
fSavages[SavID][eVelocity_x] = vVelocity[0]
fSavages[SavID][eVelocity_y] = vVelocity[1]
fSavages[SavID][eVelocity_z] = vVelocity[2]
fSavages[SavID][eJumpForce] = JumpForce
// sound
if(EngineForce > 0.2)
{
if (fSavages[SavID][eNextSoundTime] < halflife_time())
{
emit_sound(SavEnt, CHAN_VOICE, "zombie_plague/savage_engine.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
fSavages[SavID][eNextSoundTime] = halflife_time() + 0.5
}
else if(fSavages[SavID][eNextPitchTime] < halflife_time())
{
emit_sound(SavEnt, CHAN_VOICE, "zombie_plague/savage_engine.wav", VOL_NORM, ATTN_NORM, SND_CHANGE_PITCH, PITCH_NORM )
fSavages[SavID][eNextPitchTime] = halflife_time() + 0.1
}
}
if(Pev_Value[SavID] == 0)
{
static Float:StartAngle
pev(SavID, pev_angles, StartAngle)
set_pev(SavEnt, pev_angles, StartAngle)
// set_pev(SavEnt, pev_v_angle, StartAngle)
Pev_Value[SavID] = 1
}
set_pev(SavEnt, pev_nextthink, halflife_time() + 0.02)
}
public camera_think(CamEnt)
{
new SavID = pev(CamEnt, pev_owner)
if (!is_valid_ent(SavID)) return
new Float:TargetOrigin[3], Float:CameraOrigin[3], Float:CameraAngles[3]
pev(g_iSavageEntity[SavID], pev_origin, TargetOrigin)
pev(CamEnt, pev_origin, CameraOrigin)
pev(CamEnt, pev_angles, CameraAngles)
new Float:Direction[3], Float:Angles[3]
Direction[0] = (TargetOrigin[0] - CameraOrigin[0])
Direction[1] = (TargetOrigin[1] - CameraOrigin[1])
Direction[2] = (CameraOrigin[2] - TargetOrigin[2])
vector_to_angle(Direction, Angles)
Angles[0] -= CameraAngles[0]
Angles[1] -= CameraAngles[1]
Angles[0] = floatsin(Angles[0], degrees) * 500
Angles[1] = floatsin(Angles[1], degrees) * 500
set_pev(CamEnt, pev_avelocity, Angles)
new Float:Distance = (vector_distance(TargetOrigin, CameraOrigin) - 100) / 50
Direction[0] *= Distance
Direction[1] *= Distance
Direction[2] = (TargetOrigin[2] - CameraOrigin[2] + 50) * Distance
set_pev(CamEnt, pev_velocity, Direction)
if (g_iSavageCamEntity[SavID] && g_iSavageEntity[SavID])
set_pev(CamEnt, pev_nextthink, halflife_time() + 0.1)
}
public SB_Think(SandBag)
{
if (pev_valid(SandBag) != 2)
return;
static pOwner;
pOwner = pev(SandBag, pev_owner);
if (!(1 <= pOwner <= 32) || !is_user_alive(pOwner))
return;
static iBody, Float:vecColor[3], Float:vecAngles[3], Float:vecOrigin[3];
GetOriginAimEndEyes(pOwner, 128, vecOrigin, vecAngles);
iBody = 1
xs_vec_set(vecColor, 250.0, 0.0, 0.0);
engfunc(EngFunc_SetOrigin, SandBag, vecOrigin);
vecOrigin[2] -= 8.0;
if (!IsHullVacant(vecOrigin, HULL_HEAD, SandBag))
{
if(CheckSavage() || CheckSavageFake())
{
iBody = 0
xs_vec_set(vecColor, 0.0, 250.0, 0.0);
}
}
if (g_pBeam[pOwner] && is_valid_ent(g_pBeam[pOwner]))
{
Beam_RelinkBeam(g_pBeam[pOwner]);
Beam_SetColor(g_pBeam[pOwner], vecColor);
}
g_CanPlaced[pOwner] = iBody
set_pev(SandBag, pev_angles, vecAngles);
set_pev(SandBag, pev_body, iBody);
set_pev(SandBag, pev_nextthink, get_gametime() + 0.01);
return;
}
bool:IsHullVacant(const Float:vecSrc[3], iHull, pEntToSkip = 0)
{
engfunc(EngFunc_TraceHull, vecSrc, vecSrc, DONT_IGNORE_MONSTERS, iHull, pEntToSkip, 0);
return bool:(!get_tr2(0, TR_AllSolid) && !get_tr2(0, TR_StartSolid) && get_tr2(0, TR_InOpen));
}
GetOriginAimEndEyes(this, iDistance, Float:vecOut[3], Float:vecAngles[3])
{
static Float:vecSrc[3], Float:vecEnd[3], Float:vecViewOfs[3], Float:vecVelocity[3];
static Float:flFraction;
pev(this, pev_origin, vecSrc);
pev(this, pev_view_ofs, vecViewOfs);
xs_vec_add(vecSrc, vecViewOfs, vecSrc);
velocity_by_aim(this, iDistance, vecVelocity);
xs_vec_add(vecSrc, vecVelocity, vecEnd);
engfunc(EngFunc_TraceLine, vecSrc, vecEnd, DONT_IGNORE_MONSTERS, this, 0);
get_tr2(0, TR_flFraction, flFraction);
if (flFraction < 1.0)
{
static Float:vecPlaneNormal[3];
get_tr2(0, TR_PlaneNormal, vecPlaneNormal);
get_tr2(0, TR_vecEndPos, vecOut);
xs_vec_mul_scalar(vecPlaneNormal, 1.0, vecPlaneNormal);
xs_vec_add(vecOut, vecPlaneNormal, vecOut);
}
else
{
xs_vec_copy(vecEnd, vecOut);
}
vecVelocity[2] = 0.0;
vector_to_angle(vecVelocity, vecAngles);
}
public CheckSavage()
{
static victim
victim = -1
static Float:vecOrigin[3]
while ( ( victim = find_ent_in_sphere(victim,vecOrigin,float(42))) != 0 )
{
new sz_classname[32]
entity_get_string( victim , EV_SZ_classname , sz_classname, 31 )
if( !equali(sz_classname,"rcbomb") )
{
//our dude has sandbags and wants to place them near to him
if(is_user_connected(victim) && is_user_alive(victim))
return false;
}
}
return true
}
public CheckSavageFake()
{
static victim
victim = -1
static Float:vecOrigin[3]
while ( ( victim = find_ent_in_sphere(victim,vecOrigin,float(42))) != 0 )
{
new sz_classname[32]
entity_get_string( victim , EV_SZ_classname , sz_classname, 31 )
if( !equali(sz_classname, SAVAGE_CLASSNAME) )
{
//our dude has sandbags and wants to place them near to him
if(is_user_connected(victim) && is_user_alive(victim))
return false;
}
}
return true
}
public remove_preview(id)
{
if (g_pBeam[id] && pev_valid(g_pBeam[id]))
remove_entity(g_pBeam[id])
if (g_pSB[id] && pev_valid(g_pSB[id]))
remove_entity(g_pSB[id])
}
FClassnameIs(this, const szClassName[])
{
if (pev_valid(this) != 2)
return 0;
new szpClassName[32];
pev(this, pev_classname, szpClassName, charsmax(szpClassName));
return equal(szClassName, szpClassName);
}
stock client_printcolor(const id,const input[], any:...)
{
new msg[191], players[32], count = 1; vformat(msg,190,input,3);
replace_all(msg,190,"!g","^4"); // green
replace_all(msg,190,"!y","^1"); // normal
replace_all(msg,190,"!t","^3"); // team
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();
}
}
}