Raised This Month: $51 Target: $400
 12% 

[HOWTO] Make a NPC with extra features.


Post New Thread Reply   
 
Thread Tools Display Modes
ahmetberkay
New Member
Join Date: Sep 2011
Old 02-16-2012 , 14:08   Re: [HOWTO] Make a NPC with extra features.
Reply With Quote #31

dont compile :/
ahmetberkay is offline
Old 02-16-2012, 14:14
Devil259
This message has been deleted by Devil259. Reason: nvm
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 02-16-2012 , 20:57   Re: [HOWTO] Make a NPC with extra features.
Reply With Quote #32

Quote:
Originally Posted by ahmetberkay View Post
dont compile :/
Fixed.
Was a small typo when I was copying and pasting.
__________________
It's a mystery.
Mini_Midget is offline
Rirre
Veteran Member
Join Date: Nov 2006
Old 03-05-2012 , 11:44   Re: [HOWTO] Make a NPC with extra features.
Reply With Quote #33

Can you make a (sprite) health bar for the NPC's?

Last edited by Rirre; 03-05-2012 at 11:45.
Rirre is offline
Devil259
Veteran Member
Join Date: Dec 2009
Location: France (59)
Old 03-05-2012 , 12:40   Re: [HOWTO] Make a NPC with extra features.
Reply With Quote #34

Post here : http://forums.alliedmods.net/showthread.php?t=174463
__________________
You can do anything you set your mind to, man.

Devil259 is offline
Rirre
Veteran Member
Join Date: Nov 2006
Old 03-05-2012 , 12:45   Re: [HOWTO] Make a NPC with extra features.
Reply With Quote #35

Quote:
Originally Posted by Devil259 View Post
Fits this thread more since it is about "npc".
Rirre is offline
Old 03-05-2012, 13:07
liinuus
This message has been deleted by liinuus. Reason: double post
liinuus
Senior Member
Join Date: Apr 2010
Old 03-05-2012 , 13:11   Re: [HOWTO] Make a NPC with extra features.
Reply With Quote #36

Quote:
Originally Posted by Rirre View Post
Fits this thread more since it is about "npc".
that plugin will give you an general idea of how to do an health bar over the npc, thats why you were given the link, in that plugin ( from my guess after just seing the sprite used ) they most likely use a sprite that they put over the targets head, then set the frame of the sprite.
liinuus is offline
Rirre
Veteran Member
Join Date: Nov 2006
Old 03-05-2012 , 14:14   Re: [HOWTO] Make a NPC with extra features.
Reply With Quote #37

Quote:
Originally Posted by liinuus View Post
that plugin will give you an general idea of how to do an health bar over the npc, thats why you were given the link, in that plugin ( from my guess after just seing the sprite used ) they most likely use a sprite that they put over the targets head, then set the frame of the sprite.
Have take a look on it already and it just confused me, so I found this on the last page -> http://forums.alliedmods.net/showpos...8&postcount=99
A bit less code which was a bit easier to understand, so I started to give it a try to make it over a NPC.
I am stuck at several lines, I don't know what to do about them and the events.
This is why I'm asking for a full code for the health bar.

Last edited by Rirre; 03-05-2012 at 14:18.
Rirre is offline
liinuus
Senior Member
Join Date: Apr 2010
Old 03-05-2012 , 14:46   Re: [HOWTO] Make a NPC with extra features.
Reply With Quote #38

well, these plugins are just placing a sprite over the objects head, then they set the frames, frame 99 are for full hp, and frame 1 or 0 would be when theyre out of hp, then just use some math and calculate what frame it shud be, ofc this is just a quick explaination of how it works, you will need to check the code for the other settings you need to put on the bar, like the nodraw effects and such.

When the plugin starts, the entities for the health bars are created, on the addtofullpack, the origin of the bar is updated, and theyve hooke the "Health" event to change the size of the bar.
liinuus is offline
Carlen20
Senior Member
Join Date: Jun 2011
Location: Sweden
Old 03-05-2012 , 15:25   Re: [HOWTO] Make a NPC with extra features.
Reply With Quote #39

gj, will definitly use this tutorial if i will make an npc plugin
__________________
Nothing are impossible if you just use your mind!

Quote:
Originally Posted by NiceGuyx View Post
P.S: i'm the best coder here

Carlen20 is offline
Rirre
Veteran Member
Join Date: Nov 2006
Old 03-06-2012 , 16:17   Re: [HOWTO] Make a NPC with extra features.
Reply With Quote #40

Alright, this is what I've done.
model in create_npc() is replaced by EngFunc_SetModel when make_healthbar() is executed (which means the NPC is invisible in-game), I don't know how to fix this.
And at some lines I am unsure about.
Please, correct this script (also, remove the sprite/entity when it dies).
PHP Code:
#define NPC_CLASSNAME "npc"
#define HEALTH_MULTI 500.0

new Float:max_health[1000// HEALTH_MULTI * get_playersnum()

new const healthbar_spr[] = "sprites/npc/npc_hp_grade2.spr"

public plugin_init()
{
    
register_forward(FM_AddToFullPack"fm_addtofullpack_post"1)
    
register_event("Health""event_health""b")
}

create_npc()
{
    ...
    
entity_set_model(entmodel)
    
max_health[ent] = HEALTH_MULTI get_playersnum()
    
entity_set_float(entEV_FL_healthmax_health[ent] + 1000.0)
    ...

    
make_healthbar()
}

public 
make_healthbar()
{
    static 
entallocString

    ent 
find_ent_by_class(-1NPC_CLASSNAME)

    
allocString engfunc(EngFunc_AllocString"env_sprite")
    
engfunc(EngFunc_CreateNamedEntityallocString)

    if(
is_valid_ent(ent))
    {
        
engfunc(EngFunc_SetModelenthealthbar_spr)
        
set_pev(entpev_scale1.0)
        
set_pev(entpev_effectspev(entpev_effects ) | EF_NODRAW)
    }
}

public 
event_health(ent)
{
    if(
pev(entpev_health) - 1000.0 <= HEALTH_MULTI)
    {
        
max_health[ent] = HEALTH_MULTI // Unsure..
        
set_pev(entpev_frame99.0)
    }
    else
    {
        
set_pev(entpev_frame0.0 + (((HEALTH_MULTI 1000.0) * HEALTH_MULTI) / max_health[ent])) // Unsure..
    
}
}

public 
fm_addtofullpack_post(ent)
{
    if(!
is_valid_ent(ent))
        return 
HAM_IGNORED

    
if(pev(entpev_iuser4) == 1// npc is dead
        
return HAM_IGNORED

    
if(g_evoluting || g_doing_other)
        return 
HAM_IGNORED
    
    
new Float:EntOrigin[3]
    
pev(entpev_originEntOrigin)
                            
    
EntOrigin[2] += 120.0
                        
    engfunc
(EngFunc_SetOriginentEntOrigin)
    
set_pev(entpev_effectspev(entpev_effects) & ~EF_NODRAW)

    return 
FMRES_HANDLED
}

public 
fw_think(ent)
{
    if(!
is_valid_ent(ent))
        return 
HAM_IGNORED

    
if(pev(entpev_iuser4) == 1// npc is dead
        
return HAM_IGNORED

    
if(g_evoluting || g_doing_other)
        return 
HAM_IGNORED

    
if(pev(entpev_health) - 1000.0 <= 0.0)
    {
        
set_pev(entpev_iuser41)
        
set_entity_anim(ent20)
        
set_task(15.0"move_entity"ent)
        
entity_set_int(entEV_INT_solidSOLID_NOT)
        
entity_set_float(entEV_FL_takedamage0.0)

        
emit_sound(entCHAN_BODYdeath_sound1.0ATTN_NORM0PITCH_NORM)
        
        return 
HAM_IGNORED
    
}


Last edited by Rirre; 03-06-2012 at 16:54.
Rirre is offline
Reply



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 18:04.


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