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

[CS:S] Critical Hit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Debesėlis
Senior Member
Join Date: Aug 2008
Location: Lithuania
Old 02-23-2010 , 09:18   [CS:S] Critical Hit
Reply With Quote #1

Possibe code this to CS:S ? Better if be CVars:
sm_critical_chance "15"
sm_critical_damage "1.5"

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

new Handle:crits INVALID_HANDLE;
new 
Handle:chance INVALID_HANDLE;

#define PLUGIN_VERSION "0.1"

public Plugin:myinfo 
{
    
name "SM Crits chance",
    
author "pRED*",
    
description "Change critical hit %",
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net/"
};

public 
OnPluginStart()
{
    
crits CreateConVar("sm_crits_enabled""1");
    
chance CreateConVar("sm_crits_chance""1.00");
    
    
CreateConVar("sm_crits_version"PLUGIN_VERSION"Crits Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
}


public 
Action:TF2_CalcIsAttackCritical(clientweaponString:weaponname[], &bool:result)
{
    if (!
GetConVarBool(crits))
    {
        return 
Plugin_Continue;    
    }
    
    if (
GetConVarFloat(chance) > GetRandomFloat(0.01.0))
    {
        
result true;
        return 
Plugin_Handled;    
    }
    
    
result false;
    
    return 
Plugin_Handled;

Debesėlis is offline
Paah
Junior Member
Join Date: Jan 2010
Old 02-23-2010 , 11:09   Re: [CS:S] Critical Hit
Reply With Quote #2

Code:
#include <sourcemod>

new Handle:crits = INVALID_HANDLE;
new Handle:chance = INVALID_HANDLE;

#define PLUGIN_VERSION "0.1"

public Plugin:myinfo = 
{
    name = "SM Crits chance",
    author = "pRED*",
    description = "Change critical hit %",
    version = PLUGIN_VERSION,
    url = "http://www.sourcemod.net/"
};

public OnPluginStart()
{
    crits = CreateConVar("sm_crits_enabled", "1");
    chance = CreateConVar("sm_crits_chance", "1.00");
    
    CreateConVar("sm_crits_version", PLUGIN_VERSION, "Crits Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    HookEvent("player_hurt", Event_Player_Hurt, EventHookMode_Pre)

}
Public Action:Event_Player_Hurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (CritCalc)
    {
        new damage
        damage = 1.5 * GetEventInt(event, "dmg_health")
        SetEventInt(event, "dmg_health", damage)
        return Plugin_Changed
    }
    return Plugin_Continue
}

stock CritCalc()
{
    if (!GetConVarBool(crits))
    {
        return Plugin_Continue;    
    }
    
    if (GetConVarFloat(chance) > GetRandomFloat(0.0, 1.0))
    {
        result = true;
        return Plugin_Handled;    
    }
    
    result = false;
    
    return Plugin_Handled;
}
I guess

Last edited by Paah; 02-23-2010 at 11:15.
Paah is offline
Thrawn2
Veteran Member
Join Date: Apr 2009
Old 02-23-2010 , 11:14   Re: [CS:S] Critical Hit
Reply With Quote #3

sourcemod != perl
PHP Code:
stock CritCalc {

does this really work?
Thrawn2 is offline
Paah
Junior Member
Join Date: Jan 2010
Old 02-23-2010 , 11:15   Re: [CS:S] Critical Hit
Reply With Quote #4

Ahem sorry I think it should be

Code:
stock CritCalc() {
}
Fixed that
As there was no variables to carry, I forgot those :F
Paah is offline
Debesėlis
Senior Member
Join Date: Aug 2008
Location: Lithuania
Old 02-23-2010 , 11:17   Re: [CS:S] Critical Hit
Reply With Quote #5

Ohh thanks man

EDIT: It doesn't compile

Last edited by Debesėlis; 02-23-2010 at 11:27.
Debesėlis is offline
Thrawn2
Veteran Member
Join Date: Apr 2009
Old 02-23-2010 , 11:33   Re: [CS:S] Critical Hit
Reply With Quote #6

try this
PHP Code:
#include <sourcemod>

new Handle:g_hCvarCritsEnabled INVALID_HANDLE;
new 
Handle:g_hCvarChance INVALID_HANDLE;
new 
Handle:g_hCvarDmgMultiplier INVALID_HANDLE;

new 
bool:g_bCrits;
new 
Float:g_fChance;
new 
Float:g_fDmgMultiplier;

#define PLUGIN_VERSION "0.1"

public Plugin:myinfo =
{
    
name "SM Crits chance",
    
author "pRED*",
    
description "Change critical hit %",
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net/"
};

public 
OnPluginStart()
{
    
g_hCvarCritsEnabled CreateConVar("sm_crits_enabled""1");
    
g_hCvarChance CreateConVar("sm_crits_chance""0.05");
    
g_hCvarDmgMultiplier CreateConVar("sm_crits_dmgmultiplier""1.5");

    
HookConVarChange(g_hCvarCritsEnabledCvar_Changed);
    
HookConVarChange(g_hCvarChanceCvar_Changed);
    
HookConVarChange(g_hCvarDmgMultiplierCvar_Changed);

    
CreateConVar("sm_crits_version"PLUGIN_VERSION"Crits Version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
HookEvent("player_hurt"Event_Player_HurtEventHookMode_Pre);
}

public 
Cvar_Changed(Handle:convar, const String:oldValue[], const String:newValue[])
{
    
OnConfigsExecuted();
}

public 
OnConfigsExecuted()
{
    
g_bCrits GetConVarBool(g_hCvarCritsEnabled);
    
g_fChance GetConVarFloat(g_hCvarChance);
    
g_fDmgMultiplier GetConVarFloat(g_hCvarDmgMultiplier);
}

public 
Action:Event_Player_Hurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (
g_bCrits && g_fChance >= GetRandomFloat())
    {
        new 
Float:damage g_fDmgMultiplier GetEventInt(event"dmg_health");
        
SetEventInt(event"dmg_health"RoundFloat(damage));
        return 
Plugin_Changed;
    }
    return 
Plugin_Continue;

there were some other errors too. and i did some optimizations. its not recommended to check a cvar everytime a player gets hurt ;)
buuut: i dont know if it is possible for the event_player_hurt event to change damage done. dont know, i never did much for css. maybe you need to use sdkhooks for that.

Last edited by Thrawn2; 02-23-2010 at 11:40.
Thrawn2 is offline
Debesėlis
Senior Member
Join Date: Aug 2008
Location: Lithuania
Old 02-23-2010 , 11:38   Re: [CS:S] Critical Hit
Reply With Quote #7

Fix it

PHP Code:
g_hCvarChance CreateConVar("sm_crits_chance""1.00"); 
g_hCvarDmgMultiplier CreateConVar("sm_crits_chance""1.5"); 
Debesėlis is offline
Paah
Junior Member
Join Date: Jan 2010
Old 02-23-2010 , 11:41   Re: [CS:S] Critical Hit
Reply With Quote #8

Quote:
Originally Posted by Debesėlis View Post
Fix it

PHP Code:
g_hCvarChance CreateConVar("sm_crits_chance""1.00"); 
g_hCvarDmgMultiplier CreateConVar("sm_crits_multiplier""1.5"); 
Paah is offline
Debesėlis
Senior Member
Join Date: Aug 2008
Location: Lithuania
Old 02-23-2010 , 14:23   Re: [CS:S] Critical Hit
Reply With Quote #9

doesn't work...
Debesėlis is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 02-23-2010 , 15:52   Re: [CS:S] Critical Hit
Reply With Quote #10

You need to use SDKHooks to change the damage done.
Afronanny 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 07:26.


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