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

Save health of entity


Post New Thread Reply   
 
Thread Tools Display Modes
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 03-02-2015 , 03:14   Re: Save health of entity
Reply With Quote #11

i used this https://forums.alliedmods.net/showthread.php?t=79581 but the forward think is different so i think i need to get and set the hp in returnmine and spawn, here:

PHP Code:
new FloatiMineHP[33]
new 
iRemoved[33

public 
ReturnMine(id)
{
    
id -= TASK_RELEASE;
    new 
tgt,body,Float:vo[3],Float:to[3];
    
get_user_aiming(id,tgt,body);
    if(!
pev_valid(tgt)) return;
    
pev(id,pev_origin,vo);
    
pev(tgt,pev_origin,to);
    if(
get_distance_f(vo,to) > 70.0) return;
    
    new 
EntityName[32];
    
pev(tgtpev_classnameEntityName31);
    if(!
equal(EntityNameENT_CLASS_NAME)) return;
    if(
pev(tgt,LASERMINE_OWNER) != id) return;
    
RemoveEntity(tgt);

    
iMineHP[id] = pev(tgtpev_health
    
iRemoved[id] = true

    g_havemine
[id] ++;
    
g_deployed[id] --;
    
    
emit_sound(idCHAN_ITEMENT_SOUND5VOL_NORMATTN_NORM0PITCH_NORM)
    
//ShowAmmo(id)

    
return;
}

public 
Spawnid )
{
    
id -= TASK_PLANT
    
// motor
    
new i_Ent engfunc(EngFunc_CreateNamedEntity,g_EntMine);
    if(!
i_Ent)
    {
        
client_print(id,print_chat,"[ZP] Can't Create Entity");
        return 
PLUGIN_HANDLED_MAIN;
    }
    
set_pev(i_Ent,pev_classname,ENT_CLASS_NAME);

    
engfunc(EngFunc_SetModel,i_Ent,ENT_MODELS);

    
set_pev(i_Ent,pev_solid,SOLID_NOT);
    
set_pev(i_Ent,pev_movetype,MOVETYPE_FLY);

    
set_pev(i_Ent,pev_frame,0);
    
set_pev(i_Ent,pev_body,3);
    
set_pev(i_Ent,pev_sequence,TRIPMINE_WORLD);
    
set_pev(i_Ent,pev_framerate,0);
    
    
set_pev(i_Ent,pev_takedamage,DAMAGE_YES);
    
    
set_pev(i_Ent,pev_dmg,100.0);
    
set_user_health(i_Ent,get_pcvar_num(g_LHEALTH));
    new 
Float:vOrigin[3];
    new    
Float:vNewOrigin[3],Float:vNormal[3],Float:vTraceDirection[3],
        
Float:vTraceEnd[3],Float:vEntAngles[3];
    
pevidpev_originvOrigin );
    
velocity_by_aimid128vTraceDirection );
    
xs_vec_addvTraceDirectionvOriginvTraceEnd );
    
    
engfuncEngFunc_TraceLinevOriginvTraceEndDONT_IGNORE_MONSTERSid);
    
    new 
Float:fFraction;
    
get_tr20TR_flFractionfFraction );
    

    
// -- We hit something!
    
if ( fFraction 1.0 )
    {
        
// -- Save results to be used later.
        
get_tr20TR_vecEndPosvTraceEnd );
        
get_tr20TR_vecPlaneNormalvNormal );
    }


    
xs_vec_mul_scalarvNormal8.0vNormal );
    
xs_vec_addvTraceEndvNormalvNewOrigin );

    
engfunc(EngFunc_SetSizei_EntFloat:{ -4.0, -4.0, -4.0 }, Float:{ 4.04.04.0 } );
    
engfunc(EngFunc_SetOrigini_EntvNewOrigin );

    
// -- Rotate tripmine.
    
vector_to_angle(vNormal,vEntAngles );
    
set_pev(i_Ent,pev_angles,vEntAngles );

    
// -- Calculate laser end origin.
    
new Float:vBeamEnd[3], Float:vTracedBeamEnd[3];
        
    
xs_vec_mul_scalar(vNormal8192.0vNormal );
    
xs_vec_addvNewOriginvNormalvBeamEnd );

    
engfuncEngFunc_TraceLinevNewOriginvBeamEndIGNORE_MONSTERS, -1);

    
get_tr20TR_vecPlaneNormalvNormal );
    
get_tr20TR_vecEndPosvTracedBeamEnd );

    
// -- Save results to be used later.
    
set_pev(i_EntLASERMINE_OWNERid );
    
set_pev(i_Ent,LASERMINE_BEAMENDPOINT,vTracedBeamEnd);
    
set_pev(i_Ent,LASERMINE_TEAM,2);
    new 
Float:fCurrTime get_gametime();

    
set_pev(i_Ent,LASERMINE_POWERUPfCurrTime 2.5 );
   
    
set_pev(i_Ent,LASERMINE_STEP,POWERUP_THINK);
    
set_pev(i_Ent,pev_nextthinkfCurrTime 0.2 );

    
PlaySound(i_Ent,POWERUP_SOUND );

    if(
iRemoved[id]) 
    { 
       
set_pev(i_Entpev_healthiMineHP[id]) = iMineHP[id
       
iRemoved[id] = false 
    


    
g_deployed[id]++;
    
g_havemine[id]--;
    
DeleteTask(id);

    
//ShowAmmo(id);
    
client_print(idprint_chat"[ZP] LaserMine has been planted, You have %i LaserMines Remaining"g_havemine[id])
    return 
1;

i only use one mine so i suppose i dont need to use the double array right?

P.S: i cant test now but tell me if it's okay..

Last edited by wicho; 03-02-2015 at 03:43.
wicho is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-02-2015 , 08:39   Re: Save health of entity
Reply With Quote #12

Almost fine, but:
PHP Code:
set_user_health(i_Ent,get_pcvar_num(g_LHEALTH)); 
You set default hp, and only after it you check if the mine is removed and set the new health. It doesn't matter much, but I would do as:

PHP Code:
if(iRemoved[id]) 

       
set_pev(i_Entpev_healthiMineHP[id])
       
iRemoved[id] = false 

else
{
       
set_user_health(i_Ent,get_pcvar_num(g_LHEALTH));

Notice that I removed =iMineHP[id] from your code, it's wrong.
__________________

Last edited by HamletEagle; 03-02-2015 at 08:40.
HamletEagle is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 03-02-2015 , 10:55   Re: Save health of entity
Reply With Quote #13

u mean this?

PHP Code:
public Spawnid )
{
    
id -= TASK_PLANT
    
// motor
    
new i_Ent engfunc(EngFunc_CreateNamedEntity,g_EntMine);
    if(!
i_Ent)
    {
        
client_print(id,print_chat,"[ZP] Can't Create Entity");
        return 
PLUGIN_HANDLED_MAIN;
    }
    
set_pev(i_Ent,pev_classname,ENT_CLASS_NAME);

    
engfunc(EngFunc_SetModel,i_Ent,ENT_MODELS);

    
set_pev(i_Ent,pev_solid,SOLID_NOT);
    
set_pev(i_Ent,pev_movetype,MOVETYPE_FLY);

    
set_pev(i_Ent,pev_frame,0);
    
set_pev(i_Ent,pev_body,3);
    
set_pev(i_Ent,pev_sequence,TRIPMINE_WORLD);
    
set_pev(i_Ent,pev_framerate,0);
    
    
set_pev(i_Ent,pev_takedamage,DAMAGE_YES);
    
    
set_pev(i_Ent,pev_dmg,100.0);

    if(
iRemoved[id]) 
    { 
       
set_pev(i_Entpev_healthiMineHP[id])
       
iRemoved[id] = false 
    

     else
    {
       
set_user_health(i_Ent,get_pcvar_num(g_LHEALTH));
    } 

    new 
Float:vOrigin[3];
    new    
Float:vNewOrigin[3],Float:vNormal[3],Float:vTraceDirection[3],
        
Float:vTraceEnd[3],Float:vEntAngles[3];
    
pevidpev_originvOrigin );
    
velocity_by_aimid128vTraceDirection );
    
xs_vec_addvTraceDirectionvOriginvTraceEnd );
    
    
engfuncEngFunc_TraceLinevOriginvTraceEndDONT_IGNORE_MONSTERSid);
    
    new 
Float:fFraction;
    
get_tr20TR_flFractionfFraction );
    

    
// -- We hit something!
    
if ( fFraction 1.0 )
    {
        
// -- Save results to be used later.
        
get_tr20TR_vecEndPosvTraceEnd );
        
get_tr20TR_vecPlaneNormalvNormal );
    }


    
xs_vec_mul_scalarvNormal8.0vNormal );
    
xs_vec_addvTraceEndvNormalvNewOrigin );

    
engfunc(EngFunc_SetSizei_EntFloat:{ -4.0, -4.0, -4.0 }, Float:{ 4.04.04.0 } );
    
engfunc(EngFunc_SetOrigini_EntvNewOrigin );

    
// -- Rotate tripmine.
    
vector_to_angle(vNormal,vEntAngles );
    
set_pev(i_Ent,pev_angles,vEntAngles );

    
// -- Calculate laser end origin.
    
new Float:vBeamEnd[3], Float:vTracedBeamEnd[3];
        
    
xs_vec_mul_scalar(vNormal8192.0vNormal );
    
xs_vec_addvNewOriginvNormalvBeamEnd );

    
engfuncEngFunc_TraceLinevNewOriginvBeamEndIGNORE_MONSTERS, -1);

    
get_tr20TR_vecPlaneNormalvNormal );
    
get_tr20TR_vecEndPosvTracedBeamEnd );

    
// -- Save results to be used later.
    
set_pev(i_EntLASERMINE_OWNERid );
    
set_pev(i_Ent,LASERMINE_BEAMENDPOINT,vTracedBeamEnd);
    
set_pev(i_Ent,LASERMINE_TEAM,2);
    new 
Float:fCurrTime get_gametime();

    
set_pev(i_Ent,LASERMINE_POWERUPfCurrTime 2.5 );
   
    
set_pev(i_Ent,LASERMINE_STEP,POWERUP_THINK);
    
set_pev(i_Ent,pev_nextthinkfCurrTime 0.2 );

    
PlaySound(i_Ent,POWERUP_SOUND );

    
g_deployed[id]++;
    
g_havemine[id]--;
    
DeleteTask(id);

    
//ShowAmmo(id);
    
client_print(idprint_chat"[ZP] LaserMine has been planted, You have %i LaserMines Remaining"g_havemine[id])
    return 
1;


Last edited by wicho; 03-02-2015 at 10:55.
wicho is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-02-2015 , 11:03   Re: Save health of entity
Reply With Quote #14

Yes.
__________________
HamletEagle is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 03-02-2015 , 11:48   Re: Save health of entity
Reply With Quote #15

i have tag mismatch here iMineHP[id] = pev(tgt, pev_health) I do not understand if it is a float..
wicho is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-02-2015 , 12:12   Re: Save health of entity
Reply With Quote #16

This is not the right way of doing it, you should read again my post: https://forums.alliedmods.net/showpo...13&postcount=2
__________________
HamletEagle is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 03-02-2015 , 12:16   Re: Save health of entity
Reply With Quote #17

Change it to:
PHP Code:
pev(tgtpev_healthiMineHp[id]) 
Unlike engine, fakemeta way of retrieving value use byref for all value types except interger.
__________________
Currently offline for study.
RateX is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 03-02-2015 , 14:27   Re: Save health of entity
Reply With Quote #18

i tested and for some reason when i plant again says that i dont have the mine, why?

appears this error:

L 03/02/2015 - 11:21:09: [FAKEMETA] Invalid entity
L 03/02/2015 - 11:21:09: [AMXX] Displaying debug trace (plugin "zp_extra_lasermine.amxx", version "1.4")
L 03/02/2015 - 11:21:09: [AMXX] Run time error 10: native error (native "pev")
L 03/02/2015 - 11:21:09: [AMXX] [0] Untitled.sma::ReturnMine (line 424)

this line:

PHP Code:
pev(tgtpev_healthiMineHP[id]) 
but why invalid, if it already checked if its valid or not..

PHP Code:
public ReturnMine(id)
{
    
id -= TASK_RELEASE;
    new 
tgt,body,Float:vo[3],Float:to[3];
    
get_user_aiming(id,tgt,body);
    if(!
pev_valid(tgt)) return;
    
pev(id,pev_origin,vo);
    
pev(tgt,pev_origin,to);
    if(
get_distance_f(vo,to) > 70.0) return;
    
    new 
EntityName[32];
    
pev(tgtpev_classnameEntityName31);
    if(!
equal(EntityNameENT_CLASS_NAME)) return;
    if(
pev(tgt,LASERMINE_OWNER) != id) return;
    
RemoveEntity(tgt);
    
    
pev(tgtpev_healthiMineHP[id]) 
         
iRemoved[id] = true 

    g_havemine
[id] ++;
    
g_deployed[id] --;
    
emit_sound(idCHAN_ITEMENT_SOUND5VOL_NORMATTN_NORM0PITCH_NORM)
    
//ShowAmmo(id)

    
return;


Last edited by wicho; 03-02-2015 at 14:40.
wicho is offline
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 03-02-2015 , 19:57   Re: Save health of entity
Reply With Quote #19

Dude, just look at the line above it -.-
__________________
Currently offline for study.
RateX is offline
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 03-03-2015 , 01:34   Re: Save health of entity
Reply With Quote #20

Ya i know i already fixed i forgot to edit the post, thx to all..
wicho 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 21:32.


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