AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Remove HE grenade when it touches the ground (https://forums.alliedmods.net/showthread.php?t=319116)

wicho 10-12-2019 01:42

Remove HE grenade when it touches the ground
 
Hi everybody, well I want to create a mini game that consists of the players only having the HE grenade and the objective is to throw them at the players, if the grenade touches the player he dies instantly, if the player throws the grenade and fails I want the moment he touches the ground disappears, I don't want it to explode just that it disappears and gives the player another grenade, my questions are first how can I make when the player receives the blow of the grenade dies instantly, second how can I make when the grenade touches the ground or anything other than the player removes the grenade and gives the player a new one, could you please give me an example? ... Thanks in advance

Bugsy 10-12-2019 10:39

Re: Remove HE grenade when it touches the ground
 
Try this
PHP Code:


#include <amxmodx>
#include <hamsandwich>
#include <engine>
#include <fakemeta>
#include <fun>

new const Version[] = "0.1";

#define MAX_PLAYERS 32

#define IsPlayer(%1)    (1<=%1<=MAX_PLAYERS)

public plugin_init() 
{
    
register_plugin"Grenades" Version "bugsy" );
    
    
RegisterHamHam_Touch "grenade" "Grenade_Touch" );
    
register_forwardFM_SetModel "SetModel" );
}

public 
Grenade_TouchiToucher iTouched )
{
    if ( 
cs_get_grenade_typeiToucher ) == CSW_HEGRENADE )
    {
        new 
iGrenadeThrower peviToucher pev_owner );
        
        if ( 
IsPlayeriTouched ) )
        {
            
set_peviToucher pev_dmgtime 0.0 );
            
ExecuteHamHam_TakeDamage iTouched iToucher iGrenadeThrower 999.9 DMG_GRENADE );
        }
        else
        {
            
set_peviToucher pev_flags peviToucher pev_flags ) | FL_KILLME );
            
call_thinkiToucher );
        }
        
        if ( 
is_user_aliveiGrenadeThrower ) )
            
give_itemiGrenadeThrower "weapon_hegrenade" );

        return 
HAM_HANDLED;
    }
    
    return 
HAM_IGNORED;



public 
SetModeliEntity , const szModel[] )
{
    if ( 
cs_get_grenade_typeiEntity ) == CSW_HEGRENADE )
    {
        
set_peviEntity pev_dmgtime 99999.0 );
    }
}
    
cs_get_grenade_typeindex 
{
    if (!
pev_valid(index))
        return 
0
    
    
new classname[9]
    
pev(indexpev_classnameclassname8)
    
    if (!
equal(classname"grenade"))
        return 
0
    
    
if (get_pdata_int(index96) & (1<<8))
        return 
CSW_C4
    
    
new bits get_pdata_int(index114)
    
    if (
bits & (1<<0))
        return 
CSW_HEGRENADE
    
else if (bits & (1<<1))
        return 
CSW_SMOKEGRENADE
    
else if (!bits)
        return 
CSW_FLASHBANG
    
    
return 0



wicho 10-12-2019 11:49

Re: Remove HE grenade when it touches the ground
 
ok thanks i will try it when i get to my house, i just forgot to ask something else, how can i do so that the grenade doesn't explode in the air? I mean, when you throw the grenade in the air, it is only removed when it touches the ground or when it hits the player. Another thing if the player hits the player also gives him a grenade. thx for your help

Bugsy 10-12-2019 15:08

Re: Remove HE grenade when it touches the ground
 
Above code is updated based on your comments.

JocAnis 10-12-2019 16:20

Re: Remove HE grenade when it touches the ground
 
Good job Bugsy, one question, what is exactly 'call_think' doing? I hope it can be used for smth else beside hegrenade

Natsheh 10-12-2019 17:00

Re: Remove HE grenade when it touches the ground
 
He used it to safely remove the entity after giving the entity the Flag FL_KILLME

Bugsy 10-12-2019 17:01

Re: Remove HE grenade when it touches the ground
 
That is how I am killing the grenade entity, after setting the FL_KILLME flag.

JocAnis 10-12-2019 18:54

Re: Remove HE grenade when it touches the ground
 
Hm okay, interesting

Ps nice timing hah

wicho 10-13-2019 11:32

Re: Remove HE grenade when it touches the ground
 
bugsy I tested your code and it works fine but sometimes when I throw the grenade it doesn't give me a new grenade, I think that happens when I throw it to a map entity (func_wall, etc)

Bugsy 10-13-2019 11:34

Re: Remove HE grenade when it touches the ground
 
Quote:

Originally Posted by wicho (Post 2669668)
bugsy I tested your code and it works fine but sometimes when I throw the grenade it doesn't give me a new grenade, I think that happens when I throw it to a map entity (func_wall, etc)

Ok, try the above updated code.


All times are GMT -4. The time now is 02:53.

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