Raised This Month: $ Target: $400
 0% 

Problem with identifying dead player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
VJScope
Senior Member
Join Date: Jul 2012
Location: Finland
Old 04-29-2014 , 11:51   Problem with identifying dead player
Reply With Quote #1

Hello! I just started practicing and I have some troubles with my plugin. This plugin was supposed to print to chat who dropped the bomb. But it shouldn't print the message if the bomb drops when a player dies. Right now it prints every drop (including when player dies). Can anyone help?

Code:
#include <sourcemod>

public Plugin:myinfo = {
	name = "Report bomb throwers",
	author = "VJScope",
	description = "Prints to all if a player throws the bomb",
	url = ""
};

public OnPluginStart()
{
	HookEvent("bomb_dropped", bomb_dropped);
}

public OnPluginEnd()
{
	UnhookEvent("bomb_dropped", bomb_dropped);
}

public Action:bomb_dropped(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	new String:cname[32]
	GetClientName(client, cname, 32);
	
	if(IsClientInGame(client) && IsPlayerAlive(client))
	{
		PrintToChatAll(" \x04[SM] Report : \x01Player \x03%s \x01Dropped the bomb!", cname);
	}
	
	return Plugin_Continue;
}
I also tried something like this but didn't have enough skills to finish:
Code:
#include <sourcemod>

new String:dname[32]

public Plugin:myinfo = {
	name = "Report bomb throwers",
	author = "VJScope",
	description = "Prints to all if a player throws the bomb at the base",
	url = "http://www.students.oamk.fi/~r0yltu00/"
};

public OnPluginStart()
{
	HookEvent("bomb_dropped", bomb_dropped);
	HookEvent("player_death", player_death);
}

public OnPluginEnd()
{
	UnhookEvent("bomb_dropped", bomb_dropped);
	UnhookEvent("player_death", player_death);
}

public Action:player_death(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	GetClientName(client, dname, 32);
}

public Action:bomb_dropped(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	new String:cname[32]
	GetClientName(client, cname, 32);
	
	if(//See if player who died was different than player who dropped the bomb, but how?)
	{
		PrintToChatAll(" \x04[SM] Report : \x01Player \x03%s \x01Dropped the bomb!", cname);
	}
	
	return Plugin_Continue;
}
__________________
Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony.

Last edited by VJScope; 04-29-2014 at 11:55.
VJScope is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 04-29-2014 , 12:01   Re: Problem with identifying dead player
Reply With Quote #2

Chances are the bomb_dropped event fires before the game considers the player to be killed.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 04-29-2014 , 12:04   Re: Problem with identifying dead player
Reply With Quote #3

Code:
#include <sourcemod>

public Plugin:myinfo = {
	name = "Report bomb throwers",
	author = "VJScope",
	description = "Prints to all if a player throws the bomb",
	url = ""
};

public OnPluginStart()
{
	HookEvent("bomb_dropped", bomb_dropped, EventHookMode_Pre);
}

public Action:bomb_dropped(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	
	if (IsClientInGame(client))
	{
		if (!IsPlayerAlive(client))
		{
			return Plugin_Continue;
		}
		
		PrintToChatAll(" \x04[SM] Report : \x01Player \x03%N \x01Dropped the bomb!", client);
	}
	return Plugin_Continue;
}
Drixevel is offline
VJScope
Senior Member
Join Date: Jul 2012
Location: Finland
Old 04-29-2014 , 12:47   Re: Problem with identifying dead player
Reply With Quote #4

Didn't work. It still prints when player gets killed.
__________________
Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony.
VJScope is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 04-29-2014 , 13:29   Re: Problem with identifying dead player
Reply With Quote #5

Use a 0.1 timer and pass the client info and then check if the client is dead or alive...

example
__________________
View my Plugins | Donate

Last edited by TnTSCS; 04-29-2014 at 13:30.
TnTSCS is offline
VJScope
Senior Member
Join Date: Jul 2012
Location: Finland
Old 04-29-2014 , 16:57   Re: Problem with identifying dead player
Reply With Quote #6

Seems to work. Thanks!
__________________
Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony.
VJScope is offline
VJScope
Senior Member
Join Date: Jul 2012
Location: Finland
Old 04-30-2014 , 06:45   Re: Problem with identifying dead player
Reply With Quote #7

Okay, now I have another problem. I'm trying to add new features to this plugin. I managed to get this plugin to take 99dmg from player who drops the bomb but I want that to end after 15 seconds. So in short:

If round has lasted 15sec or under and player drops the bomb = slap 99dmg and print a message.
Else = just print a message.

Here's what I tried:
Code:
#include <sourcemod>
#include <sdktools>

new Handle:h_Enabled = INVALID_HANDLE;
new Handle:h_DoDamage = INVALID_HANDLE;
new bool:g_dontSlap;

public Plugin:myinfo = {
	name = "Report bomb throwers",
	author = "VJScope",
	description = "Prints to all if a player throws the bomb",
	url = ""
};

public OnPluginStart()
{
	h_Enabled = CreateConVar("sm_bombdrop_enabled",  "1", "Plugin enabled/disabled. 1 = enabled.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
	h_DoDamage = CreateConVar("sm_bombdrop_damage",  "99", "How much damage does bomb drop take.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
	AutoExecConfig(true, "report_bomb_dropper.cfg");
	
	HookEvent("bomb_dropped", bomb_dropped);
}

public Action:round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
	g_dontSlap = true;
	new IsEnabled = GetConVarInt(h_Enabled);
	if (IsEnabled == 1)
	{
		CreateTimer(15.0, Timer_SlapBombDrop, _, TIMER_FLAG_NO_MAPCHANGE);
	}
}

public Action:Timer_SlapBombDrop(Handle:timer, any:serial)
{
	g_dontSlap = true;
}

public Action:bomb_dropped(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	new IsEnabled = GetConVarInt(h_Enabled);
	
	if (IsClientInGame(client) && IsEnabled == 1)
	{
		CreateTimer(0.1, Timer_AdvBombDrop, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE);
	}
}

public Action:Timer_AdvBombDrop(Handle:timer, any:serial)
{
	new client = GetClientFromSerial(serial);
	new IsEnabled = GetConVarInt(h_Enabled);
	new damage = GetConVarInt(h_DoDamage);
	
	if (client == 0 && IsEnabled == 1)
	{
		return Plugin_Handled;
	}
	
	if (IsPlayerAlive(client))
	{
		PrintToChatAll(" \x04[SM] \x01Player \x03%N \x01Dropped the bomb!", client);
		
		if(!g_dontSlap)
		{
			SlapPlayer(client, damage);
		}
	}
	
	return Plugin_Handled;
}
__________________
Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony.
VJScope is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 04-30-2014 , 10:03   Re: Problem with identifying dead player
Reply With Quote #8

g_dontSlap should be set to false in your round start code... you set it to true on round start, then set it to true when the 15 second timer ends, but check if it's false before you slap them
__________________
View my Plugins | Donate
TnTSCS is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 04-30-2014 , 15:46   Re: Problem with identifying dead player
Reply With Quote #9

Quote:
Originally Posted by TnTSCS View Post
g_dontSlap should be set to false in your round start code... you set it to true on round start, then set it to true when the 15 second timer ends, but check if it's false before you slap them
i think he was referring to the var self explanatory. At round stary "g_PleaseDontSlap == yes" instead
of "g_PleaseSlapMe".

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

new Handle:h_Enabled INVALID_HANDLE;
new 
Handle:h_DoDamage INVALID_HANDLE;
new 
bool:g_dontSlap;

public 
Plugin:myinfo = {
    
name "Report bomb throwers",
    
author "VJScope",
    
description "Prints to all if a player throws the bomb",
    
url ""
};

public 
OnPluginStart()
{
    
h_Enabled CreateConVar("sm_bombdrop_enabled",  "1""Plugin enabled/disabled. 1 = enabled."FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
h_DoDamage CreateConVar("sm_bombdrop_damage",  "99""How much damage does bomb drop take."FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
AutoExecConfig(true"report_bomb_dropper");
    
    
HookEvent("bomb_dropped"bomb_dropped);
}

public 
Action:round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
    if ( 
GetConVarBool(h_Enabled) == false ) return; // stop wasting time, this also help you understand better on how it work for now.
    
    
g_dontSlap true;
    
CreateTimer(15.0Timer_SlapBombDrop_TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action:Timer_SlapBombDrop(Handle:timer)
{
    
g_dontSlap false;
}

public 
bomb_dropped(Handle:event, const String:name[], bool:dontBroadcast)
{
    if ( 
GetConVarBool(h_Enabled) == false || g_dontSlap == true ) return; // stop wasting time
    
    
new client GetClientOfUserId(GetEventInt(event"userid"));
    if ( 
client && IsClientInGame(client))
    {
        
CreateTimer(0.1Timer_AdvBombDropGetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE);
    }
}

public 
Action:Timer_AdvBombDrop(Handle:timerany:serial)
{
    
// you need no additional filter here since the timer will not fire if the 15 seconds has not elapsed yet.
    
new client GetClientFromSerial(serial);
    if ( 
client && IsClientInGameclient ) && IsPlayerAlive(client))    // check if this dude qualified to get the lovely kiss.
    
{
        
PrintToChatAll(" \x04[SM] \x01Player \x03%N \x01Dropped the bomb!"client)
        
SlapPlayer(clientGetConVarInt(h_DoDamage));
    }

__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 04-30-2014 at 15:51.
GsiX is offline
Nerus
Senior Member
Join Date: Aug 2010
Location: Poland
Old 05-07-2015 , 13:52   Re: Problem with identifying dead player
Reply With Quote #10

Hi guys i have same problem like VJScope, is any other way to catch player dead without timer ?
First point is drop items and next is dead in source ?
Natural will be die and drop, of course this is my opinion.

ah, on dead is remove from world ?!

Regards,
Nerus.

Last edited by Nerus; 05-07-2015 at 13:54.
Nerus 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 11:44.


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