Raised This Month: $32 Target: $400
 8% 

[L4D2] Help to auto kill infected


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
diorfo
Member
Join Date: Dec 2013
Old 05-08-2017 , 19:12   [L4D2] Help to auto kill infected
Reply With Quote #1

Hello,

I'm trying to develop a plugin to auto kill spitter after spit_burst event to avoid players hold spitter for long time in game.

Tried the below code but didn't work and i don't know why:

PHP Code:
#include <sourcemod> 
#include <sdktools> 

#define PLUGIN_VERSION "1.0" 

public Plugin:myinfo 

    
name "Spitter Auto Kill"
    
author "diorfo"
    
description "Spitter Auto Kill after Spit"
    
version PLUGIN_VERSION
    
url "" 


public 
OnPluginStart() 

    
CreateConVar("sm_l4d2_spitter_auto_kill"PLUGIN_VERSION"Spitter Auto Kill"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY); 
     
    
HookEvent("spit_burst"Event_SpitBurst); 



public 
Event_SpitBurst (Handle:event, const String:name[], bool:dontBroadcast

    new 
client GetClientOfUserId(GetEventInt(event,"userid")); 
    new 
Handle:idfix CreateDataPack();   
    
WritePackCell(idfixGetClientUserId(client)); 
    
PrintToChat(client"\x04[SM] \x05Voce spitou e morrera em 10s"); 
    
CreateTimer(10.0kill_spitter); 


public 
Action:kill_spitter(Handle:timerany:idfix

    
GetClientOfUserId(ReadPackCell(idfix)); 
    
ForcePlayerSuicide(idfix); 

looks like the id of spitter is losing in public Action:kill_spitter because if i change the CreateTimer(10.0, kill_spitter) for ForcePlayerSuicide(client) the spitter is killed instantly after spit and i'd like to set a time before she get auto killed.

Any ideas what is it wrong in code?
diorfo is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 05-08-2017 , 20:09   Re: [L4D2] Help to auto kill infected
Reply With Quote #2

If i understand this correctly then this would do the trick.

PHP Code:
#include <sourcemod>  
#include <sdktools>  

#define PLUGIN_VERSION "1.0"  

public Plugin myinfo =  
{  
    
name "Spitter Auto Kill",  
    
author "diorfo",  
    
description "Spitter Auto Kill after Spit",  
    
version PLUGIN_VERSION,  
    
url ""  
}  

public 
void OnPluginStart()  
{  
    
CreateConVar("sm_l4d2_spitter_auto_kill"PLUGIN_VERSION"Spitter Auto Kill"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);  
    
HookEvent("spit_burst"Event_SpitBurst);  
}  

public 
Action Event_SpitBurst(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    if(
IsValidClient(client)
    {
        
PrintToChat(client"\x04[SM] \x05Voce spitou e morrera em 10s");  
        
CreateTimer(10.0kill_spitterGetClientUserId(client));
    }
    return 
Plugin_Continue;


public 
Action kill_spitter(Handle timerany userid)  
{  
    
int client GetClientOfUserId(userid);  
    if(
IsValidClient(client) && IsPlayerAlive(client))
    {
        
ForcePlayerSuicide(client);
    }
    return 
Plugin_Stop;
}

stock bool IsValidClient(int client)
{
    return (
<= client <= MaxClients && IsClientInGame(client));

__________________
xines is offline
diorfo
Member
Join Date: Dec 2013
Old 05-08-2017 , 21:11   Re: [L4D2] Help to auto kill infected
Reply With Quote #3

worked.

thank you
diorfo is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 05-09-2017 , 10:17   Re: [L4D2] Help to auto kill infected
Reply With Quote #4

The issue in your first code was that you never send the datapack handle to the timer function. So it would try to access an unknown datapack which the error log should show.
xerox8521 is offline
diorfo
Member
Join Date: Dec 2013
Old 05-09-2017 , 17:23   Re: [L4D2] Help to auto kill infected
Reply With Quote #5

Quote:
Originally Posted by xerox8521 View Post
The issue in your first code was that you never send the datapack handle to the timer function. So it would try to access an unknown datapack which the error log should show.
Probably that's why i was receiving some lose identification warning.
diorfo is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-20-2019 , 19:32   Re: [L4D2] Help to auto kill infected
Reply With Quote #6

Edit (20-January-2019)

There is a new version released here.
_____________________________________________ ___________________________________________

Here is the working code.

PHP Code:
#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.0"

public Plugin myinfo =
{
    
name "Spitter Auto Kill",
    
author "diorfo",
    
description "Spitter Auto Kill after Spit",
    
version PLUGIN_VERSION,
    
url ""
}

public 
void OnPluginStart()
{
    
CreateConVar("sm_l4d2_spitter_auto_kill"PLUGIN_VERSION"Spitter Auto Kill"FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
HookEvent("spit_burst"Event_SpitBurst);
}

public 
Action Event_SpitBurst(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    if(
IsValidClient(client))
    {
        
PrintToChat(client"\x04[SM] \x05Voce spitou e morrera em 10s");
        
CreateTimer(10.0kill_spitterGetClientUserId(client));
    }
    return 
Plugin_Continue;
}

public 
Action kill_spitter(Handle timerany userid)
{
    
int client GetClientOfUserId(userid);
    if(
IsValidClient(client) && IsPlayerAlive(client))
    {
        
ForcePlayerSuicide(client);
    }
    return 
Plugin_Stop;
}

stock bool IsValidClient(int client)
{
    return (
<= client <= MaxClients && IsClientInGame(client));

__________________

Last edited by Marttt; 04-02-2019 at 07:21.
Marttt is offline
Reply


Thread Tools
Display Modes

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 08:42.


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