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

ptouched and kill


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 02-07-2022 , 11:37   ptouched and kill
Reply With Quote #1

Hello, I use this code and I would like that when someone touches the entity it dies, but the frag is added to the person who created the entity

At the moment I can only make them die when they touch the entity, but I would like the frag to be added to whoever created the entity

PHP Code:

//----------------------------------------------------------------------------------------------
public pfn_touch(ptrptd
{
    if(!
is_valid_ent(ptd) || !is_valid_ent(ptr))
        return 
PLUGIN_CONTINUE
            
    
if(!is_user_connected(ptd) || !is_user_alive(ptd))
        return 
PLUGIN_CONTINUE
    
    
new classname[32]
    
entity_get_string(ptrEV_SZ_classnameclassname31)
    if(
equal(classname"coronavirus")) {
            
            
// This is to make the one who touches the entity die
            
new gOrigHealth get_user_health(ptd)
            new 
health gOrigHealth gOrigHealth
            
            set_user_health
(ptdhealth)    
            
            
remove_entity(ptr)
        
    }
    
    return 
PLUGIN_CONTINUE
}
//---------------------------------------------------------------------------------------------- 
Arje is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-07-2022 , 11:52   Re: ptouched and kill
Reply With Quote #2

PHP Code:
//----------------------------------------------------------------------------------------------
public pfn_touch(ptrptd
{
    if(!
is_valid_ent(ptr) || !is_user_alive(ptd))
        return
    
    static 
classname[32];
    
entity_get_string(ptrEV_SZ_classnameclassname31)
    if(
equal(classname"coronavirus")) {
            
            
// This is to make the one who touches the entity die
            
set_user_health(ptd, -1);
            
entity_set_int(ptdEV_INT_deadflagDEAD_DYING);

            static 
iOwner;
            
iOwner entity_get_edict(ptrEV_ENT_owner);

            if(
is_user_connected(iOwner))
            {
                
set_user_frags(iOwnerget_user_frags(iOwner) + 1);

                static 
pUserMsgDeathMSG 0; if(!pUserMsgDeathMSGpUserMsgDeathMSG get_user_msgid("DeathMsg");
                
message_begin(MSG_ALLpUserMsgDeathMSG_0);
                
write_byte(iOwner);
                
write_byte(ptd);
                
write_byte(0);
                
write_string("coronavirus");
                
message_end();
            }
            
            
remove_entity(ptr);
    }
    
    return 
PLUGIN_CONTINUE
}
//---------------------------------------------------------------------------------------------- 
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-07-2022 at 14:46.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 02-07-2022 , 12:29   Re: ptouched and kill
Reply With Quote #3

sorry but it didn't work, it still only counts as kill, and doesn't add frag to which the entity was created

this is all important of the code

PHP Code:

public plugin_init()
{
// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
    
register_event("ResetHUD""newRound","b")
        
register_event("DeathMsg","deathevent","a")
}

//----------------------------------------------------------------------------------------------
public newRound()
{
    new 
coronavirus find_ent_by_class(-1"coronavirus")
    while(
coronavirus) {
        
remove_entity(coronavirus)
        
coronavirus find_ent_by_class(coronavirus"coronavirus")
    }
}
//----------------------------------------------------------------------------------------------
public deathevent
{
        new 
killer read_data(1)
    new 
victim read_data(2)

    if ( 
victim == killer ) return
     
    if ( 
is_user_alive(killer ) && gHasCoronaPower[killer ] ) {
        
            
createcoronavirus(victim)
            new 
aimvec[3]
            
get_user_origin(victimaimvec)
            
            
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
            
write_byte(23)
            
write_coord(aimvec[0])
            
write_coord(aimvec[1])
            
write_coord(aimvec[2])
            
write_short(Smoke)
            
write_byte(001)
            
write_byte(65)
            
write_byte(200)
            
message_end()
            
aimvec[2] -= 100
            set_user_origin
(victimaimvec
        }


//----------------------------------------------------------------------------------------------
public createcoronavirus(victim)
{
    new 
Float:vAim[3], Float:vOrigin[3]
    
entity_get_vector(victimEV_VEC_originvOrigin)
    
VelocityByAim(victimrandom_num(24), vAim)
    
    
vOrigin[0] += vAim[0]
    
vOrigin[1] += vAim[1]
    
vOrigin[2] += 30.0
    
    
new coronavirus create_entity("info_target")
    
entity_set_string(coronavirusEV_SZ_classname"coronavirus")
    
entity_set_model(coronavirus"models/shmod/coronavirus.mdl")    
    
entity_set_size(coronavirusFloat:{-2.5, -2.5, -1.5}, Float:{2.52.51.5})
    
entity_set_int(coronavirusEV_INT_solid2)
    
entity_set_int(coronavirusEV_INT_movetype6)
    
entity_set_vector(coronavirusEV_VEC_originvOrigin)
}
//----------------------------------------------------------------------------------------------
public pfn_touch(ptrptd
{
    if(!
is_valid_ent(ptd) || !is_valid_ent(ptr))
        return 
PLUGIN_CONTINUE
            
    
if(!is_user_connected(ptd) || !is_user_alive(ptd))
        return 
PLUGIN_CONTINUE
    
    
new classname[32]
    
entity_get_string(ptrEV_SZ_classnameclassname31)
    if(
equal(classname"coronavirus")) {

            static 
pUserMsgDeathMSG 0; if(!pUserMsgDeathMSGpUserMsgDeathMSG get_user_msgid("DeathMsg");
            
// This is to make the one who touches the entity die
            
set_user_health(ptd, -1

            static 
iOwner;
            
iOwner entity_get_edict(ptrEV_ENT_owner);
    
            if(
is_user_connected(iOwner)) {
            
                
set_user_frags(iOwnerget_user_frags(iOwner) + 1);
                
message_begin(MSG_ALLpUserMsgDeathMSG_0);
                
write_byte(iOwner);
                
write_byte(ptd);
                
write_byte(0);
                
write_string("coronavirus");
                
message_end();
            }
        
            
remove_entity(ptr);
           } 
    
    return 
PLUGIN_CONTINUE

Arje is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-07-2022 , 12:44   Re: ptouched and kill
Reply With Quote #4

its because you're not setting the entity ownership when creating...

replace the function

PHP Code:
public createcoronavirus(victim)
{
    new 
Float:vAim[3], Float:vOrigin[3]
    
entity_get_vector(victimEV_VEC_originvOrigin)
    
VelocityByAim(victimrandom_num(24), vAim)
    
    
vOrigin[0] += vAim[0]
    
vOrigin[1] += vAim[1]
    
vOrigin[2] += 30.0
    
    
new coronavirus create_entity("info_target")
    
entity_set_string(coronavirusEV_SZ_classname"coronavirus")
    
entity_set_model(coronavirus"models/shmod/coronavirus.mdl")    
    
entity_set_size(coronavirusFloat:{-2.5, -2.5, -1.5}, Float:{2.52.51.5})
    
entity_set_edict(coronavirusEV_ENT_ownervictim);
    
entity_set_int(coronavirusEV_INT_solid2)
    
entity_set_int(coronavirusEV_INT_movetype6)
    
entity_set_vector(coronavirusEV_VEC_originvOrigin)

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-07-2022 at 14:48.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 02-07-2022 , 13:53   Re: ptouched and kill
Reply With Quote #5

sorry but it didn't work that way either because it wouldn't let me compile, however in this way I replaced

PHP Code:
entity_set_edict(coronavirusEV_EDICT_ownervictim); 
for: (thanks for the guidance)

PHP Code:
entity_set_edict(coronavirusEV_ENT_ownercoronaowner
the code was like this:

PHP Code:
//----------------------------------------------------------------------------------------------
public sh_client_death(victimattacker)
{
    if ( !
sh_is_active() || !sh_is_inround() ) return
    
    if ( 
victim == attacker ) return
     
    new 
randnum random_num(0100)
    new 
coronachance floatround(get_pcvar_float(pcvarPercent) * 100)
     
    if ( 
coronachance >= randnum && is_user_alive(attacker) && gHasCoronaPower[attacker] ) {
        
            new 
parm[2]
            
parm[0] = victim
            parm
[1] = attacker 
            createcoronavirus
(parm)
            
            new 
aimvec[3]
            
get_user_origin(victimaimvec)
            
            
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
            
write_byte(23)
            
write_coord(aimvec[0])
            
write_coord(aimvec[1])
            
write_coord(aimvec[2])
            
write_short(Smoke)
            
write_byte(001)
            
write_byte(65)
            
write_byte(200)
            
message_end()
            
aimvec[2] -= 100
            set_user_origin
(victimaimvec
        }


//----------------------------------------------------------------------------------------------
public createcoronavirus(parm[])
{
    new 
victim parm[0]
    new 
coronaowner parm[1]
    
    new 
Float:vAim[3], Float:vOrigin[3]
    
entity_get_vector(victimEV_VEC_originvOrigin)
    
VelocityByAim(victimrandom_num(24), vAim)
    
    
vOrigin[0] += vAim[0]
    
vOrigin[1] += vAim[1]
    
vOrigin[2] += 30.0
    
    
new coronavirus create_entity("info_target")
    
entity_set_string(coronavirusEV_SZ_classname"coronavirus")
    
entity_set_model(coronavirus"models/shmod/coronavirus.mdl")    
    
entity_set_size(coronavirusFloat:{-2.5, -2.5, -1.5}, Float:{2.52.51.5})
    
entity_set_edict(coronavirusEV_ENT_ownercoronaowner)
    
entity_set_int(coronavirusEV_INT_solid2)
    
entity_set_int(coronavirusEV_INT_movetype6)
    
entity_set_vector(coronavirusEV_VEC_originvOrigin)
    
}
//----------------------------------------------------------------------------------------------
public pfn_touch(ptrptd
{
    if(!
is_valid_ent(ptd) || !is_valid_ent(ptr))
        return 
PLUGIN_CONTINUE
            
    
if(!is_user_connected(ptd) || !is_user_alive(ptd))
        return 
PLUGIN_CONTINUE
    
    
new classname[32]
    
entity_get_string(ptrEV_SZ_classnameclassname31)
    if(
equal(classname"coronavirus")) {
        
        static 
pUserMsgDeathMSG 0; if(!pUserMsgDeathMSGpUserMsgDeathMSG get_user_msgid("DeathMsg");
        
        static 
iOwner;
        
iOwner entity_get_edict(ptrEV_ENT_owner);

        if( 
is_user_connected(iOwner) ) {
            
            
set_user_frags(iOwnerget_user_frags(iOwner) + 1);
            
message_begin(MSG_ALLpUserMsgDeathMSG_0);
            
write_byte(iOwner);
            
write_byte(ptd);
            
write_byte(0);
            
write_string("coronavirus");
            
message_end();
            
            
// This is to make the one who touches the entity die
            
set_user_health(ptd, -1);
        }
            
        
remove_entity(ptr);
    
            
            
    } 
    
    return 
PLUGIN_CONTINUE

and now the code works but wrong, for example when someone touches the entity it dies twice, the first one appears as if you killed it but it does not add frag, and the second one as if you had put kill on the console

but then when you kill someone the next time, instead of giving you a frag it gives you two frags, that's why I say it works well but badly

Sorry if I don't express it well in English I can try again
Arje is offline
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 02-07-2022 , 14:16   Re: ptouched and kill
Reply With Quote #6

Finally I was able to make it work now it works correctly, thank you very much for the help it really helped me a lot, thank you

I had to change some things in this function and use natives of the superhero include

PHP Code:
//----------------------------------------------------------------------------------------------
public pfn_touch(ptrptd
{
    if(!
is_valid_ent(ptd) || !is_valid_ent(ptr))
        return 
PLUGIN_CONTINUE
            
    
if(!is_user_connected(ptd) || !is_user_alive(ptd))
        return 
PLUGIN_CONTINUE
    
    
new classname[32]
    
entity_get_string(ptrEV_SZ_classnameclassname31)
    if(
equal(classname"coronavirus")) {
        
        static 
iOwner;
        
iOwner entity_get_edict(ptrEV_ENT_owner);

        if( 
is_user_connected(iOwner) && is_user_alive(iOwner) ) {
            
            
// This is to make the one who touches the entity die
            // Make damage to target
            
new damage read_data(2)
            
            
sh_extra_damage(ptdiOwnerdamage"Por CoronaVirus"0SH_DMG_KILL)
        }
        
        
remove_entity(ptr);
    } 
    
    return 
PLUGIN_CONTINUE
}
//---------------------------------------------------------------------------------------------- 
Arje is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-07-2022 , 14:31   Re: ptouched and kill
Reply With Quote #7

Thats because touch forward is called many times per second, and you need to make the dead player think after setting his hp to -1 or you can simply set touched player dead flag, ill fix my code and you better use it because youre doing alot of useless checks in addition creating new variables in a forward that is called many times per sec which youre working the cpu hard, and we don't want to make the cpu work hard or it gets upset.


Code in the post was edited!
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-07-2022 at 14:48.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 02-07-2022 , 14:45   Re: ptouched and kill
Reply With Quote #8

ok thanks if you can make the previous code work correctly I will use it, for now the last one I uploaded works

I don't understand much about how to do that to overload the CPU, I'm quite new to this but thanks for the help
Arje 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 10:12.


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