AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   problem +USE in ent (https://forums.alliedmods.net/showthread.php?t=117029)

frk_14 01-28-2010 12:48

problem +USE in ent
 
i'm trying when press E(+USE) in the entity "cosa" something happen, but dont work

PHP Code:

#include <amxmodx> 
#include <engine> 
#include <fakemeta>


 
public plugin_init()
 {
     
register_clcmd("cosa""cosa"
     
register_forward(FM_CmdStart"fw_CmdStart")

     
 }
 
 public 
plugin_precache()
 {
     
precache_model("models/a.mdl"
     
 }
 
 public 
cosa(id)
 {
 
     new 
Float:origin[3
 
     
entity_get_vector(id,EV_VEC_origin,origin)
 
     new 
ent create_entity("info_target"
     
 
     
entity_set_origin(ent,origin); 
     
origin[2] += 100.0
     entity_set_origin
(id,origin)
 
     
entity_set_float(ent,EV_FL_takedamage,1.0
     
entity_set_float(ent,EV_FL_health,100.0
 
     
entity_set_string(ent,EV_SZ_classname,"cosa"); 
     
entity_set_model(ent,"models/a.mdl"); 
     
entity_set_int(ent,EV_INT_solid2)
 
     
entity_set_byte(ent,EV_BYTE_controller1,125);
     
entity_set_byte(ent,EV_BYTE_controller2,125);
     
entity_set_byte(ent,EV_BYTE_controller3,125);
     
entity_set_byte(ent,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,mins,maxs)
 
     
entity_set_float(ent,EV_FL_animtime,2.0
     
entity_set_float(ent,EV_FL_framerate,1.0
     
entity_set_int(ent,EV_INT_sequence,0);
 
     
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01)
 
     
drop_to_floor(ent)
     return 
1;
 }
 public 
fw_CmdStart(idhandlerandom_seed)
{
    if(!
is_user_alive(id))
        return;
    
    new 
buttons = (get_uc handleUC_Buttons ) & IN_USE
    
    
    if (
buttons )
    {
        new 
targettemp
        
if(get_user_aiming(idtargettemp50) != 0.0)
        {
            if(!
target || !is_valid_ent(target))
                return
        
            new class[
33]
            
entity_get_string(targetEV_SZ_classname, class, 31)
            
            if(
equal(class, "cosa"))
            {
                
client_print(idprint_center"Tocaste la Cosa we")
            }
        }
    }



xPaw 01-28-2010 13:09

Re: problem +USE in ent
 
Register Ham_Use for "info_target" and then filter your classname there

ConnorMcLeod 01-28-2010 13:39

Re: problem +USE in ent
 
Dunno if info_target is usable, but some other entity types can do the job.

joropito 01-28-2010 14:45

Re: problem +USE in ent
 
Quote:

Originally Posted by ConnorMcLeod (Post 1070793)
Dunno if info_target is usable, but some other entity types can do the job.

func_button maybe

There's a lot of entities to play
http://www.twhl.co.za/wiki.php?sub=1

frk_14 01-29-2010 14:30

Re: problem +USE in ent
 
Ok, i try with ham_use, and diferent entities, but the problem continues...


PHP Code:

  RegisterHam(Ham_Use"func_button""ToqueLaCosa"

PHP Code:

public ToqueLaCosa(entity)
{
    new 
classname[32]
    
entity_get_string(entityEV_SZ_classnameclassnamesizeof classname 1)
    
    if (
equal(classname"cosa"))
    {
        
client_print(0print_chat"Alguien toco la cosa")
    }


maybe the problem is here?
PHP Code:

public cosa(id)
 {
 
     new 
Float:origin[3
 
     
entity_get_vector(id,EV_VEC_origin,origin)
 
     new 
ent create_entity("info_target"
     
 
     
entity_set_origin(ent,origin); 
     
origin[2] += 100.0
     entity_set_origin
(id,origin)
 
     
entity_set_float(ent,EV_FL_takedamage,1.0
     
entity_set_float(ent,EV_FL_health,100.0
 
     
entity_set_string(ent,EV_SZ_classname,"cosa"); 
     
entity_set_model(ent,"models/a.mdl"); 
     
entity_set_int(ent,EV_INT_solid2)
 
     
entity_set_byte(ent,EV_BYTE_controller1,125);
     
entity_set_byte(ent,EV_BYTE_controller2,125);
     
entity_set_byte(ent,EV_BYTE_controller3,125);
     
entity_set_byte(ent,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,mins,maxs)
 
     
entity_set_float(ent,EV_FL_animtime,2.0
     
entity_set_float(ent,EV_FL_framerate,1.0
     
entity_set_int(ent,EV_INT_sequence,0);
 
     
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01)
 
     
drop_to_floor(ent)
     return 
1;
 } 


joropito 01-29-2010 17:06

Re: problem +USE in ent
 
Change info_target for func_button

If you change classname, Ham_Use will not be called for that entity.

For test purposes I suggest to use FM_Use (register_forward)

Then you can start using ham but before registerham you must be sure that you you have at least one entity with your new classname and then registerham using that classname and not func_button.

joropito 01-29-2010 19:45

Re: problem +USE in ent
 
Try something like this


PHP Code:

new g_HamUse

public plugin_init()
{
      
register_plugin(......
}

public 
cosa(id)
{
 
     new 
Float:origin[3
 
     
entity_get_vector(id,EV_VEC_origin,origin)
 
     new 
ent create_entity("info_target")
     
entity_set_string(ent,EV_SZ_classname,"cosa"); 

     if(!
g_HamUse)
     {
          
g_HamUse RegisterHam(Ham_Use"cosa""ToqueLaCosa")
     }
     
 
     
entity_set_origin(ent,origin); 
     
origin[2] += 100.0
     entity_set_origin
(id,origin)
 
     
entity_set_float(ent,EV_FL_takedamage,1.0
     
entity_set_float(ent,EV_FL_health,100.0
 
     
entity_set_model(ent,"models/a.mdl"); 
     
entity_set_int(ent,EV_INT_solid2)
 
     
entity_set_byte(ent,EV_BYTE_controller1,125);
     
entity_set_byte(ent,EV_BYTE_controller2,125);
     
entity_set_byte(ent,EV_BYTE_controller3,125);
     
entity_set_byte(ent,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,mins,maxs)
 
     
entity_set_float(ent,EV_FL_animtime,2.0
     
entity_set_float(ent,EV_FL_framerate,1.0
     
entity_set_int(ent,EV_INT_sequence,0);
 
     
entity_set_float(ent,EV_FL_nextthink,halflife_time() + 0.01)
 
     
drop_to_floor(ent)
     return 
1;
 } 


IneedHelp 01-29-2010 19:54

Re: problem +USE in ent
 
I'd use RegisterHamFromEntity & alter the entity's classname to func_button/cycler_sprite.

ConnorMcLeod 01-29-2010 20:28

Re: problem +USE in ent
 
Quote:

Originally Posted by IneedHelp (Post 1072280)
I'd use RegisterHamFromEntity & alter the entity's classname to func_button/cycler_sprite.

Hum, i guess it would be better to spawn a func_button, and then to alter the classname to a custom classname.

joropito 01-29-2010 21:13

Re: problem +USE in ent
 
frk, make it simple

With your code here

1- You can try with func_pushable too
2- ToqueLaCosa is wrong. The correct declaration of that function must be like this
PHP Code:

public ToqueLaCosa(thisidcalleridactivatoruse_typeFloat:value

3- Try first without any classname change and registerham at plugin_init
PHP Code:

RegisterHam(Ham_Use"func_button""ToqueLaCosa"



All times are GMT -4. The time now is 07:21.

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