Raised This Month: $51 Target: $400
 12% 

[TF2] Damage Modifier?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DanTycoon
New Member
Join Date: Aug 2008
Old 08-17-2008 , 18:39   [TF2] Damage Modifier?
Reply With Quote #1

I'm trying to learn how to make a plugin, and something I thought would be easy to do would be to change the amount of damage taken by, say, a scattergun bullet, then apply what I know from there to all the weapons.

I've searched for a while and I guess I'm not looking for the right thing because I'm pretty sure there's plugins out there that change the amount of damage per weapon. So how does one go about doing that?

I'm a noob to coding this kind of thing, so if you're going to give me code, could you please comment it so I know what does what? Thanks
DanTycoon is offline
DiscoBBQ
Veteran Member
Join Date: Jan 2005
Location: Clemson, South Carolina
Old 08-18-2008 , 01:44   Re: [TF2] Damage Modifier?
Reply With Quote #2

Your going to:
A. Hook an event with 'player_hurt'
B. On the callback for that, you will want to check for the weapon and then add some more damage by removing it from the health.
C. You can either prethink real quick to not kill them with the extra damage so it won't appear as a suicide, or you can go to a thread I few weeks ago in this subthread on creating custom death messages.

Here we go:
Code:
 
//Initation, this is a 'callback' it will be called one time in a plugin's life:
public OnPluginStart()
{
 
 //Hook the event, this makes it so the function 'EventDamage' will be called at the same time (or about the same time) as 'player_hurt' event.
 HookEvent("player_hurt", EventDamage);
}
 
//Now we write the hook, it has to be formatted like this for events:
public EventDamage(Handle:Event, const String:Name[], bool:Broadcast)
{
 
 //Notice EventDamage is the same thing we wrote in HookEvent, it creates this function as a hook. 'public' infront of it is used for call backs. Otherwise it is not neccessary.
 
 //Declare the variables we want to use:
 decl Client, Attacker; //Client & Attacker ID we need to find
 decl ClientHealth; //No functags it is an integer, meaning a number with no decimals.
 decl String:WeaponName[32]; //String means it is a sentence of standard ANSI characters. 32 in brackets is how many characters it can have, including a null terminator.
 
 
 //Now we initiliaze the variables:
 Client = GetClientOfUserId(GetEventInt(Event, "userid")); //These are parameters returned in the event player_hurt
 Attacker = GetClientOfUserId(GetEventInt(Event, "attacker"));
 ClientHealth = GetClientHealth(Client); //Gets the clients HP, integer.
 GetClientWeapon(Client, WeaponName, sizeof(WeaponName)); //Get's Weapon Name as a string.
 
 //Add Damage:
 if(StrContains(WeaponName, "scatter", false)) //This checks to see if their weapon name contains 'scatter', false is a parameter which means it is not case-sensative.
 {
 
  //So if it is a scatter gun:
  //We want to modify the damage...
  if(Health - 10 >= 1) //This makes sure they wont die from the extra damage to avoid death message interuption.
  SetEntityHealth(Client, Health - 10); //10 is the extra damage we want to add.
 }
 
//Close & Return:
CloseHandle(Event); //Always close handles
return Plugin_Handled;
}
__________________
"Every man is guilty of all the good he did not do"
DiscoBBQ is offline
DanTycoon
New Member
Join Date: Aug 2008
Old 08-18-2008 , 09:11   Re: [TF2] Damage Modifier?
Reply With Quote #3

Thanks, this is perfect!
DanTycoon is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 08-18-2008 , 19:17   Re: [TF2] Damage Modifier?
Reply With Quote #4

Actually, the code Pinkfaire has posted does not provide the name of the weapon that actually did the damage (which is NOT possible with TF2). It checks the weapon that the attacker is currently using (which is the same thing most of the time, but NOT all of the time). This is a subtle difference, but can make a big difference.

This method can be fooled by switching weapons (IE. Soldier fires rocket and switches to shovel before it hits) and will not also detect engineer's sentry as the weapon, ever - it will usually say it's the wrench.

Unfortunately, there isn't a better way of doing this, you just have to keep these limitations in mind.

I have used the same method to give a bonus for Melee attacks, but I had to add a distance calculation to ensure I didn't give Melee bonuses to people killed from across the map (; soldiers were switching weapons ;)
naris is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 08-18-2008 , 19:20   Re: [TF2] Damage Modifier?
Reply With Quote #5

Quote:
Originally Posted by Pinkfairie View Post
Code:
CloseHandle(Event); //Always close handles
return Plugin_Handled;
}
Actually, I don't think you are supposed to close event handles..
naris is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 08-19-2008 , 01:06   Re: [TF2] Damage Modifier?
Reply With Quote #6

You can but they are auto-closed when the event is finished if you don't
__________________
Greyscale is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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