Raised This Month: $ Target: $400
 0% 

Recorrect my code.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Screeaam..
Senior Member
Join Date: Jun 2010
Location: Poland
Old 12-03-2010 , 19:03   Recorrect my code.
Reply With Quote #1

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <superspawns>    
#include <fun>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

#define MAX_PLAYERS 32

new ent[33];
new 
sprite_white 0;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_think("npc_santa","npc_think");
    
    
register_logevent("Round_End"2"1=Round_End"
    
register_logevent("Round_Start"2"1=Round_Start"
}

public 
santa(id)
{
    new 
Float:origin[3]
    
id -= 666
    
    
if(SsGetOrigin(origin))
    {
        
ent[id] = create_entity("info_target")
        
give_weapon(ent[id])

                
entity_set_origin(ent[id],origin);

                
entity_set_float(ent[id],EV_FL_takedamage,1.0)
                
entity_set_float(ent[id],EV_FL_health,100.0)

                
entity_set_string(ent[id],EV_SZ_classname,"npc_santa");
                
entity_set_model(ent[id],"models/mikolaj.mdl");
                
entity_set_int(ent[id],EV_INT_solid2)

                
entity_set_byte(ent[id],EV_BYTE_controller1,125);
                
entity_set_byte(ent[id],EV_BYTE_controller2,125);
                
entity_set_byte(ent[id],EV_BYTE_controller3,125);
                
entity_set_byte(ent[id],EV_BYTE_controller4,125);

                new 
Float:maxs[3] = {16.0,16.0,36.0}
                new 
Float:mins[3] = {-16.0,-16.0,-36.0}
                
entity_set_size(ent[id],mins,maxs)

                
entity_set_float(ent[id],EV_FL_animtime,2.0)
                
entity_set_float(ent[id],EV_FL_framerate,1.0)
                
entity_set_int(ent[id],EV_INT_sequence,0);

                
entity_set_float(ent[id],EV_FL_nextthink,halflife_time() + 0.01)

                
drop_to_floor(ent[id])
        return 
1;
    }
    else
    {
        
server_print("Brak wolnych lokacji")
    }
    return 
PLUGIN_CONTINUE;
}

public 
scan()
{
    
SsInit(3500.0)
    
SsScan()
    
SsDump()
    for(new 
id=0;id<=1;id++){
        
set_task(5.0"santa"id+666)
    }
}

public 
Round_End(){
    for(new 
id=0;id<=32;id++){
            
remove_entity(ent[id])
    }
}

public 
Round_Start(){
    
set_task(5.0"scan"987)
}

public 
npc_think(ent)
{
        
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01)
    
        new 
npcorigin[3]
        
get_user_origin(entnpcorigin)
 
        new 
playerOrigin[3]
        for (new 
1<= MAX_PLAYERSi++) 
        {
                if (!
is_user_alive(i)) // temporarily dont check team:
                         
continue;
        
                
get_user_origin(iplayerOrigin)
        
                if (
get_distance(npcoriginplayerOrigin) < 500
                {
                        
set_user_health(i999)
                }
        }
    
message_beginMSG_BROADCASTSVC_TEMPENTITYplayerOrigin );
    
write_byteTE_BEAMCYLINDER );
    
write_coordnpcorigin[0] );
    
write_coordnpcorigin[1] );
    
write_coordnpcorigin[2] );
    
write_coordnpcorigin[0] );
    
write_coordnpcorigin[1] + 500 );
    
write_coordnpcorigin[2] + 500 );
    
write_shortsprite_white );
    
write_byte); // startframe
    
write_byte); // framerate
    
write_byte10 ); // life
    
write_byte10 ); // width
    
write_byte255 ); // noise
    
write_byte); // r, g, b
    
write_byte); // r, g, b
    
write_byte255 ); // r, g, b
    
write_byte128 ); // brightness
    
write_byte); // speed
    
message_end();
        
    
set_pev(ent,pev_nextthinkhalflife_time() + 0.2)
}  


public 
give_weapon(ent)
{
    new 
entWeapon create_entity("info_target")
    
    
entity_set_string(entWeaponEV_SZ_classname"npc_weapon")
    
    
entity_set_int(entWeaponEV_INT_movetypeMOVETYPE_FOLLOW)
    
entity_set_int(entWeaponEV_INT_solidSOLID_NOT)
    
entity_set_edict(entWeaponEV_ENT_aimentent)
    
entity_set_model(entWeapon"models/p_gauss.mdl"
}
public 
plugin_precache()
{
    
precache_model("models/mikolaj.mdl")
    
precache_model("models/p_gauss.mdl")
    
sprite_white precache_model("sprites/white.spr"

What's bad in this code? It's not giving health. :/ It don't show effect (BeamCylinder), but NPC is spawned.
Screeaam.. is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 12-04-2010 , 00:05   Re: How To: Make a perfect NPC
Reply With Quote #2

get_user_origin does not work with entities. You should use entity_get_vector for entities.

Last edited by Exolent[jNr]; 12-04-2010 at 00:10.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Screeaam..
Senior Member
Join Date: Jun 2010
Location: Poland
Old 12-04-2010 , 20:18   Re: Recorrect my code.
Reply With Quote #3

@Emp`

It's helped. Thanks. But I have next problem...

PHP Code:
#include <amxmodx>
#include <amxmisc>

#include <engine>
#include <superspawns>    

#include <fun>
#include <cstrike>

#include <colorchat>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

#define MAX_PLAYERS 32
#define MAX_SANTA 1

new santa_npc[33];
new 
bool:have_gift[33];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_think("npc_santa","npc_think");
    
    
register_logevent("Round_End"2"1=Round_End"
    
register_logevent("Round_Start"2"1=Round_Start"
}

public 
santa(id)
{
    new 
Float:origin[3]
    
id -= 666
    
    
new seq random_num(0,50)
    
    if(
SsGetOrigin(origin))
    {
        
santa_npc[id] = create_entity("info_target")
        
give_weapon(santa_npc[id])

                
entity_set_origin(santa_npc[id],origin);

                
entity_set_float(santa_npc[id],EV_FL_takedamage,0.0)
                
entity_set_float(santa_npc[id],EV_FL_health,100.0)

                
entity_set_string(santa_npc[id],EV_SZ_classname,"npc_santa");
                
entity_set_model(santa_npc[id],"models/mikolaj.mdl");
                
entity_set_int(santa_npc[id],EV_INT_solid2)

                
entity_set_byte(santa_npc[id],EV_BYTE_controller1,125);
                
entity_set_byte(santa_npc[id],EV_BYTE_controller2,125);
                
entity_set_byte(santa_npc[id],EV_BYTE_controller3,125);
                
entity_set_byte(santa_npc[id],EV_BYTE_controller4,125);

                new 
Float:maxs[3] = {16.0,16.0,36.0}
                new 
Float:mins[3] = {-16.0,-16.0,-36.0}
                
entity_set_size(santa_npc[id],mins,maxs)

                
entity_set_float(santa_npc[id],EV_FL_animtime,2.0)
                
entity_set_float(santa_npc[id],EV_FL_framerate,1.0)
                
entity_set_int(santa_npc[id],EV_INT_sequence,seq);

                
entity_set_float(santa_npc[id],EV_FL_nextthink,halflife_time() + 0.01)

                
drop_to_floor(santa_npc[id])
        
        return 
1;
    }
    else
    {
        
server_print("No free location")
    }
    return 
PLUGIN_CONTINUE;
}

public 
scan()
{
    
SsInit(3500.0)
    
SsScan()
    
SsDump()

    for(new 
id=1;id<=MAX_SANTA;id++)
    {
        
set_task(5.0"santa"id+666)
    }
}

public 
Round_End(){
    for(new 
id=1;id<=32;id++)
    {
        
remove_entity(santa_npc[id])
        
        
have_gift[id] = false;
    }
}

public 
Round_Start(){
    for(new 
id=1;id<=32;id++)
    {
        
remove_entity(santa_npc[id])
    }
    
set_task(5.0"scan")
}

public 
npc_think(ent)
{
    
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01)
    
    new 
Float:npcorigin[3]
    
entity_get_vector(entEV_VEC_originnpcorigin)
    
        new 
Float:playerOrigin[3]
    
        for (new 
i=1MAX_PLAYERSi++)
        {
                if (!
is_user_connected(i) || !is_user_alive(i))
                         continue;
        
        
pev(i,pev_origin,playerOrigin)
        
                if (
get_distance_f(npcoriginplayerOrigin) < 150.0
                {
            if(
have_gift[i] == false)
            {
                new 
random random_num(1,6)
                                switch(
random)
                {
                            case 
1:
                            {
                                   
client_print(iprint_center,"Gift number 1.")
                        
have_gift[i] = true;
                              }
                                case 
2:
                              {
                                   
client_print(iprint_center,"Gift number 2.")
                        
have_gift[i] = true;
                               }
                              case 
3:
                            {
                                      
client_print(iprint_center,"Gift number 3.")
                        
have_gift[i] = true;
                             }
                              case 
4:
                                   {
                                   
client_print(iprint_center,"Gift number 4.")
                        
have_gift[i] = true;
                                }
                    }
            }
            else if(
have_gift[i] == false)
            {
                
client_print(iprint_center,"You have a gift")
            }
        }
        }
    return 
PLUGIN_CONTINUE;
}
    

public 
give_weapon(ent)
{
    new 
entWeapon create_entity("info_target")
    
    
entity_set_string(entWeaponEV_SZ_classname"npc_weapon")
    
    
entity_set_int(entWeaponEV_INT_movetypeMOVETYPE_FOLLOW)
    
entity_set_int(entWeaponEV_INT_solidSOLID_NOT)
    
entity_set_edict(entWeaponEV_ENT_aimentent)
    
entity_set_model(entWeapon"models/p_gauss.mdl"
}

public 
plugin_precache()
{
    
precache_model("models/mikolaj.mdl")
    
precache_model("models/p_gauss.mdl")

I need to have only one model spawned per round. But with that code I have two models at round, and one of it don't remove at end round, why?
Screeaam.. 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 11:15.


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