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

[CSGO] Weapon Jam


Post New Thread Reply   
 
Thread Tools Display Modes
Author
VJScope
Senior Member
Join Date: Jul 2012
Location: Finland
Plugin ID:
4189
Plugin Version:
1.0
Plugin Category:
Fun Stuff
Plugin Game:
Counter-Strike: GO
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Your weapon may get jammed during a shootout and you need to reload.
    Old 05-07-2014 , 20:36   [CSGO] Weapon Jam
    Reply With Quote #1

    Weapon Jam



    Introduction:
    While shooting, your weapon might get jammed and you need to reload. This way you can balance guns or making shootouts more random. You can modify the probability for each weapon (by default they are all 10). Shotguns are not included because I thought that it would be a silly idea.

    Probabilities:
    1 = 0.01% (= an average of one in a ten thousand bullet causes weapon to jam)
    2 = 0.02%
    3 = 0.03%
    ...
    10 = 0.1% (= an average of one in a thousand bullet causes weapon to jam)
    ...
    100 = 1%
    ...
    1000 = 10%

    Installation:
    - Upload .smx to addons/sourcemod/plugins folder.
    - Upload .sp to addons/sourcemod/scripting folder.
    - Configs file will be created automatically when plugin is used for the first time.
    - If you want to have a version with colored chat, download the .zip > Unzip > Upload. Folders should be right.

    Credits:
    DorCoMaNdO - Thank you for helping me with the code.

    Changelog:
    1.10 - Auto-create configs file, new cvar which let's you to decide about plugin messages, improvements to code, increased the range of probability.
    Attached Files
    File Type: zip weapon_jam_colored_chat.zip (9.1 KB, 488 views)
    File Type: smx weapon_jam.smx (5.8 KB, 541 views)
    File Type: sp Get Plugin or Get Source (weapon_jam.sp - 1370 views - 7.7 KB)
    __________________
    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; 05-15-2014 at 10:14. Reason: more info
    VJScope is offline
    zipcore
    Veteran Member
    Join Date: Mar 2010
    Location: m_flZipcore
    Old 05-08-2014 , 08:35   Re: [CSGO] Weapon Jam
    Reply With Quote #2

    sm_weaponjam_propability_awp 900
    __________________
    zipcore is offline
    Chesterfield
    Senior Member
    Join Date: Apr 2013
    Old 05-08-2014 , 08:48   Re: [CSGO] Weapon Jam
    Reply With Quote #3

    Can you upload a preview video? thanks in advance.
    Chesterfield is offline
    VJScope
    Senior Member
    Join Date: Jul 2012
    Location: Finland
    Old 05-08-2014 , 15:04   Re: [CSGO] Weapon Jam
    Reply With Quote #4

    Quote:
    Originally Posted by Chesterfield View Post
    Can you upload a preview video? thanks in advance.
    I haven't really had any good recording software. But I'll give it a try.
    __________________
    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
    boombee
    SourceMod Donor
    Join Date: Nov 2013
    Old 05-08-2014 , 15:11   Re: [CSGO] Weapon Jam
    Reply With Quote #5

    Quote:
    Originally Posted by Chesterfield View Post
    Can you upload a preview video? thanks in advance.
    Quote:
    Originally Posted by VJScope View Post
    I haven't really had any good recording software. But I'll give it a try.
    Please!
    boombee is offline
    DorCoMaNdO
    Senior Member
    Join Date: Feb 2012
    Old 05-08-2014 , 19:07   Re: [CSGO] Weapon Jam
    Reply With Quote #6

    Instead of defining the "gun" variable for every weapon, you can use
    Code:
    new gun = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
    above everything, same applies for the other variables, also you can place the comparison of the jam variables at the top and change them for each weapon as you need, then call the jam at the bottom.
    Also there's no need of the ammo variables, and no need for adding the randomnum variable to the messages, you seemed to describe the convars as integers, but use them as floats in the code, use GetConVarInt instead.
    Another thing is that you used both spaces and tabs at the beginning of lines, pick one and use it, I recommend tabs. Switching from spaces to tabs and vice versa will throw a warning when compiling.
    You should have something like that at the end :
    Code:
    public Action:Event_WeaponFired(Handle:event, const String:name[], bool:dontBroadcast)
    {
    	if (!GetConVarBool(Enabled))
    	{
    		return;
    	}
    	
    	new client = GetClientOfUserId(GetEventInt(event, "userid"));
    	new String:sWeaponName[64];
    	GetClientWeapon(client, sWeaponName, sizeof(sWeaponName));
    	new gun = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
    	new Float:x = 1.0;
    	new randomnum = GetRandomInt(0, 999);
    	if(StrEqual(sWeaponName, "weapon_glock"))
    	{
    		x = GetConVarFloat(Probability_glock);
    	}else if(StrEqual(sWeaponName, "weapon_hkp2000"))
    	{
    		x = GetConVarInt(Probability_hkp2000);
    	}
    	// Other weapons here
    	
    	x += 499;
    	if(randomnum > 499 && randomnum <= x)
    	{
    		SetEntProp(gun, Prop_Send, "m_iClip1", 0, 1);
    		PrintToChat(client, "\x04[SM] \x01Weapon jammed!");
    	}
    }
    Haven't attempted to compile this, but it should work.
    DorCoMaNdO is offline
    VJScope
    Senior Member
    Join Date: Jul 2012
    Location: Finland
    Old 05-14-2014 , 11:08   Re: [CSGO] Weapon Jam
    Reply With Quote #7

    Quote:
    Originally Posted by DorCoMaNdO View Post
    Instead of defining the "gun" variable for every weapon, you can use
    Code:
    new gun = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
    above everything, same applies for the other variables, also you can place the comparison of the jam variables at the top and change them for each weapon as you need, then call the jam at the bottom.
    Also there's no need of the ammo variables, and no need for adding the randomnum variable to the messages, you seemed to describe the convars as integers, but use them as floats in the code, use GetConVarInt instead.
    Another thing is that you used both spaces and tabs at the beginning of lines, pick one and use it, I recommend tabs. Switching from spaces to tabs and vice versa will throw a warning when compiling.
    You should have something like that at the end :
    Code:
    public Action:Event_WeaponFired(Handle:event, const String:name[], bool:dontBroadcast)
    {
    	if (!GetConVarBool(Enabled))
    	{
    		return;
    	}
    	
    	new client = GetClientOfUserId(GetEventInt(event, "userid"));
    	new String:sWeaponName[64];
    	GetClientWeapon(client, sWeaponName, sizeof(sWeaponName));
    	new gun = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
    	new Float:x = 1.0;
    	new randomnum = GetRandomInt(0, 999);
    	if(StrEqual(sWeaponName, "weapon_glock"))
    	{
    		x = GetConVarFloat(Probability_glock);
    	}else if(StrEqual(sWeaponName, "weapon_hkp2000"))
    	{
    		x = GetConVarInt(Probability_hkp2000);
    	}
    	// Other weapons here
    	
    	x += 499;
    	if(randomnum > 499 && randomnum <= x)
    	{
    		SetEntProp(gun, Prop_Send, "m_iClip1", 0, 1);
    		PrintToChat(client, "\x04[SM] \x01Weapon jammed!");
    	}
    }
    Haven't attempted to compile this, but it should work.

    Thanks for your advice! I'll try it. "x = GetConVarInt(Probability_hkp2000)" Don't you mean x = GetConVarFloat(Probability_hkp2000)?
    __________________
    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 05-14-2014 , 11:44   Re: [CSGO] Weapon Jam
    Reply With Quote #8

    Code:
    #include <sourcemod>
    #include <sdktools>
    
    new Handle:Enabled;
    new Handle:PrintWho;
    new Handle:Probability_glock;
    new Handle:Probability_hkp2000;
    new Handle:Probability_elite;
    new Handle:Probability_p250;
    new Handle:Probability_fiveseven;
    new Handle:Probability_tec9;
    new Handle:Probability_deagle;
    new Handle:Probability_galilar;
    new Handle:Probability_famas;
    new Handle:Probability_ak47;
    new Handle:Probability_m4a1;
    new Handle:Probability_ssg08;
    new Handle:Probability_aug;
    new Handle:Probability_sg550;
    new Handle:Probability_g3sg1;
    new Handle:Probability_scar20;
    new Handle:Probability_awp;
    new Handle:Probability_mac10;
    new Handle:Probability_ump45;
    new Handle:Probability_p90;
    new Handle:Probability_bizon;
    new Handle:Probability_mp7;
    new Handle:Probability_mp9;
    
    public Plugin:myinfo = {
    	name = "WeaponJam v1.10",
    	author = "VJScope",
    	description = "Player might get his weapon jammed while shooting and he has to reload.",
    	url = ""
    };
    
    public OnPluginStart()
    {
    	//Propability: 1 = 0.01%, 10 = 0.1%, 100 = 1%, 1000 = 10%
    	Enabled = CreateConVar("sm_weaponjam_enabled", "1", "Enable/Disable the plugin. Enable = 1.", _, true, 0.0, true, 1.0);
    	PrintWho = CreateConVar("sm_weaponjam_chat", "1", "Who can see when your weapon gets jammed. 0 = nobody, 1 = you (chat), 2 = all, 3 = you (center)", _, true, 0.0, true, 3.0);
    	Probability_glock = CreateConVar("sm_weaponjam_propability_glock", "10", "How often does the weapon glock get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_hkp2000 = CreateConVar("sm_weaponjam_propability_hkp2000", "10", "How often does the weapon hkp2000 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_elite = CreateConVar("sm_weaponjam_propability_elite", "10", "How often does the weapon elite get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_p250 = CreateConVar("sm_weaponjam_propability_p250", "10", "How often does the weapon p250 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_fiveseven = CreateConVar("sm_weaponjam_propability_fiveseven", "10", "How often does the weapon fiveseven get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_tec9 = CreateConVar("sm_weaponjam_propability_tec9", "10", "How often does the weapon tec9 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_deagle = CreateConVar("sm_weaponjam_propability_deagle", "10", "How often does the weapon deagle get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_galilar = CreateConVar("sm_weaponjam_propability_galilar", "10", "How often does the weapon galilar get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_famas = CreateConVar("sm_weaponjam_propability_famas", "10", "How often does the weapon famas get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_ak47 = CreateConVar("sm_weaponjam_propability_ak47", "10", "How often does the weapon ak47 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_m4a1 = CreateConVar("sm_weaponjam_propability_m4a1", "10", "How often does the weapon m4a1 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_ssg08 = CreateConVar("sm_weaponjam_propability_ssg08", "10", "How often does the weapon ssg08 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_aug = CreateConVar("sm_weaponjam_propability_aug", "10", "How often does the weapon aug get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_sg550 = CreateConVar("sm_weaponjam_propability_sg550", "10", "How often does the weapon sg550 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_g3sg1 = CreateConVar("sm_weaponjam_propability_g3sg1", "10", "How often does the weapon g3sg1 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_scar20 = CreateConVar("sm_weaponjam_propability_scar20", "10", "How often does the weapon scar20 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_awp = CreateConVar("sm_weaponjam_propability_awp", "10", "How often does the weapon awp get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_mac10 = CreateConVar("sm_weaponjam_propability_mac10", "10", "How often does the weapon mac10 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_ump45 = CreateConVar("sm_weaponjam_propability_ump45", "10", "How often does the weapon ump45 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_p90 = CreateConVar("sm_weaponjam_propability_p90", "10", "How often does the weapon p90 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_bizon = CreateConVar("sm_weaponjam_propability_bizon", "10", "How often does the weapon bizon get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_mp7 = CreateConVar("sm_weaponjam_propability_mp7", "10", "How often does the weapon mp7 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_mp9 = CreateConVar("sm_weaponjam_propability_mp9", "10", "How often does the weapon mp9 get jammed.", _, true, 1.0, true, 1000.0);
    	
    	AutoExecConfig(true, "weapon_jam3");
    	
    	HookEvent("weapon_fire", Event_WeaponFired, EventHookMode_Pre);
    }
    
    public Action:Event_WeaponFired(Handle:event, const String:name[], bool:dontBroadcast)
     {
    	if (!GetConVarBool(Enabled))
        {
            return;
        }
    	
    	new client = GetClientOfUserId(GetEventInt(event, "userid"));
    	new String:sWeaponName[64], String:playerName[32];
    	GetClientWeapon(client, sWeaponName, sizeof(sWeaponName));
    	GetClientName(client, playerName, sizeof(playerName));
    	new gun = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
    	new Float:x = 1.0;
    	new randomnum = GetRandomInt(0, 9999);
    	if(StrEqual(sWeaponName, "weapon_glock"))
    	{
    		x = GetConVarFloat(Probability_glock);
    	}else if(StrEqual(sWeaponName, "weapon_hkp2000"))
    	{
    		x = GetConVarFloat(Probability_hkp2000);
    	}else if(StrEqual(sWeaponName, "weapon_elite"))
    	{
    		x = GetConVarFloat(Probability_elite);
    	}else if(StrEqual(sWeaponName, "weapon_p250"))
    	{
    		x = GetConVarFloat(Probability_p250);
    	}else if(StrEqual(sWeaponName, "weapon_fiveseven"))
    	{
    		x = GetConVarFloat(Probability_fiveseven);
    	}else if(StrEqual(sWeaponName, "weapon_tec9"))
    	{
    		x = GetConVarFloat(Probability_tec9);
    	}else if(StrEqual(sWeaponName, "weapon_deagle"))
    	{
    		x = GetConVarFloat(Probability_deagle);
    	}else if(StrEqual(sWeaponName, "weapon_galilar"))
    	{
    		x = GetConVarFloat(Probability_galilar);
    	}else if(StrEqual(sWeaponName, "weapon_famas"))
    	{
    		x = GetConVarFloat(Probability_famas);
    	}else if(StrEqual(sWeaponName, "weapon_ak47"))
    	{
    		x = GetConVarFloat(Probability_ak47);
    	}else if(StrEqual(sWeaponName, "weapon_m4a1"))
    	{
    		x = GetConVarFloat(Probability_m4a1);
    	}else if(StrEqual(sWeaponName, "weapon_ssg08"))
    	{
    		x = GetConVarFloat(Probability_ssg08);
    	}else if(StrEqual(sWeaponName, "weapon_aug"))
    	{
    		x = GetConVarFloat(Probability_aug);
    	}else if(StrEqual(sWeaponName, "weapon_sg550"))
    	{
    		x = GetConVarFloat(Probability_sg550);
    	}else if(StrEqual(sWeaponName, "weapon_g3sg1"))
    	{
    		x = GetConVarFloat(Probability_g3sg1);
    	}else if(StrEqual(sWeaponName, "weapon_scar20"))
    	{
    		x = GetConVarFloat(Probability_scar20);
    	}else if(StrEqual(sWeaponName, "weapon_awp"))
    	{
    		x = GetConVarFloat(Probability_awp);
    	}else if(StrEqual(sWeaponName, "weapon_mac10"))
    	{
    		x = GetConVarFloat(Probability_mac10);
    	}else if(StrEqual(sWeaponName, "weapon_ump45"))
    	{
    		x = GetConVarFloat(Probability_ump45);
    	}else if(StrEqual(sWeaponName, "weapon_p90"))
    	{
    		x = GetConVarFloat(Probability_p90);
    	}else if(StrEqual(sWeaponName, "weapon_bizon"))
    	{
    		x = GetConVarFloat(Probability_bizon);
    	}else if(StrEqual(sWeaponName, "weapon_mp7"))
    	{
    		x = GetConVarFloat(Probability_mp7);
    	}else if(StrEqual(sWeaponName, "weapon_mp9"))
    	{
    		x = GetConVarFloat(Probability_mp9);
    	}
    	
    	x += 499;
    	if(randomnum > 499 && randomnum <= x)
    	{
    		SetEntProp(gun, Prop_Send, "m_iClip1", 0, 1);
    		
    		new Float:chatNum = GetConVarFloat(PrintWho);
    		if(chatNum == 1.0)
    		{
    			PrintToChat(client, " \x04[SM] \x01Weapon jammed, reload!");
    		}else if(chatNum == 2.0)
    		{
    			PrintToChatAll(" \x04[SM]%s: \x01My weapon got jammed! I need to reload!", playerName);
    		}else if(chatNum == 3.0)
    		{
    			PrintCenterText(client, "[SM] Weapon jammed, reload!");
    		}
    	}
     }
    Has anyone any idea why console gives me:
    "sm_weaponjam_chat" = "1" min. 0.000000 max. 1.000000 - Who can see when your weapon gets jammed. 0 = nobody, 1 = you (chat), 2 = all, 3

    I compiled it at first when that cvar had max value 1 but then I noticed that problem but it wont change in console no matter what I try...
    __________________
    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
    DorCoMaNdO
    Senior Member
    Join Date: Feb 2012
    Old 05-15-2014 , 02:31   Re: [CSGO] Weapon Jam
    Reply With Quote #9

    Quote:
    Originally Posted by VJScope View Post
    Thanks for your advice! I'll try it. "x = GetConVarInt(Probability_hkp2000)" Don't you mean x = GetConVarFloat(Probability_hkp2000)?
    Nope I meant Int, also change the definition of x as a float, define it as int.
    Quote:
    Originally Posted by VJScope View Post
    Code:
    #include <sourcemod>
    #include <sdktools>
    
    new Handle:Enabled;
    new Handle:PrintWho;
    new Handle:Probability_glock;
    new Handle:Probability_hkp2000;
    new Handle:Probability_elite;
    new Handle:Probability_p250;
    new Handle:Probability_fiveseven;
    new Handle:Probability_tec9;
    new Handle:Probability_deagle;
    new Handle:Probability_galilar;
    new Handle:Probability_famas;
    new Handle:Probability_ak47;
    new Handle:Probability_m4a1;
    new Handle:Probability_ssg08;
    new Handle:Probability_aug;
    new Handle:Probability_sg550;
    new Handle:Probability_g3sg1;
    new Handle:Probability_scar20;
    new Handle:Probability_awp;
    new Handle:Probability_mac10;
    new Handle:Probability_ump45;
    new Handle:Probability_p90;
    new Handle:Probability_bizon;
    new Handle:Probability_mp7;
    new Handle:Probability_mp9;
    
    public Plugin:myinfo = {
    	name = "WeaponJam v1.10",
    	author = "VJScope",
    	description = "Player might get his weapon jammed while shooting and he has to reload.",
    	url = ""
    };
    
    public OnPluginStart()
    {
    	//Propability: 1 = 0.01%, 10 = 0.1%, 100 = 1%, 1000 = 10%
    	Enabled = CreateConVar("sm_weaponjam_enabled", "1", "Enable/Disable the plugin. Enable = 1.", _, true, 0.0, true, 1.0);
    	PrintWho = CreateConVar("sm_weaponjam_chat", "1", "Who can see when your weapon gets jammed. 0 = nobody, 1 = you (chat), 2 = all, 3 = you (center)", _, true, 0.0, true, 3.0);
    	Probability_glock = CreateConVar("sm_weaponjam_propability_glock", "10", "How often does the weapon glock get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_hkp2000 = CreateConVar("sm_weaponjam_propability_hkp2000", "10", "How often does the weapon hkp2000 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_elite = CreateConVar("sm_weaponjam_propability_elite", "10", "How often does the weapon elite get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_p250 = CreateConVar("sm_weaponjam_propability_p250", "10", "How often does the weapon p250 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_fiveseven = CreateConVar("sm_weaponjam_propability_fiveseven", "10", "How often does the weapon fiveseven get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_tec9 = CreateConVar("sm_weaponjam_propability_tec9", "10", "How often does the weapon tec9 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_deagle = CreateConVar("sm_weaponjam_propability_deagle", "10", "How often does the weapon deagle get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_galilar = CreateConVar("sm_weaponjam_propability_galilar", "10", "How often does the weapon galilar get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_famas = CreateConVar("sm_weaponjam_propability_famas", "10", "How often does the weapon famas get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_ak47 = CreateConVar("sm_weaponjam_propability_ak47", "10", "How often does the weapon ak47 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_m4a1 = CreateConVar("sm_weaponjam_propability_m4a1", "10", "How often does the weapon m4a1 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_ssg08 = CreateConVar("sm_weaponjam_propability_ssg08", "10", "How often does the weapon ssg08 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_aug = CreateConVar("sm_weaponjam_propability_aug", "10", "How often does the weapon aug get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_sg550 = CreateConVar("sm_weaponjam_propability_sg550", "10", "How often does the weapon sg550 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_g3sg1 = CreateConVar("sm_weaponjam_propability_g3sg1", "10", "How often does the weapon g3sg1 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_scar20 = CreateConVar("sm_weaponjam_propability_scar20", "10", "How often does the weapon scar20 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_awp = CreateConVar("sm_weaponjam_propability_awp", "10", "How often does the weapon awp get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_mac10 = CreateConVar("sm_weaponjam_propability_mac10", "10", "How often does the weapon mac10 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_ump45 = CreateConVar("sm_weaponjam_propability_ump45", "10", "How often does the weapon ump45 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_p90 = CreateConVar("sm_weaponjam_propability_p90", "10", "How often does the weapon p90 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_bizon = CreateConVar("sm_weaponjam_propability_bizon", "10", "How often does the weapon bizon get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_mp7 = CreateConVar("sm_weaponjam_propability_mp7", "10", "How often does the weapon mp7 get jammed.", _, true, 1.0, true, 1000.0);
    	Probability_mp9 = CreateConVar("sm_weaponjam_propability_mp9", "10", "How often does the weapon mp9 get jammed.", _, true, 1.0, true, 1000.0);
    	
    	AutoExecConfig(true, "weapon_jam3");
    	
    	HookEvent("weapon_fire", Event_WeaponFired, EventHookMode_Pre);
    }
    
    public Action:Event_WeaponFired(Handle:event, const String:name[], bool:dontBroadcast)
     {
    	if (!GetConVarBool(Enabled))
        {
            return;
        }
    	
    	new client = GetClientOfUserId(GetEventInt(event, "userid"));
    	new String:sWeaponName[64], String:playerName[32];
    	GetClientWeapon(client, sWeaponName, sizeof(sWeaponName));
    	GetClientName(client, playerName, sizeof(playerName));
    	new gun = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
    	new Float:x = 1.0;
    	new randomnum = GetRandomInt(0, 9999);
    	if(StrEqual(sWeaponName, "weapon_glock"))
    	{
    		x = GetConVarFloat(Probability_glock);
    	}else if(StrEqual(sWeaponName, "weapon_hkp2000"))
    	{
    		x = GetConVarFloat(Probability_hkp2000);
    	}else if(StrEqual(sWeaponName, "weapon_elite"))
    	{
    		x = GetConVarFloat(Probability_elite);
    	}else if(StrEqual(sWeaponName, "weapon_p250"))
    	{
    		x = GetConVarFloat(Probability_p250);
    	}else if(StrEqual(sWeaponName, "weapon_fiveseven"))
    	{
    		x = GetConVarFloat(Probability_fiveseven);
    	}else if(StrEqual(sWeaponName, "weapon_tec9"))
    	{
    		x = GetConVarFloat(Probability_tec9);
    	}else if(StrEqual(sWeaponName, "weapon_deagle"))
    	{
    		x = GetConVarFloat(Probability_deagle);
    	}else if(StrEqual(sWeaponName, "weapon_galilar"))
    	{
    		x = GetConVarFloat(Probability_galilar);
    	}else if(StrEqual(sWeaponName, "weapon_famas"))
    	{
    		x = GetConVarFloat(Probability_famas);
    	}else if(StrEqual(sWeaponName, "weapon_ak47"))
    	{
    		x = GetConVarFloat(Probability_ak47);
    	}else if(StrEqual(sWeaponName, "weapon_m4a1"))
    	{
    		x = GetConVarFloat(Probability_m4a1);
    	}else if(StrEqual(sWeaponName, "weapon_ssg08"))
    	{
    		x = GetConVarFloat(Probability_ssg08);
    	}else if(StrEqual(sWeaponName, "weapon_aug"))
    	{
    		x = GetConVarFloat(Probability_aug);
    	}else if(StrEqual(sWeaponName, "weapon_sg550"))
    	{
    		x = GetConVarFloat(Probability_sg550);
    	}else if(StrEqual(sWeaponName, "weapon_g3sg1"))
    	{
    		x = GetConVarFloat(Probability_g3sg1);
    	}else if(StrEqual(sWeaponName, "weapon_scar20"))
    	{
    		x = GetConVarFloat(Probability_scar20);
    	}else if(StrEqual(sWeaponName, "weapon_awp"))
    	{
    		x = GetConVarFloat(Probability_awp);
    	}else if(StrEqual(sWeaponName, "weapon_mac10"))
    	{
    		x = GetConVarFloat(Probability_mac10);
    	}else if(StrEqual(sWeaponName, "weapon_ump45"))
    	{
    		x = GetConVarFloat(Probability_ump45);
    	}else if(StrEqual(sWeaponName, "weapon_p90"))
    	{
    		x = GetConVarFloat(Probability_p90);
    	}else if(StrEqual(sWeaponName, "weapon_bizon"))
    	{
    		x = GetConVarFloat(Probability_bizon);
    	}else if(StrEqual(sWeaponName, "weapon_mp7"))
    	{
    		x = GetConVarFloat(Probability_mp7);
    	}else if(StrEqual(sWeaponName, "weapon_mp9"))
    	{
    		x = GetConVarFloat(Probability_mp9);
    	}
    	
    	x += 499;
    	if(randomnum > 499 && randomnum <= x)
    	{
    		SetEntProp(gun, Prop_Send, "m_iClip1", 0, 1);
    		
    		new Float:chatNum = GetConVarFloat(PrintWho);
    		if(chatNum == 1.0)
    		{
    			PrintToChat(client, " \x04[SM] \x01Weapon jammed, reload!");
    		}else if(chatNum == 2.0)
    		{
    			PrintToChatAll(" \x04[SM]%s: \x01My weapon got jammed! I need to reload!", playerName);
    		}else if(chatNum == 3.0)
    		{
    			PrintCenterText(client, "[SM] Weapon jammed, reload!");
    		}
    	}
     }
    Has anyone any idea why console gives me:
    "sm_weaponjam_chat" = "1" min. 0.000000 max. 1.000000 - Who can see when your weapon gets jammed. 0 = nobody, 1 = you (chat), 2 = all, 3

    I compiled it at first when that cvar had max value 1 but then I noticed that problem but it wont change in console no matter what I try...
    Again you could use GetConVarInt instead of float, you add an extra space at the beginning of the message the player(s) receive(s).
    You could also use %N instead of %s for the player's name, providing the client instead of a string, like so :
    Code:
    PrintToChat(client, "Your name is %N", client);
    Another thing you might want to do is use "switch" instead of "if", at least on the message part, like so :
    Code:
    switch(GetConVarInt(PrintWho))
    {
    	case 1:
    		PrintToChat(client, "\x04[SM] \x01Weapon jammed, reload!");
    	case 2:
    		PrintToChatAll("\x04[SM]%N: \x01My weapon got jammed! I need to reload!", client);
    	case 3:
    		PrintCenterText(client, "[SM] Weapon jammed, reload!");
    }
    You might also want to add (or replace "All" with) a "Team" option for the message convar.

    About your issue, if you look at the convar through the generated config, delete the config and let it regenerate. Configs aren't updated when you change something in the convar's definition.

    Last edited by DorCoMaNdO; 05-15-2014 at 02:42.
    DorCoMaNdO is offline
    VJScope
    Senior Member
    Join Date: Jul 2012
    Location: Finland
    Old 05-15-2014 , 09:23   Re: [CSGO] Weapon Jam
    Reply With Quote #10

    Thank you again! I'll make those changes and upload a new version.

    "Again you could use GetConVarInt instead of float, you add an extra space at the beginning of the message the player(s) receive(s).!"
    I have to add that extra space or colours won't work in chat. I can add second file without colors.

    "You might also want to add (or replace "All" with) a "Team" option for the message convar."
    I need to study more about how to print to team. Looks like simple PrintToChatTeam isn't automatically defined.
    __________________
    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; 05-15-2014 at 09:48.
    VJScope 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 03:20.


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