Raised This Month: $209 Target: $400
 52% 

[SNIPPET] NPC DeathMSG


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-09-2021 , 14:25   [SNIPPET] NPC DeathMSG
Reply With Quote #1

I've found a way to make an npc fake deathmsg, i thought i'd share since i had never found something similar on the web.

PHP Code:
#include <fakemeta>

enum any:DEATHMSG_DATA (+=1) {
    
DEATHMSG_VICTIM_ID 0,
    
DEATHMSG_KILLER_ID,
    
DEATHMSG_bHEADSHOT,
    
DEATHMSG_WEAPON_NAME[24]
}

public 
fw_NPC_KILLED(idkiller)
{
    if(!
pev_valid(id)) return HAM_IGNORED;
    
    
pev(idpev_globalnameszZMnamecharsmax(szZMname))
    if(!
szZMname[0]) copy(szZMnamecharsmax(szZMname), "Unnamed");

    static 
szParam[10], Array:xArrayiNPC_DeathMSG_Data[DEATHMSG_DATA];
    
iNPC_DeathMSG_Data[DEATHMSG_VICTIM_ID] = id;
    
iNPC_DeathMSG_Data[DEATHMSG_KILLER_ID] = killer;
    
iNPC_DeathMSG_Data[DEATHMSG_bHEADSHOT] = false;
    
copy(iNPC_DeathMSG_Data[DEATHMSG_WEAPON_NAME], charsmax(iNPC_DeathMSG_Data[DEATHMSG_WEAPON_NAME]), "knife");
    
copy(iNPC_DeathMSG_Data[DEATHMSG_VIC_NAME], charsmax(iNPC_DeathMSG_Data[DEATHMSG_VIC_NAME]), szZMname);

    if(
IsPlayer(killer))
    {
        
get_user_name(killeriNPC_DeathMSG_Data[DEATHMSG_KILLER_NAME], charsmax(iNPC_DeathMSG_Data[DEATHMSG_KILLER_NAME]))
    }
    else if(
killer && pev(killerPEV_IDENTITY) == ZOMBIE_PET_ID) {
        
pev(killerpev_globalnameszZMnamecharsmax(szZMname));
        if(!
szZMname[0]) copy(szZMnamecharsmax(szZMname), "Unnamed");
        
copy(iNPC_DeathMSG_Data[DEATHMSG_KILLER_NAME], charsmax(iNPC_DeathMSG_Data[DEATHMSG_KILLER_NAME]), szZMname);
    }

    
ArrayPushArray((xArray ArrayCreate(DEATHMSG_DATA1)), iNPC_DeathMSG_Data);
    
num_to_str(_:xArrayszParamcharsmax(szParam));

    static const 
Float:fInterval_len 1.0;
    static 
Float:finterval 0.0;

    if(
finterval >= get_gametime())
        
finterval += fInterval_len;
    else 
        
finterval get_gametime() + fInterval_len;

    
set_task((finterval get_gametime()), "task_interval_NPC_DEATHMSG"idszParamcharsmax(szParam));
    return 
HAM_SUPERCEDE;
}

public 
task_interval_NPC_DEATHMSG(const param[], taskid)
{
    static Array:
xArrayiNPC_DeathMSG_Data[DEATHMSG_DATA];
    
xArray any:str_to_num(param);
    
ArrayGetArray(xArray0iNPC_DeathMSG_Data);
    
ArrayDestroy(xArray);
    
Make_NPC_DeathMsg(iNPC_DeathMSG_Data[DEATHMSG_VICTIM_ID], iNPC_DeathMSG_Data[DEATHMSG_KILLER_ID],
        
iNPC_DeathMSG_Data[DEATHMSG_VIC_NAME], iNPC_DeathMSG_Data[DEATHMSG_KILLER_NAME],
        
iNPC_DeathMSG_Data[DEATHMSG_bHEADSHOT], iNPC_DeathMSG_Data[DEATHMSG_WEAPON_NAME]);
}

Make_NPC_DeathMsg(idkiller, const vicName[32], const killerName[32], const bool:bHeadshot, const weapon[24])
{
    static 
iMsg_TeamInfo 0;
    if(!
iMsg_TeamInfoiMsg_TeamInfo get_user_msgid("TeamInfo");
    
    
enum (+=1) {
        
VICTIM_ID 0,
        
KILLER_ID
    
}

    new 
iTargets[2];
    
iTargets[VICTIM_ID] = id;
    
iTargets[KILLER_ID] = killer;

    static 
szRejectReason[128], szName[2][32];

    
copy(szName[VICTIM_ID], charsmax(szName[]), vicName);
    
copy(szName[KILLER_ID], charsmax(szName[]), killerName);

    for(new 
iiTarget2i++)
    {
        
iTarget iTargets[i];
        if( 
IsPlayer(iTarget) && get_user_index(szName[i]) || !iTarget || (KILLER_ID == && iTargets[i] == iTargets[VICTIM_ID]))
            continue;

        
iTarget engfunc(EngFunc_CreateFakeClientszName[i]);

        if(!
iTarget)
            continue;
        
        
engfunc(EngFunc_FreeEntPrivateDataiTarget);

        
dllfunc(DLLFunc_ClientConnectiTarget szName[i], "127.0.0.1"szRejectReason);
        
        if( !
is_user_connected(iTarget) ) 
            continue;

        
dllfunc(DLLFunc_ClientPutInServeriTarget);
        
set_pev(iTargetpev_flagspev(iTarget,pev_flags) | FL_FAKECLIENT);

        
message_begin(MSG_ALLiMsg_TeamInfo, {0,0,0}, 0);
        
write_byte(iTarget);
        
write_string("TERRORIST");
        
message_end();

        
set_rendering(iTargetkRenderFxNone000kRenderTransAlpha);

        
iTargets[i] = iTarget;
    }

    new 
szParam[10], Array:xArrayiNPC_DeathMSG_Data[DEATHMSG_DATA];
    
iNPC_DeathMSG_Data[DEATHMSG_VICTIM_ID] = iTargets[VICTIM_ID];
    
iNPC_DeathMSG_Data[DEATHMSG_KILLER_ID] = iTargets[KILLER_ID];
    
iNPC_DeathMSG_Data[DEATHMSG_bHEADSHOT] = _:bHeadshot;
    
copy(iNPC_DeathMSG_Data[DEATHMSG_WEAPON_NAME], charsmax(iNPC_DeathMSG_Data[DEATHMSG_WEAPON_NAME]), weapon);
    
copy(iNPC_DeathMSG_Data[DEATHMSG_KILLER_NAME], charsmax(iNPC_DeathMSG_Data[DEATHMSG_KILLER_NAME]), killerName);
    
copy(iNPC_DeathMSG_Data[DEATHMSG_VIC_NAME], charsmax(iNPC_DeathMSG_Data[DEATHMSG_VIC_NAME]), vicName);
    
ArrayPushArray((xArray ArrayCreate(DEATHMSG_DATA1)), iNPC_DeathMSG_Data);
    
num_to_str(_:xArrayszParamcharsmax(szParam));
    
set_task(0.1"declare_npc_deathmsg"idszParamcharsmax(szParam))
}

public 
declare_npc_deathmsg(const param[], const taskid)
{
    new Array:
xArray any:str_to_num(param), iNPC_DeathMSG_Data[DEATHMSG_DATA];
    
ArrayGetArray(xArray0iNPC_DeathMSG_Data);
    
ArrayDestroy(xArray);

    
make_deathmsg(iNPC_DeathMSG_Data[DEATHMSG_KILLER_ID], iNPC_DeathMSG_Data[DEATHMSG_VICTIM_ID],
         
iNPC_DeathMSG_Data[DEATHMSG_bHEADSHOT], iNPC_DeathMSG_Data[DEATHMSG_WEAPON_NAME]);

    if(
iNPC_DeathMSG_Data[DEATHMSG_KILLER_ID] > && pev(iNPC_DeathMSG_Data[DEATHMSG_KILLER_ID], pev_flags) & FL_FAKECLIENT)
    {
        
server_cmd("kick #%d;"get_user_userid(iNPC_DeathMSG_Data[DEATHMSG_KILLER_ID]));
    }
    
    if(
iNPC_DeathMSG_Data[DEATHMSG_VICTIM_ID] > && pev(iNPC_DeathMSG_Data[DEATHMSG_VICTIM_ID], pev_flags) & FL_FAKECLIENT)
    {
        
server_cmd("kick #%d;"get_user_userid(iNPC_DeathMSG_Data[DEATHMSG_VICTIM_ID]));
    }


basically what this function do is it creates a bot if an npc entity id was passed into either the killer or id ( victim ) parameters or both, and it kicks the bot/s once the fake deathmsg is sent.

NPC entity name must be set into globalname keyvalue, or you can change that if you're using one npc name for all.

Adding a delay of 1.0 second to Make_NPC_DeathMsg is recommended if you're going to call it many times per second.
__________________
@Jailbreak Main Mod v2.6.5 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Last edited by Natsheh; 05-09-2021 at 20:23.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 06-18-2021 , 04:43   Re: [SNIPPET] NPC DeathMSG
Reply With Quote #2

When you refer to Non-Player Character you mean Artificial Intelligence? As it stands this is non-functional. I started to clean it up but still missing some pieces and got too much other work to do. Are you up for sharing a non-fragmented script please? When I first looked at this I had found a way to do this with way less code yet then I scrolled down to see a lot more code. I just wanted to see what this can do beforehand.
__________________
"It's not the actual programming that's interesting. But it's what you can accomplish with the end results that are important." -Dennis Ritchie
"Mathematics, rightly viewed, possesses not only truth, but supreme beauty a beauty cold and austere, like that of sculpture..." -Bertrand Russell
DJEarthQuake is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode