AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   entity goes to a random direction (https://forums.alliedmods.net/showthread.php?t=294507)

Adomaz1 02-28-2017 14:36

entity goes to a random direction
 
My entity sometimes goes where the HUD is, and that is what I want, and most of the time it goes to a random direction, what is the problem?

Code:

public MakeRock(id)
{
        new Float:Origin[3], Float:Velocity[3], Float:vAngle[3];
        new RockSpeed = get_pcvar_num(cvar_tank_rock_speed);

        entity_get_vector(id, EV_VEC_origin, Origin);
        entity_get_vector(id, EV_VEC_v_angle, vAngle);

        new NewEnt = create_entity("info_target");

        entity_set_string(NewEnt, EV_SZ_classname, "rock_ent")

        entity_set_model(NewEnt, rock_model)

        entity_set_size(NewEnt, Float:{-1.5, -1.5, -1.5}, Float:{1.5, 1.5, 1.5})

        entity_set_origin(NewEnt, Origin)
        entity_set_vector(NewEnt, EV_VEC_angles, vAngle)
        entity_set_int(NewEnt, EV_INT_solid, 2)

        entity_set_int(NewEnt, EV_INT_movetype, 5)
        entity_set_edict(NewEnt, EV_ENT_owner, id)

        velocity_by_aim(id, RockSpeed  , Velocity)
        entity_set_vector(NewEnt, EV_VEC_velocity ,Velocity)
       
        return PLUGIN_HANDLED
}


georgik57 02-28-2017 18:47

Re: entity goes to a random direction
 
Please search next time.

Quote:

Originally Posted by georgik57 (Post 2107188)
The rocket goes off the aim(doesn't go where I'm pointing my crosshair)
http://i40.tinypic.com/6z936p.jpg
Tried every possible method in the rocket firing function(different ways of getting the start and end origins), none fixed it.

EDIT: 2 years later, the first problem is solved.
The problem was that I was setting a higher velocity to the rocket entity than the sv_maxvelocity cvar value, as described here: https://github.com/ValveSoftware/halflife/issues/1723

PHP Code:

/*
To do:

T = needs testing
X = done
- = cancelled

[X] damageable entities that get hit take full damage
[T] make rockets not collide with other team rockets?
[T] make rockets not collide with non-solid entities?
[T] fix error log generated on invalid touched entity
[T] increase range in EngFunc_FindEntityInSphere
[T] make rockets destroy any damageable entity from other teams
[T] ignore cases where damage <= 0.0 instead of checking for distance
[T] make sure rockets don't destroy each other in case they're same team rockets
[T] emessage instead of message for death for more compatibility with other plugins
[T] rocket class name
[T] remove entities by class name
[T] ftFMEntityOriginGet model check
[T] user rpg class name on death message
[T] separate touched entity damage code
[T] make sure the player takes the full damage, then kill him
[T] only kill the player if he actually died from the rocket damage
[T] add support for damage modification by external sources
[T] get_user_team instead of cs_get_user_team
[T] fix crash related to when touching a trigger_multiple(or any other solid_trigger?) entity
    [ ] see why it is happening
[T] float velocity_by_aim
    [ ] map entities can have studio models too...
[-] only kill the player if the remaining hp is 1.0, otherwise restore old hp
[ ] cache as many things as possible and see if it increases touch rate
[ ] explode rocket after X time if it doesn't hit anything
[ ] 
*/

#include <amxmodx>
//#include <cstrike>
#include <fakemeta>
#include <hamsandwich>

#include <cs_ham_bots_api>

#include <bitsums>
#include <D7Debug>



enum
{
    
g_iIDModHL,
    
g_iIDModCS,
    
g_iIDModDOD
}

new 
g_iBsHasBazookag_iBsCanShootg_iBsConnectedg_iBsAliveg_iIDPCVarSvMaxVelocity;

const 
g_iIDEntityRocketPev pev_iuser4;
const 
g_iIDEntityRocket 7575;

new const 
g_szClassNameRocket[] = "D7RPG";

new const 
g_szEntityRocketModel[] = "models/rpgrocket.mdl";
new const 
ROCKET_SOUND[] = "weapons/rocketfire1.wav";

new 
g_iIDCacheSpriteRocketTrailexplosionwhite;

new 
CVar_RocketDelayCVar_RocketSpeed,
CVar_RocketDmgCVar_Dmg_range;

new 
g_iMaxPlayersg_iIDMsgDeathg_iIDMod;

public 
plugin_precache()
{
    
precache_model(g_szEntityRocketModel)
    
    
g_iIDCacheSpriteRocketTrail precache_model("sprites/smoke.spr");
    
explosion precache_model("sprites/zerogxplode.spr")
    
white precache_model("sprites/white.spr")
    
    
precache_sound(ROCKET_SOUND)
}

public 
plugin_init()
{
    
register_plugin("D7 API RPG""0.2.0""D i 5 7 i n c T")
    
    
RegisterHam(Ham_Spawn"player""fwHamSpawnPlayer"1)
    
RegisterHamBots(Ham_Spawn"fwHamSpawnPlayer"1)
    
//RegisterHam(Ham_TakeDamage, "player", "fwHamTakeDamagePlayerPre")
    //RegisterHamBots(Ham_TakeDamage, "fwHamTakeDamagePlayerPre")
    //RegisterHam(Ham_TakeDamage, "player", "fwHamTakeDamagePlayer", 1)
    //RegisterHamBots(Ham_TakeDamage, "fwHamTakeDamagePlayer", 1)
    
RegisterHam(Ham_Killed"player""fwHamKilledPlayerPre")
    
RegisterHamBots(Ham_Killed"fwHamKilledPlayerPre")
    
    
register_forward(FM_Touch"fwFmTouch"1)
    
register_forward(FM_PlayerPreThink"fwFmPlayerPreThink"1)
    
    
register_clcmd("say /b""fwClCmdSayB")
    
    
g_iIDPCVarSvMaxVelocity get_cvar_pointer("sv_maxvelocity");
    
    
CVar_RocketDelay register_cvar("D7RPGDelay""0.1")
    
CVar_RocketSpeed register_cvar("D7RPGSpeed""970")
    
CVar_RocketDmg register_cvar("D7RPGDamage""5")
    
CVar_Dmg_range register_cvar("D7RPGDamageRadius""240")
    
    
g_iMaxPlayers get_maxplayers();
    
g_iIDMsgDeath get_user_msgid("DeathMsg");
    
    
//register_message(g_iIDMsgDeath, "fwMsgDeathPre")
    
    
new szModName[32];
    
get_modname(szModNamecharsmax(szModName));
    
    if (
equali(szModName"cstrike") || equali(szModName"czero") || equali(szModName"csv15") || equali(szModName"cs13"))
        
g_iIDMod g_iIDModCS;
    else if (
equali(szModName"dod"))
        
g_iIDMod g_iIDModDOD;
    else
        
g_iIDMod g_iIDModHL;
}
/*
// After fwHamKilledPlayerPre
// Before fwHamKilledPlayer
public fwMsgDeathPre(const iIDMsg, const iMsgDest, const iIDEnt)
{
    new iIDAttacker = get_msg_arg_int(1),
    iIDVictim = get_msg_arg_int(2);
    
    ftD7Log(_, _, "[fwMsgDeathPre] iIDAttacker: %d. iIDVictim: %d.", iIDAttacker, iIDVictim)
}*/

ftEntityRocketRemove(const iIDOwner 0)
{
    new 
iIDEntity = -1;
    
    
//while ((iIDEntity = engfunc(EngFunc_FindEntityInSphere, iIDEntity, Float:{ 0.0, 0.0, 0.0 }, 99999.0)) != 0)
    
while ((iIDEntity engfunc(EngFunc_FindEntityByStringiIDEntity"classname"g_szClassNameRocket)) != 0)
    {
        if (!
pev_valid(iIDEntity)
        
//|| pev(iIDEntity, g_iIDEntityRocketPev) != g_iIDEntityRocket
        
|| iIDOwner && iIDOwner != pev(iIDEntitypev_owner))
            continue;
        
        
engfunc(EngFunc_RemoveEntityiIDEntity)
    }
}

public 
client_putinserver(iID)
{
    
bitsum_add(g_iBsConnectediID)
}

public 
client_disconnect(iID)
{
    
ftEntityRocketRemove(iID)
    
    
remove_task(iID)
    
    
bitsum_del(g_iBsHasBazookaiID)
    
bitsum_del(g_iBsCanShootiID)
    
bitsum_del(g_iBsConnectediID)
    
bitsum_del(g_iBsAliveiID)
}

public 
fwHamSpawnPlayer(const iID)
{
    
//remove_task(iID)
    
    //bitsum_del(g_iBsHasBazooka, iID)
    //bitsum_del(g_iBsCanShoot, iID)
    
    
if (!is_user_alive(iID))
        return;
    
    
bitsum_add(g_iBsAliveiID)
}

public 
fwHamKilledPlayerPre(const iID)
{
    
remove_task(iID)
    
    
bitsum_del(g_iBsHasBazookaiID)
    
bitsum_del(g_iBsCanShootiID)
    
bitsum_del(g_iBsAliveiID)
}

public 
fwClCmdSayB(const iID)
{
    if (!
bitsum_get(g_iBsHasBazookaiID))
    {
        
bitsum_add(g_iBsHasBazookaiID)
        
fwTaskCanShoot(iID)
    }
    else
    {
        
ftEntityRocketRemove(iID)
        
        
remove_task(iID)
        
        
bitsum_del(g_iBsHasBazookaiID)
        
bitsum_del(g_iBsCanShootiID)
    }
}
/*
new g_iBsDeath;

public fwHamTakeDamagePlayerPre(const iIDEntity, const iIDInflictor, const iIDAttacker, Float:fDamage, const iBsDamageType)
{
    if (iBsDamageType != DMG_BLAST)
    {
        ftD7Log(_, _, "[fwHamTakeDamagePlayerPre] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. Damage type is not DMG_BLAST.", iIDEntity, iIDInflictor, iIDAttacker)
        
        return;
    }
    else if (GetHamReturnStatus() == HAM_SUPERCEDE)
    {
        ftD7Log(_, _, "[fwHamTakeDamagePlayerPre] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. Damage has been blocked.", iIDEntity, iIDInflictor, iIDAttacker)
        
        return;
    }
    else if (!pev_valid(iIDInflictor))
    {
        ftD7Log(_, _, "[fwHamTakeDamagePlayerPre] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. Inflictor is invalid.", iIDEntity, iIDInflictor, iIDAttacker)
        
        return;
    }
    else if (pev(iIDInflictor, g_iIDEntityRocketPev) != g_iIDEntityRocket)
    {
        ftD7Log(_, _, "[fwHamTakeDamagePlayerPre] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. Inflictor is not a rocket.", iIDEntity, iIDInflictor, iIDAttacker)
        
        return;
    }
    else if (get_user_health(iIDEntity) - floatround(fDamage, floatround_floor) > 0)
    {
        ftD7Log(_, _, "[fwHamTakeDamagePlayerPre] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. Health: %d. Damage: %d. NOT a kill.", iIDEntity, iIDInflictor, iIDAttacker, get_user_health(iIDEntity), floatround(fDamage, floatround_floor))
        
        return;
    }
    
    //ftD7Log(_, _, "[fwHamTakeDamagePlayerPre] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. Health: %d. Damage: %d. KILL.", iIDEntity, iIDInflictor, iIDAttacker, get_user_health(iIDEntity), floatround(fDamage, floatround_floor))
    
    bitsum_add(g_iBsDeath, iIDEntity)
    
    set_pev(iIDEntity, pev_health, fDamage + 1.0)
}

public fwHamTakeDamagePlayer(const iIDEntity, const iIDInflictor, const iIDAttacker, Float:fDamage, const iBsDamageType)
{
    if (iBsDamageType != DMG_BLAST)
    {
        //ftD7Log(_, _, "[fwHamTakeDamagePlayer] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. Damage type is not DMG_BLAST.", iIDEntity, iIDInflictor, iIDAttacker)
        
        return;
    }
    else if (GetHamReturnStatus() == HAM_SUPERCEDE)
    {
        //ftD7Log(_, _, "[fwHamTakeDamagePlayer] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. Damage has been blocked.", iIDEntity, iIDInflictor, iIDAttacker)
        
        return;
    }
    else if (!pev_valid(iIDInflictor))
    {
        //ftD7Log(_, _, "[fwHamTakeDamagePlayer] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. Inflictor is invalid.", iIDEntity, iIDInflictor, iIDAttacker)
        
        return;
    }
    else if (pev(iIDInflictor, g_iIDEntityRocketPev) != g_iIDEntityRocket)
    {
        //ftD7Log(_, _, "[fwHamTakeDamagePlayer] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. Inflictor is not a rocket.", iIDEntity, iIDInflictor, iIDAttacker)
        
        return;
    }
    else if (!bitsum_get(g_iBsDeath, iIDEntity))
    {
        //ftD7Log(_, _, "[fwHamTakeDamagePlayer] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. NOT a kill.", iIDEntity, iIDInflictor, iIDAttacker)
        
        return;
    }
    
    ftD7Log(_, _, "[fwHamTakeDamagePlayer] iIDEntity: %d. iIDInflictor: %d. iIDAttacker: %d. Health: %d. Damage: %d. KILL.", iIDEntity, iIDInflictor, iIDAttacker, get_user_health(iIDEntity), floatround(fDamage, floatround_floor))
    
    new iTemp = get_msg_block(g_iIDMsgDeath);
    
    set_msg_block(g_iIDMsgDeath, BLOCK_ONCE)
    
    ExecuteHamB(Ham_Killed, iIDEntity, iIDAttacker, 2)
    
    set_msg_block(g_iIDMsgDeath, iTemp)
    
    ftMsgDeathSend(iIDAttacker, iIDEntity, g_szClassNameRocket, _, iIDInflictor)
}*/

// Credits to VEN
stock ftFMEntityOriginGet(const iIDEntityFloat:fVecTemp[3])
{
    new 
szModel[2];
    
pev(iIDEntitypev_modelszModelcharsmax(szModel))
    
    if (
szModel[0] == '*')
    {
        
pev(iIDEntitypev_minsfVecTemp)
        
        static 
Float:fVecTemp2[3];
        
        
pev(iIDEntitypev_maxsfVecTemp2);
        
        
fVecTemp[0] += fVecTemp2[0];
        
fVecTemp[1] += fVecTemp2[1];
        
fVecTemp[2] += fVecTemp2[2];
        
        
fVecTemp[0] *= 0.5;
        
fVecTemp[1] *= 0.5;
        
fVecTemp[2] *= 0.5;
        
        return;
    }
    
    
pev(iIDEntitypev_originfVecTemp)
}

ftMsgDeathSend(const iIDAttacker, const iIDVictim, const szNameWeapon[] = "", const bool:bHeadShot false, const iIDInflictor 0)
{
    
message_begin(MSG_ALLg_iIDMsgDeath)
    
write_byte(iIDAttacker)
    
write_byte(iIDVictim)
    
    if (
g_iIDMod == g_iIDModCS)
    {
        
write_byte(bHeadShot//headshot
        
write_string(szNameWeapon)
    }
    else if (
g_iIDMod == g_iIDModHL)
    {
        
write_string(szNameWeapon)
    }
    else if (
g_iIDMod == g_iIDModDOD)
    {
        
write_byte(iIDInflictor//weaponid
    
}
    
    
message_end()
}

public 
fwFmTouch(iIDEntityToucheriIDEntityTouched)
{
    new 
iIDEntityRocket;
    
    if (
pev_valid(iIDEntityToucher) && pev(iIDEntityToucherg_iIDEntityRocketPev) == g_iIDEntityRocket)
        
iIDEntityRocket iIDEntityToucher;
    else if (
pev_valid(iIDEntityTouched) && pev(iIDEntityTouchedg_iIDEntityRocketPev) == g_iIDEntityRocket)
    {
        
iIDEntityRocket iIDEntityTouched;
        
        
iIDEntityTouched iIDEntityToucher;
        
iIDEntityToucher iIDEntityRocket;
    }
    else
        return;
    
    new 
iIDEntityRocketOwner pev(iIDEntityRocketpev_owner);
    
    if (
iIDEntityTouched == iIDEntityRocketOwner)
        return;
    
    new 
iEntityRocketOwnerTeam get_user_team(iIDEntityRocketOwner),
    
iIDEntityOtherOwnerFloat:fCVarDamage get_pcvar_float(CVar_RocketDmg),
    
Float:fHealthiTempFloat:fDamage;
    
    static 
szEntityClassName[32];
    
    
// Pass through dead/same team players and team entities
    
if (<= iIDEntityTouched <= g_iMaxPlayers)
    {
        if (!
bitsum_get(g_iBsAliveiIDEntityTouched) || bitsum_get(g_iBsConnectediIDEntityTouched) && iEntityRocketOwnerTeam == get_user_team(iIDEntityTouched))
        {
            
ftD7Log(__"[fwFmTouch] Touched entity is an either dead or a connected and on the same team player as the rocket owner. Ignoring.")
            
            return;
        }
        
        if (
fCVarDamage 0.0)
        {
            
pev(iIDEntityTouchedpev_healthfHealth)
            
set_pev(iIDEntityTouchedpev_health10000000.0)
            
            
ExecuteHamB(Ham_TakeDamageiIDEntityTouchediIDEntityRocketiIDEntityRocketOwnerfCVarDamageDMG_BLAST)
            
            
fDamage 10000000.0 get_user_health(iIDEntityTouched);
            
            
ftD7Log(__"[fwFmTouch] fHealth: %f. fDamage: %f."fHealthfDamage)
            
            if (
fHealth fDamage)
            {
                
//if (fHealth < 1.0)
                //{
                //    ftD7Log(_, _, "[fwFmTouch] Player in explosion range has health between 0 and 1. fHealth: %f.", fHealth)
                //}
                
fHealth -= fDamage;
                
set_pev(iIDEntityTouchedpev_healthfHealth)
            }
            else
            {
                
ftD7Log(__"[fwFmTouch] Player hit should be dead. Executing Ham_Killed with custom death message.")
                
                
//set_pev(iIDEntityTouched, pev_health, 1.0)
                //ExecuteHam(Ham_Spawn, iIDEntityTouched)
                //engfunc(EngFunc_SetOrigin, iIDEntityTouched, fVecOriginEntityInSphere)
                
                
iTemp get_msg_block(g_iIDMsgDeath);
                
                
set_msg_block(g_iIDMsgDeathBLOCK_ONCE)
                
                
ExecuteHamB(Ham_KillediIDEntityTouchediIDEntityRocketOwner2)
                
                
set_msg_block(g_iIDMsgDeathiTemp)
                
                
ftMsgDeathSend(iIDEntityRocketOwneriIDEntityTouchedg_szClassNameRocket_iIDEntityRocket)
            }
        }
    }
    else if (
pev_valid(iIDEntityTouched))
    {
        if (
pev(iIDEntityTouchedpev_solid) <= SOLID_TRIGGER)
            return;
        
        
iIDEntityOtherOwner pev(iIDEntityTouchedpev_owner);
        
        if ((
<= iIDEntityOtherOwner <= g_iMaxPlayers) && bitsum_get(g_iBsConnectediIDEntityOtherOwner) && iEntityRocketOwnerTeam == get_user_team(iIDEntityOtherOwner))
            return;
        
        if (
fCVarDamage 0.0)
        {
            
pev(iIDEntityTouchedpev_healthfHealth)
            
            
//ftD7Log(_, _, "[fwFmTouch] iIDEntityRocket: %d. iIDEntityTouched: %d. Damage: %f. Health: %f.",
            //iIDEntityRocket, iIDEntityTouched, fCVarDamage, fHealth)
            
            
if (fHealth 0.0)
            {
                
pev(iIDEntityTouchedpev_takedamagefDamage)
                
                if (
fDamage != 0.0)
                {
                    
ExecuteHamB(Ham_TakeDamageiIDEntityTouchediIDEntityRocketiIDEntityRocketOwnerfCVarDamageDMG_BLAST)
                }
                else
                {
                    
pev(iIDEntityTouchedpev_classnameszEntityClassNamecharsmax(szEntityClassName))
                    
                    if (
equali(szEntityClassName"func_breakable"))
                        
ExecuteHamB(Ham_TakeDamageiIDEntityTouchediIDEntityRocketiIDEntityRocketOwnerfCVarDamageDMG_BLAST)
                }
            }
        }
        
        
pev(iIDEntityTouchedpev_classnameszEntityClassNamecharsmax(szEntityClassName))
        
ftD7Log(__"[fwFmTouch] iIDEntityToucher: %d. iIDEntityTouched: %d. iIDEntityRocket: %d. Touched class name: ^"%s^"."iIDEntityToucheriIDEntityTouchediIDEntityRocketszEntityClassName)
    }
    
    static 
Float:fVecOrigin[3], Float:fVecOriginEntityInSphere[3];
    
    
pev(iIDEntityRocketpev_originfVecOrigin)
    
    new 
iIDEntityInSphere = -1Float:fCVarRadius get_pcvar_float(CVar_Dmg_range);
    
    
//ftD7Log(_, _, "[fwFmTouch] iIDEntityRocket: %d. fVecOrigin: %f, %f, %f.", iIDEntityRocket, fVecOrigin[0], fVecOrigin[1], fVecOrigin[2])
    
    
while ((iIDEntityInSphere engfunc(EngFunc_FindEntityInSphereiIDEntityInSpherefVecOriginfCVarRadius)) != 0)
    {
        if (
iIDEntityInSphere == iIDEntityRocket
        
|| iIDEntityInSphere == iIDEntityRocketOwner
        
|| iIDEntityInSphere == iIDEntityTouched)
            continue;
        
        
//pev(iIDEntityInSphere, pev_classname, szEntityClassName, charsmax(szEntityClassName))
        //ftD7Log(_, _, "[fwFmTouch] iIDEntityInSphere: %d. Class name: ^"%s^".", iIDEntityInSphere, szEntityClassName)
        
        
if (<= iIDEntityInSphere <= g_iMaxPlayers)
        {
            if (!
bitsum_get(g_iBsAliveiIDEntityInSphere)
            || 
iEntityRocketOwnerTeam == get_user_team(iIDEntityInSphere))
                continue;
            
            
pev(iIDEntityInSpherepev_originfVecOriginEntityInSphere)
            
            
fDamage fCVarDamage - (fCVarDamage fCVarRadius get_distance_f(fVecOriginfVecOriginEntityInSphere));
            
            
//ftD7Log(_, _, "[fwFmTouch] iIDEntityRocket: %d. iIDEntityInSphere: %d. fVecOriginEntityInSphere: %f, %f, %f. Damage: %f.",
            //iIDEntityRocket, iIDEntityInSphere, fVecOriginEntityInSphere[0], fVecOriginEntityInSphere[1], fVecOriginEntityInSphere[2], fDamage)
            //ftD7Log(_, _, "[fwFmTouch] iIDEntityRocket: %d. iIDEntityInSphere: %d. Damage: %f.",
            //iIDEntityRocket, iIDEntityInSphere, fDamage)
            
            
if (fDamage 1.0)
                continue;
            
/*
            engfunc(EngFunc_MessageBegin, MSG_ALL, SVC_TEMPENTITY, fVecOrigin, 0)
            write_byte(TE_LIGHTNING)
            engfunc(EngFunc_WriteCoord, fVecOrigin[0])
            engfunc(EngFunc_WriteCoord, fVecOrigin[1])
            engfunc(EngFunc_WriteCoord, fVecOrigin[2])
            engfunc(EngFunc_WriteCoord, fVecOriginEntityInSphere[0])
            engfunc(EngFunc_WriteCoord, fVecOriginEntityInSphere[1])
            engfunc(EngFunc_WriteCoord, fVecOriginEntityInSphere[2])
            write_byte(25) //life in 0.1's
            write_byte(25) //width in 0.1's
            write_byte(0) //amplitude in 0.01's
            write_short(g_iIDCacheSpriteRocketTrail) //sprite model index
            message_end()*/
            
            
pev(iIDEntityInSpherepev_healthfHealth)
            
set_pev(iIDEntityInSpherepev_health10000000.0)
            
            
ExecuteHamB(Ham_TakeDamageiIDEntityInSphereiIDEntityRocketiIDEntityRocketOwnerfDamageDMG_BLAST)
            
            
fDamage 10000000.0 get_user_health(iIDEntityInSphere);
            
            
ftD7Log(__"[fwFmTouch] fHealth: %f. fDamage: %f."fHealthfDamage)
            
            if (
fHealth fDamage)
            {
                
//if (fHealth < 1.0)
                //{
                //    ftD7Log(_, _, "[fwFmTouch] Player in explosion range has health between 0 and 1. fHealth: %f.", fHealth)
                //}
                
fHealth -= fDamage;
                
set_pev(iIDEntityInSpherepev_healthfHealth)
                
                continue;
            }
            
            
ftD7Log(__"[fwFmTouch] Player in explosion range should be dead. Executing Ham_Killed with custom death message.")
            
            
//set_pev(iIDEntityInSphere, pev_health, 1.0)
            //ExecuteHam(Ham_Spawn, iIDEntityInSphere)
            //engfunc(EngFunc_SetOrigin, iIDEntityInSphere, fVecOriginEntityInSphere)
            
            
iTemp get_msg_block(g_iIDMsgDeath);
            
            
set_msg_block(g_iIDMsgDeathBLOCK_ONCE)
            
            
ExecuteHamB(Ham_KillediIDEntityInSphereiIDEntityRocketOwner2)
            
            
set_msg_block(g_iIDMsgDeathiTemp)
            
            
ftMsgDeathSend(iIDEntityRocketOwneriIDEntityInSphereg_szClassNameRocket_iIDEntityRocket)
        }
        else if (
pev_valid(iIDEntityInSphere))
        {
            
pev(iIDEntityInSpherepev_healthfHealth)
            
            if (
fHealth <= 0.0)
                continue;
            
            
iIDEntityOtherOwner pev(iIDEntityInSpherepev_owner);
            
            if ((
<= iIDEntityOtherOwner <= g_iMaxPlayers) && bitsum_get(g_iBsConnectediIDEntityOtherOwner) && iEntityRocketOwnerTeam == get_user_team(iIDEntityOtherOwner))
                continue;
            
            
pev(iIDEntityInSpherepev_takedamagefDamage)
            
            if (
fDamage == 0.0)
            {
                
pev(iIDEntityInSpherepev_classnameszEntityClassNamecharsmax(szEntityClassName))
                
                if (!
equali(szEntityClassName"func_breakable"))
                    continue;
            }
            
            
ftFMEntityOriginGet(iIDEntityInSpherefVecOriginEntityInSphere)
            
//pev(iIDEntityInSphere, pev_origin, fVecOriginEntityInSphere)
            
            
fDamage fCVarDamage - (fCVarDamage fCVarRadius get_distance_f(fVecOriginfVecOriginEntityInSphere));
            
            
//ftD7Log(_, _, "[fwFmTouch] iIDEntityRocket: %d. iIDEntityInSphere: %d. fVecOriginEntityInSphere: %f, %f, %f. Damage: %f.",
            //iIDEntityRocket, iIDEntityInSphere, fVecOriginEntityInSphere[0], fVecOriginEntityInSphere[1], fVecOriginEntityInSphere[2], fDamage)
            
            
if (fDamage <= 0.0)
                continue;
            
            
ftD7Log(__"[fwFmTouch] iIDEntityRocket: %d. iIDEntityInSphere: %d. Damage: %f. Health: %f.",
            
iIDEntityRocketiIDEntityInSpherefDamagefHealth)
            
/*
            engfunc(EngFunc_MessageBegin, MSG_ALL, SVC_TEMPENTITY, fVecOrigin, 0)
            write_byte(TE_LIGHTNING)
            engfunc(EngFunc_WriteCoord, fVecOrigin[0])
            engfunc(EngFunc_WriteCoord, fVecOrigin[1])
            engfunc(EngFunc_WriteCoord, fVecOrigin[2])
            engfunc(EngFunc_WriteCoord, fVecOriginEntityInSphere[0])
            engfunc(EngFunc_WriteCoord, fVecOriginEntityInSphere[1])
            engfunc(EngFunc_WriteCoord, fVecOriginEntityInSphere[2])
            write_byte(25) //life in 0.1's
            write_byte(25) //width in 0.1's
            write_byte(0) //amplitude in 0.01's
            write_short(g_iIDCacheSpriteRocketTrail) //sprite model index
            message_end()*/
            
            
ExecuteHamB(Ham_TakeDamageiIDEntityInSphereiIDEntityRocketiIDEntityRocketOwnerfDamageDMG_BLAST)
        }
    }
    
    
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYfVecOrigin0)
    
write_byte(TE_EXPLOSION)
    
engfunc(EngFunc_WriteCoordfVecOrigin[0])
    
engfunc(EngFunc_WriteCoordfVecOrigin[1])
    
engfunc(EngFunc_WriteCoordfVecOrigin[2])
    
write_short(explosion)
    
write_byte(30)
    
write_byte(15)
    
write_byte(0)
    
message_end()
    
/*
    // Smallest ring
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, fVecOrigin, 0)
    write_byte(TE_BEAMCYLINDER) // TE id
    engfunc(EngFunc_WriteCoord, fVecOrigin[0]) // x
    engfunc(EngFunc_WriteCoord, fVecOrigin[1]) // y
    engfunc(EngFunc_WriteCoord, fVecOrigin[2]) // z
    engfunc(EngFunc_WriteCoord, fVecOrigin[0]) // x axis
    engfunc(EngFunc_WriteCoord, fVecOrigin[1]) // y axis
    engfunc(EngFunc_WriteCoord, fVecOrigin[2] + (fCVarRadius * 2) - (fCVarRadius * 2 / 3)) // z axis 385.0
    write_short(white) // sprite
    write_byte(0) // startframe
    write_byte(0) // framerate
    write_byte(4) // life
    write_byte(72) // width
    write_byte(0) // noise
    write_byte(255) // red
    write_byte(255) // green 100
    write_byte(255) // blue
    write_byte(200) // brightness
    write_byte(0) // speed
    message_end()
    
    // Medium ring
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, fVecOrigin, 0)
    write_byte(TE_BEAMCYLINDER) // TE id
    engfunc(EngFunc_WriteCoord, fVecOrigin[0]) // x
    engfunc(EngFunc_WriteCoord, fVecOrigin[1]) // y
    engfunc(EngFunc_WriteCoord, fVecOrigin[2]) // z
    engfunc(EngFunc_WriteCoord, fVecOrigin[0]) // x axis
    engfunc(EngFunc_WriteCoord, fVecOrigin[1]) // y axis
    engfunc(EngFunc_WriteCoord, fVecOrigin[2] + (fCVarRadius * 2) - (fCVarRadius * 2 / 6)) // z axis
    write_short(white) // sprite
    write_byte(0) // startframe
    write_byte(0) // framerate
    write_byte(4) // life
    write_byte(72) // width
    write_byte(0) // noise
    write_byte(255) // red
    write_byte(255) // green 100
    write_byte(255) // blue
    write_byte(200) // brightness
    write_byte(0) // speed
    message_end()
    */
    // Largest ring
    
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYfVecOrigin0)
    
write_byte(TE_BEAMCYLINDER// TE id
    
engfunc(EngFunc_WriteCoordfVecOrigin[0]) // x
    
engfunc(EngFunc_WriteCoordfVecOrigin[1]) // y
    
engfunc(EngFunc_WriteCoordfVecOrigin[2]) // z
    
engfunc(EngFunc_WriteCoordfVecOrigin[0]) // x axis
    
engfunc(EngFunc_WriteCoordfVecOrigin[1]) // y axis
    
engfunc(EngFunc_WriteCoordfVecOrigin[2] + (fCVarRadius 2)) // z axis
    
write_short(white// sprite
    
write_byte(0// startframe
    
write_byte(0// framerate
    
write_byte(4// life
    
write_byte(72// width
    
write_byte(0// noise
    
write_byte(255// red
    
write_byte(255// green 100
    
write_byte(255// blue
    
write_byte(200// brightness
    
write_byte(0// speed
    
message_end()
    
    
engfunc(EngFunc_RemoveEntityiIDEntityRocket)
}

ftFmVelocityByAim(const iID, const Float:fAmountFloat:fVecTemp[3])
{
    
pev(iIDpev_v_anglefVecTemp)
    
angle_vector(fVecTempANGLEVECTOR_FORWARDfVecTemp)
    
    
fVecTemp[0] *= fAmount;
    
fVecTemp[1] *= fAmount;
    
fVecTemp[2] *= fAmount;
}

public 
fwFmPlayerPreThink(iID)
{
    
//ftD7Log(_, iID, "[client_PreThink] iID: %d.", iID)
    
    
if (!bitsum_get(g_iBsHasBazookaiID) || !bitsum_get(g_iBsCanShootiID))
    {
        
//ftD7Log(_, iID, "[client_PreThink] No bazooka/can't shoot.")
        
        
return;
    }
    
    new 
iBsButtons pev(iIDpev_button);
    
    if (!(
iBsButtons IN_ATTACK2))
    {
        
//ftD7Log(_, iID, "[client_PreThink] Not holding buttons.")
        
        
return;
    }
    
    
set_pev(iIDpev_button, (iBsButtons & ~IN_ATTACK2))
    
    static 
iIDAllocString;
    
    if(!
iIDAllocString)
    {
        
//ftD7Log(_, iID, "[client_PreThink] String not allocated. Allocating.")
        
        
iIDAllocString engfunc(EngFunc_AllocString"info_target"); // alloc string once per load
    
}
    
    new 
iIDEntity engfunc(EngFunc_CreateNamedEntityiIDAllocString);
    
    if (!
pev_valid(iIDEntity))
    {
        
//ftD7Log(_, iID, "[client_PreThink] Entity failed to create!")
        
        
return;
    }
    
    
set_pev(iIDEntitypev_classnameg_szClassNameRocket)
    
set_pev(iIDEntityg_iIDEntityRocketPevg_iIDEntityRocket)
    
set_pev(iIDEntitypev_owneriID)
    
    static 
Float:fVecTemp[3];
    
    
pev(iIDpev_v_anglefVecTemp)
    
fVecTemp[0] *= -1;
    
set_pev(iIDEntitypev_anglesfVecTemp)
    
    
set_pev(iIDEntitypev_solidSOLID_TRIGGER)
    
set_pev(iIDEntitypev_movetypeMOVETYPE_FLY)
    
    new 
Float:fEntMaxVelocity get_pcvar_float(g_iIDPCVarSvMaxVelocity);
    
    
ftFmVelocityByAim(iIDfloatclamp(get_pcvar_float(CVar_RocketSpeed), -fEntMaxVelocityfEntMaxVelocity), fVecTemp)
    
set_pev(iIDEntitypev_velocityfVecTemp)
    
    
set_pev(iIDEntitypev_effects, (pev(iIDEntitypev_effects) | EF_LIGHT))
    
    static 
Float:fVecTemp2[3];
    
    
pev(iIDpev_originfVecTemp)
    
pev(iIDpev_view_ofsfVecTemp2)
    
fVecTemp[0] += fVecTemp2[0];
    
fVecTemp[1] += fVecTemp2[1];
    
fVecTemp[2] += fVecTemp2[2];
    
engfunc(EngFunc_SetOriginiIDEntityfVecTemp)
    
    
engfunc(EngFunc_SetModeliIDEntityg_szEntityRocketModel)
    
    
message_begin(MSG_BROADCASTSVC_TEMPENTITY);
    
write_byte(TE_BEAMFOLLOW);
    
write_short(iIDEntity);
    
write_short(g_iIDCacheSpriteRocketTrail);
    
write_byte(11);
    
write_byte(5);
    
write_byte(191);
    
write_byte(191);
    
write_byte(191);
    
write_byte(random_num(150240));
    
message_end();
    
    
emit_sound(iIDEntityCHAN_WEAPONROCKET_SOUND1.0ATTN_NORM0PITCH_NORM)
    
    
bitsum_del(g_iBsCanShootiID)
    
    
set_task(get_pcvar_float(CVar_RocketDelay), "fwTaskCanShoot"iID)
}

public 
fwTaskCanShoot(const iID)
{
    
bitsum_add(g_iBsCanShootiID)
    
    
client_print(iIDprint_center"Your can now shoot the next rocket!")



Adomaz1 03-01-2017 12:42

Re: entity goes to a random direction
 
thank you!


All times are GMT -4. The time now is 20:42.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.