Left 4 Dead 2

Left 4 Dead 2

View Stats:
Z Apr 6 @ 11:34am
Damage Witch using TakeDamage
so apparently my simple function will just crash the game every single time

function OnGameEvent_infected_hurt( params )
{
if ( params.attacker == 0 ) return;
local attacker = GetPlayerFromUserID(params.attacker); local witch = EntIndexToHScript(params.entityid );

witch.TakeDamage( 2000, 256, attacker);
}

anyone know of a way to damage Witch without crashing the game ?
Last edited by Z; Apr 6 @ 11:34am
Originally posted by kurochama:
That "infected_hurt" will cause damage loop that causes crash if you don't set the damage type. The the loop mechanism will be like this:
1. Witch takes damage from your gun
2. You set "TakeDamage" on "infected_hurt" when witch takes damage.
3. Witch takes damage from your "TakeDamage"
4. Loop back from no. 2 infinitely until it crashes.

One of safest mechanisms to use "infected_hurt" is by setting the "type", like this:
local damagetype = null; if(("type" in event)) { damagetype = event["type"]; } //if you want to stumble witch without causing crash with blast damage if(damagetype != 64) { witch.TakeDamage(200, 64, attacker); }
In other words, you need to use that "damagetype" to prevent damage loop so it won't crash anymore.
< >
Showing 1-7 of 7 comments
Evil Apr 6 @ 12:01pm 
This script function is all kinds of wonky. I'm far too tired to give this a full run down but try this, maybe it will work:

function AllowTakeDamage( damageTable ) { if( damageTable.Attacker.GetClassname() == "survivor" && damageTable.Victim.GetClassname() == "witch" ) { ScriptedDamageInfo.DamageDone = 5000; } return true; }
Last edited by Evil; Apr 6 @ 12:02pm
The author of this thread has indicated that this post answers the original topic.
That "infected_hurt" will cause damage loop that causes crash if you don't set the damage type. The the loop mechanism will be like this:
1. Witch takes damage from your gun
2. You set "TakeDamage" on "infected_hurt" when witch takes damage.
3. Witch takes damage from your "TakeDamage"
4. Loop back from no. 2 infinitely until it crashes.

One of safest mechanisms to use "infected_hurt" is by setting the "type", like this:
local damagetype = null; if(("type" in event)) { damagetype = event["type"]; } //if you want to stumble witch without causing crash with blast damage if(damagetype != 64) { witch.TakeDamage(200, 64, attacker); }
In other words, you need to use that "damagetype" to prevent damage loop so it won't crash anymore.
Z Apr 6 @ 2:59pm 
function OnGameEvent_infected_hurt( params ) { if ( params.attacker == 0 ) return; local attacker = GetPlayerFromUserID(params.attacker); local witch = EntIndexToHScript(params.entityid ); local zombietype = witch.GetZombieType() ; if (!zombietype == 7 ) return; local isheadshot = params.headshot; if (isheadshot) { attacker.ValidateScriptScope(); local attackerScope = attacker.GetScriptScope(); if ( attackerScope.1shot_token > 0 ) { attackerScope.1shot_token -= 1; local damagetype = null; if(("type" in event)) { damagetype = event["type"]; } if(damagetype != 64) { witch.TakeDamage( 2000, 64 , attacker); } } } }

side question: why would GetZombieType() not take witch/common EntID ? I keep getting [the index 'GetZombieType' does not exist]
Originally posted by zetgoodkid:
function OnGameEvent_infected_hurt( params ) { if ( params.attacker == 0 ) return; local attacker = GetPlayerFromUserID(params.attacker); local witch = EntIndexToHScript(params.entityid ); local zombietype = witch.GetZombieType() ; if (!zombietype == 7 ) return; local isheadshot = params.headshot; if (isheadshot) { attacker.ValidateScriptScope(); local attackerScope = attacker.GetScriptScope(); if ( attackerScope.1shot_token > 0 ) { attackerScope.1shot_token -= 1; local damagetype = null; if(("type" in event)) { damagetype = event["type"]; } if(damagetype != 64) { witch.TakeDamage( 2000, 64 , attacker); } } } }

side question: why would GetZombieType() not take witch/common EntID ? I keep getting [the index 'GetZombieType' does not exist]
"GetZombieType" is only for "player" classname (special infected, tank & survivor). & that "GetZombieType" no 7 is probably unused, as witch is not playable (not player). For witch, use "witch" on "GetClassname()" instead.
Z Apr 6 @ 8:21pm 
Originally posted by kurochama:
That "infected_hurt" will cause damage loop that causes crash if you don't set the damage type. The the loop mechanism will be like this:
1. Witch takes damage from your gun
2. You set "TakeDamage" on "infected_hurt" when witch takes damage.
3. Witch takes damage from your "TakeDamage"
4. Loop back from no. 2 infinitely until it crashes.

One of safest mechanisms to use "infected_hurt" is by setting the "type", like this:
local damagetype = null; if(("type" in event)) { damagetype = event["type"]; } //if you want to stumble witch without causing crash with blast damage if(damagetype != 64) { witch.TakeDamage(200, 64, attacker); }
In other words, you need to use that "damagetype" to prevent damage loop so it won't crash anymore.

still trying to figure out what this "event" of yours is. similiar to my parms in OnGameEvent_infected_hurt( params ) or is it something else ?
Originally posted by zetgoodkid:
Originally posted by kurochama:
That "infected_hurt" will cause damage loop that causes crash if you don't set the damage type. The the loop mechanism will be like this:
1. Witch takes damage from your gun
2. You set "TakeDamage" on "infected_hurt" when witch takes damage.
3. Witch takes damage from your "TakeDamage"
4. Loop back from no. 2 infinitely until it crashes.

One of safest mechanisms to use "infected_hurt" is by setting the "type", like this:
local damagetype = null; if(("type" in event)) { damagetype = event["type"]; } //if you want to stumble witch without causing crash with blast damage if(damagetype != 64) { witch.TakeDamage(200, 64, attacker); }
In other words, you need to use that "damagetype" to prevent damage loop so it won't crash anymore.

still trying to figure out what this "event" of yours is. similiar to my parms in OnGameEvent_infected_hurt( params ) or is it something else ?
That's "infected_hurt" too. I just gave a simple example just to show about that "damagetype" to prevent crash. & that "event" or "param" is just the same. It's just a matter of naming preference as both "infected_hurt(event)" & "infected_hurt(params)" can work

Actually you can also use "bullet_impact" to damage witch with "TakeDamage" & this one won't cause crash, but this event function is a little tricky because you also need to set the vector coordinate of the bullet (x,y,z) & detect a zombie hit by the bullet via "Entities.FindByClassname"
Last edited by kurochama; Apr 7 @ 12:45am
Originally posted by kurochama:
Originally posted by zetgoodkid:
.
"GetZombieType" is only for "player" classname (special infected, tank & survivor). & that "GetZombieType" no 7 is probably unused, as witch is not playable (not player). For witch, use "witch" on "GetClassname()" instead.
Thanks, this was really helpful
< >
Showing 1-7 of 7 comments
Per page: 1530 50