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

Solved [L4D2] Tank fire immunity


Post New Thread Reply   
 
Thread Tools Display Modes
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 05-26-2018 , 10:30   Re: [L4D2] Tank fire immunity
Reply With Quote #11

Quote:
Originally Posted by Silvers View Post
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
// Nice and simple we have an event for tank spawning
    
HookEvent("tank_spawn"Event_TankSpawn);
}

public 
Action Event_TankSpawn(Handle eventchar[] namebool dontBroadcast)
{
    
int client GetEventInt(event"userid");
    
client GetClientOfUserId(client);

    if( 
client && IsClientInGame(client) )
    {
        
// We only need to hook when the tank spawns
        
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
    }
}  

public 
Action OnTakeDamage(int clientint &attackerint &inflictorfloat &damageint &damagetype)
{
    if( 
damagetype == 268435464 )
    {
        
ExtinguishEntity(client);
        
SetEntPropFloat(clientProp_Send"m_burnPercent"1.0);

        
// If you want to completely block damage caused by walking in the fire, these two lines do that:
        
damage 0.0;
        return 
Plugin_Changed;
    }
    return 
Plugin_Continue// No changes to damage.

You could remove the "return blah" and "damage = 0.0" lines if you don't want to change damage.

See Mutant Zombies plugin for more on dealing with fire and preventing the damage or you could reduce the damage etc.
You can simplify the following:

PHP Code:
int client GetEventInt(event"userid");
client GetClientOfUserId(client); 
To this:

PHP Code:
int client GetClientOfUserId(event.GetInt("userid")); 
__________________
Psyk0tik is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 05-26-2018 , 11:57   Re: [L4D2] Tank fire immunity
Reply With Quote #12

Just remember sometimes you need to check if the "userid" is not 0 before GetClientOfUserId() although this event should never give a userid of 0 so that would be fine.
__________________
Silvers is offline
alcybery
Member
Join Date: Apr 2016
Old 05-26-2018 , 19:50   Re: [L4D2] Tank fire immunity
Reply With Quote #13

Thank you very much.

Last edited by alcybery; 05-26-2018 at 19:52.
alcybery is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 05-27-2018 , 05:01   Re: [L4D2] Tank fire immunity
Reply With Quote #14

Quote:
Originally Posted by Silvers View Post
Just remember sometimes you need to check if the "userid" is not 0 before GetClientOfUserId() although this event should never give a userid of 0 so that would be fine.
I've never had to do that on any event. Can you show me an exact example of its usage?

int GetClientOfUserId(int userid)

Code:
Errors

Returns 0 if invalid userid.
Valid userids are > 0 anyway.

Also, it's always good form to perform client index validation checks after int client = GetClientOfUserId(event.GetInt("userid"));
Depending on what you're doing to the client, you may also want to check client connected/is in game state.

Last edited by Visual77; 05-27-2018 at 05:08.
Visual77 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 05-27-2018 , 06:15   Re: [L4D2] Tank fire immunity
Reply With Quote #15

Code:
Name: 	player_death
short 	userid 	user ID who died
long 	entityid 	entity ID who died, userid should be used first, to get the dead Player. Otherwise, it is not a player, so use this.
short 	attacker 	user ID who killed
__________________
Silvers is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 05-27-2018 , 07:02   Re: [L4D2] Tank fire immunity
Reply With Quote #16

Quote:
Originally Posted by Silvers View Post
Code:
Name: 	player_death
short 	userid 	user ID who died
long 	entityid 	entity ID who died, userid should be used first, to get the dead Player. Otherwise, it is not a player, so use this. 
short 	attacker 	user ID who killed
That event is no different than any others. Eg, what Crasher_3637 pointed out as an simplification would suffice in any event.
Just remember to always validate the cliient index to avoid unwanted console errors.


Code:
public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(event.GetInt("userid"));

	if (client < 1 || client > MaxClients || !IsClientConnected(client))  // Here I validate the client index and validate IsClientConnected so that PrintToChat don't error out if the player disconnects during the same frame.
	{
		return;
	}

        PrintToChat(client, "You died!");
}

Last edited by Visual77; 05-27-2018 at 07:13.
Visual77 is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 05-29-2018 , 16:28   Re: [L4D2] Tank fire immunity
Reply With Quote #17

I think a perfect example of when a userid can come back as 0 is after a player disconnects, then everything associated with said event becomes 0/world...Using ontakedamage sdkhook if a player throws a molly then disconnects, that mollies owner becomes 0/world. To the best of my knowledge. Ontakedamage isn't an event but i could see it possibly happening in an event.

In Silvers example of player death. attacker can be world I believe. Maybe from a fall or something.

Almost every Friendly Fire plugin i've seen doesn't take this into account so a player can throw a molly, immediately disconnect and friendly fire protection no longer works.

Last edited by MasterMind420; 05-29-2018 at 16:35.
MasterMind420 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 06:17.


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