AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Spawn a HE grenade on player. (https://forums.alliedmods.net/showthread.php?t=157144)

Voltron 05-17-2011 02:50

Spawn a HE grenade on player.
 
Code:

new nade = engfunc(EngFunc_CreateNamedEntity, "armoury_entity");
set_pev(nade, pev_classname, "grenade");
entity_set_int(nade,EV_ENT_owner, owner);
engfunc(EngFunc_SetOrigin, nade, playerOrigin);
engfunc(EngFunc_SetModel, nade, "models/w_hegrenade.mdl");
set_pev(nade, pev_movetype, MOVETYPE_TOSS);
set_pev(nade, pev_solid, SOLID_TRIGGER);

Doesn't spawn a nade.
What am I doing wrong?

Leon M. 05-17-2011 02:57

Re: Spawn a HE grenade on player.
 
What do you want exactly?

If a player should get a nade then use this:
PHP Code:

give_item(id"weapon_hegrenade"

Don't forget to include fun.inc (#include <fun>) at the beginning of your file.

Voltron 05-17-2011 03:12

Re: Spawn a HE grenade on player.
 
Quote:

Originally Posted by Leon M. (Post 1470834)
What do you want exactly?

I want to spawn a HE nade on or near a player and then detonate it.

Leon M. 05-17-2011 03:45

Re: Spawn a HE grenade on player.
 
I'm not sure if you can execute a detonation but you can create your own detonation.

PHP Code:

public plugin_init(){
        
//...
        
register_forward(FM_Think"fwd_think")
        
//...
}

// iVictim is your target ;)
public JohnDoe(iVictim){
                
//...

                // Create a fake hegrenade
                
new iEntity engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"))

                
engfunc(EngFunc_SetModeliEntity"models/w_hegrenade.mdl")
                
set_pev(iEntitypev_classname"fake_hegrenade")
                
set_pev(iEntitypev_owneriVictim)
                
set_pev(iEntitypev_iuser10)
                
set_pev(iEntitypev_mins, { -2.5, -2.5, -2.5})
                
set_pev(iEntitypev_maxs, { 2.52.52.5})
                
set_pev(iEntitypev_solidSOLID_TRIGGER)
                
set_pev(iEntitypev_movetypeMOVETYPE_TOSS)

                
// That's your timer for the detonation
                
set_pev(iEntitypev_nextthinkget_gametime() + 10.0)

                new 
Float:f_vAngles[3] = { 0.00.00.0}
                
f_vAngles[1] = random_float(0.0180.0)
                
set_pev(iEntitypev_anglesf_vAngles)

                new 
Float:f_vOrigin[3]
                
pev(iVictimpev_originf_vOrigin)
                
f_vOrigin[0] += 10.0
                engfunc
(EngFunc_SetOriginiEntityf_vOrigin)

                
//...
}

public 
fwd_think(iEntity){
    if (!
pev_valid(iEntity)){
        return 
FMRES_IGNORED
    
}

    new 
szClass[20]
    
pev(iEntitypev_classnameszClass19)

    if (
equal(szClass"fake_hegrenade")){
        
func_nade_explode(iEntity)
    }
    return 
FMRES_IGNORED
}

public 
func_nade_explode(iEntity){

    
// ... Do anything

    // Remove the nade
    
engfunc(EngFunc_RemoveEntityiEntity)




All times are GMT -4. The time now is 04:28.

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