PDA

View Full Version : Damage Event


Peoples Army
08-10-2007, 03:34
i cant seem to catch the grenade damage . am i using the event right ??



/*
Napalm Grenades
Ignites Players Injured By Greandes
*/

#include <sourcemod>
#include <sdktools_functions>
#define VERSION "0.1"
new Handle:Switch;
new String:Weapon[30];
public Plugin:myinfo =
{
name = "Napalm grenades",
author = "Peoples Army",
description = "Ignites Players On Fire From Nades",
version = VERSION,
url = "www.sourcemod.net (http://www.sourcemod.net)"
};
// create convars and hook event
public OnPluginStart()
{
Switch = CreateConVar("napalm_nades_on","1","Turns the plugin on and off 1/0",FCVAR_NOTIFY);
HookEvent("player_hurt",DamageEvent);
}
//hook the player_hurt event and look for nade damge
public DamageEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
GetEventString(event,"weapon",Weapon,29);
new DmgDone = GetEventInt(event,"dmg_health");
new clientid = GetEventInt(event,"userid");
new client = GetClientOfUserId(clientid);

// if plugin is on and nade was found then ignite client

if(StrEqual(Weapon,"weapon_hegrenade")== true)
{
PrintToChat(client,"Youve Been Hit By A Nade");
switch(DmgDone)
{
case 0.30:IgniteEntity(client,3.0);
case 31.50:IgniteEntity(client,6.0);
case 51.70:IgniteEntity(client,9.0);
case 71.100:IgniteEntity(client,12.0);
}
}
}

Shaman
08-10-2007, 04:17
1-Using 'switch' in a variable name is not a good idea. Try not to use 'if', 'switch', 'while', etc. in variable names.
2-Are you sure that url works? There are lots of " in it.
3-Try to use 'health' instead of 'dmg_health'.
4-You don't have to use if(StrEqual(Weapon,"weapon_hegrenade")== true)
Use if(StrEqual(Weapon,"weapon_hegrenade")) instead.
5-Try with 'hegrenade' not 'weapon_hegrenade'.

Have a nice debugging ;)

teame06
08-10-2007, 10:20
Never -1 on the maxlen. You have to do sizeof(Weapon) or 30. This is how it is done in Sourcemod. If you do 30 - 1 for max len. When it reaches inside of the native etc your pretty much doing 30 - 2.

dalto
08-10-2007, 11:03
It is just "hegrenade" not "weapon_hegrenade"

Peoples Army
08-10-2007, 14:26
im catch the event now , but its not punishing . is my switch statement wrong too ???


p.s .

health isnt the byte i wanted.


"player_hurt"
{
"userid" "short" // player index who was hurt
"attacker" "short" // player index who attacked
"health" "byte" // remaining health points
"armor" "byte" // remaining armor points
"weapon" "string" // weapon name attacker used, if not the world
"dmg_health" "byte" // damage done to health
"dmg_armor" "byte" // damage done to armor
"hitgroup" "byte" // hitgroup that was damaged
}


and in my last plugin , StrEqual() wouldnt work for me unless i used == true , becuase it is a bool . so im gonna use it cause it works .

and yes were right its hegrenade . :wink:

dalto
08-10-2007, 15:01
im catch the event now , but its not punishing . is my switch statement wrong too ???

and in my last plugin , StrEqual() wouldnt work for me unless i used == true , becuase it is a bool . so im gonna use it cause it works .

I don't know much about grenade damage but are sure that grenades do that exact amount of damage all the time? Those aren't ranges.

Peoples Army
08-10-2007, 15:08
um so how do i do ranges?

dalto
08-10-2007, 16:04
um so how do i do ranges?

I don't think that SourcePawn switch statements support ranges. I have always gotten compiler errors whenever I have tried to use them.

You could just use an if statement

if(DmgDone > 0 && DmgDone <= 30)
IgniteEntity(client,3.0);
else if(DmgDone > 30 && DmgDone <= 50)
IgniteEntity(client,3.0);
else if(DmgDone > 50 && DmgDone <= 70)
IgniteEntity(client,3.0);
else if(DmgDone > 70)
IgniteEntity(client,3.0);

Peoples Army
08-10-2007, 16:09
thats why my switch statemnet only has 1 period in it , when i used 2 i got errors with the compiler , so i thought they might have changed to 1 . i really dont like else if statements but if thats all we got i got no choice :|

dalto
08-10-2007, 16:22
thats why my switch statemnet only has 1 period in it , when i used 2 i got errors with the compiler , so i thought they might have changed to 1 . i really dont like else if statements but if thats all we got i got no choice :|

The compiler probably accepted a single period because it was treating it as a decimal point.(This is also what I thought when I first read it. I had no idea why you were trying to catch .3 damage)

Peoples Army
08-10-2007, 17:07
oh lol . nope i was trying to do a range for sourcmod . its kinda hard programming for sourcmod , when its still in beta , theres no real info or plugins to follow yet . so everything is trial and error lol .

but i used a else if statement and it worksw now . thanks for the hel p :up: