AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can't make a eng2fm fakedamage function work (https://forums.alliedmods.net/showthread.php?t=74297)

Shaman 07-15-2008 19:15

Can't make a eng2fm fakedamage function work
 
PHP Code:

stock DamagePlayer(iddamagedamageTypeorigin[3])
    {
    new 
entityengfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"trigger_hurt"))
    
    
//Damage
    
set_kvd(0KV_ClassName"trigger_hurt")
    
set_kvd(0KV_KeyName"dmg")
    
set_kvd(0KV_Valuedamage)
    
set_kvd(0KV_fHandled0)
    
dllfunc(DLLFunc_KeyValueentity0)
    
    
//Damage Type
    
set_kvd(1KV_ClassName"trigger_hurt")
    
set_kvd(1KV_KeyName"damagetype")
    
set_kvd(1KV_ValuedamageType)
    
set_kvd(1KV_fHandled0)
    
dllfunc(DLLFunc_KeyValueentity1)
    
    
//Origin
    
set_kvd(2KV_ClassName"trigger_hurt")
    
set_kvd(2KV_KeyName"origin")
    
set_kvd(2KV_Valueorigin)
    
set_kvd(2KV_fHandled0)
    
dllfunc(DLLFunc_KeyValueentity2)
    
    
//Spawn the entity
    
dllfunc(DLLFunc_Spawnentity)
    
    
//Touch entity and the player
    
dllfunc(DLLFunc_Touchentityid)
    
    
//Remove the entity
    
engfunc(EngFunc_RemoveEntityentity)
    } 

When I use it like this to make a player kill another (with gibs):
PHP Code:

DamagePlayer(targethealthDMG_ALWAYSGIB|DMG_ENERGYBEAMorigin

the game crashes, but I can't find which function makes it crash.

danielkza 07-15-2008 22:12

Re: Can't make a eng2fm fakedamage function work
 
When something crashes I put a server_print("passed whatever") beetween each suspect statements to figure out what is wrong.

ot_207 07-16-2008 16:45

Re: Can't make a eng2fm fakedamage function work
 
PHP Code:

//From fakemeta_util.inc
stock fm_fakedamage(victim,const classname[],Float:takedmgdamage,damagetype)
{
    new 
classn[] = "trigger_hurt"
    
new entity engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,classn))
    if(!
entity) return 0
    
    
static value[16]
    
float_to_str((takedmgdamage 2),value,sizeof value 1)
    
fm_set_kvd(entity,"dmg",value,classn)

    
num_to_str(damagetype,value,sizeof value 1)
    
fm_set_kvd(entity,"damagetype",value,classn)

    
fm_set_kvd(entity,"origin","8192 8192 8192",classn)
    
dllfunc(DLLFunc_Spawn,entity)

    
set_pev(entity,pev_classname,classname)
    
    
dllfunc(DLLFunc_Touch,entity,victim)
    
    
engfunc(EngFunc_RemoveEntity,entity)

    return 
1
}


stock fm_set_kvd(entity,const key[],const value[],const classname[]="")
{
    if(
classname[0]) set_kvd(0,KV_ClassName,classname)
    else
    {
        new class[
32]
        
pev(entity,pev_classname,class,sizeof class - 1)
        
set_kvd(0,KV_ClassName,class)
    }

    
set_kvd(0,KV_KeyName,key)
    
set_kvd(0,KV_Value,value)
    
set_kvd(0,KV_fHandled,0)

    return 
dllfunc(DLLFunc_KeyValue,entity,0)



Arkshine 07-16-2008 18:00

Re: Can't make a eng2fm fakedamage function work
 
fakemeta_util :)

Shaman 07-17-2008 04:53

Re: Can't make a eng2fm fakedamage function work
 
That doesn't cover everything I need. Maybe I should add a new parameter and build the origin string myself.

Arkshine 07-17-2008 04:56

Re: Can't make a eng2fm fakedamage function work
 
What are you talking about ?! Oo

Shaman 07-17-2008 06:24

Re: Can't make a eng2fm fakedamage function work
 
This:
http://wiki.amxmodx.org/Half-Life_1_Game_Events#Damage

I want players to see where the shot came from.

ot_207 07-17-2008 06:36

Re: Can't make a eng2fm fakedamage function work
 
no but this does ->

This if you use fakedamage
PHP Code:

        fm_fakedamage(player,"classname",damage,3)
        
        
set_pev(player,pev_dmg_inflictor,ent)
        
set_pev(player,pev_dmg_save,0.0)
        
set_pev(player,pev_dmg_take,damage)
        
set_pev(player,pev_dmg,3)
            
        
emessage_begin(MSG_ONE,get_user_msgid("Damage"),{0,0,0},player)
        
ewrite_byte(0)
        
ewrite_byte(floatround(damage))
        
ewrite_long(3)
        
ewrite_coord(floatround(origin[0]))
        
ewrite_coord(floatround(origin[1]))
        
ewrite_coord(floatround(origin[2]))
        
emessage_end() 

I've tried to do the thing you said but it isn't possible to add origin since you fake touch the entity to the player ... so the damage comes from the inside.

But if you want to use hamsandwich (which is better)
This is the function that you need to use ->
PHP Code:

ExecuteHamB(Ham_TakeDamage,player,ent,pev(ent,pev_owner),damage,damagetype


Shaman 07-17-2008 11:29

Re: Can't make a eng2fm fakedamage function work
 
Thanks ot_207. This solved my problem:
PHP Code:

new entityengfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"trigger_hurt"))

ExecuteHamB(Ham_TakeDamagetargetentityid10000.0DMG_ENERGYBEAM|DMG_ALWAYSGIB)

engfunc(EngFunc_RemoveEntityentity



All times are GMT -4. The time now is 05:35.

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