Raised This Month: $ Target: $400
 0% 

[CSGO] Weapon Jam


Post New Thread Reply   
 
Thread Tools Display Modes
DorCoMaNdO
Senior Member
Join Date: Feb 2012
Old 05-16-2014 , 03:02   Re: [CSGO] Weapon Jam
Reply With Quote #11

Quote:
Originally Posted by VJScope View Post
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.
Colors do work without an extra space.

Code:
for(new i = 1; i < MaxClients; i++)
{
	if(IsClientInGame(i) && GetClientTeam(i) == GetClientTeam(client))
	{
		PrintToChat(i, "\x04[SM] \x05%N \x01: My weapon is jammed!", client);
	}
}
That's how you print to team (0 = no team, 1 = spec, 2 = t, 3 = ct), the code compares the team of the client who has his weapon jammed to all of the clients on the server, and prints a message to every single one who has the same team (including self, to disabled that add "&& client != i" to the rules). If you want me to explain this code (probably how "for" works), let me know.
BTW if you want a default action (if what you're checking in the switch isn't anything of the stuff that you defined) use "default:".

There's the code after the improvements I mentioned and a little more :
Code:
#include <sourcemod>
#include <sdktools>

new Handle:gH_Enabled;
new Handle:gH_PrintWho;

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%
	gH_Enabled = CreateConVar("sm_weaponjam_enabled", "1", "Enable/Disable the plugin. Enable = 1.", _, true, 0.0, true, 1.0);
	gH_PrintWho = CreateConVar("sm_weaponjam_chat", "1", "Who can see when your weapon gets jammed. 0 = nobody, 1 = you (chat), 2 = team, 3 = you (center)", _, true, 0.0, true, 3.0);
	CreateConVar("sm_weaponjam_propability_glock", "10", "How often does the weapon glock get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_hkp2000", "10", "How often does the weapon hkp2000 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_elite", "10", "How often does the weapon elite get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_p250", "10", "How often does the weapon p250 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_fiveseven", "10", "How often does the weapon fiveseven get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_tec9", "10", "How often does the weapon tec9 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_deagle", "10", "How often does the weapon deagle get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_galilar", "10", "How often does the weapon galilar get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_famas", "10", "How often does the weapon famas get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_ak47", "10", "How often does the weapon ak47 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_m4a1", "10", "How often does the weapon m4a1 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_ssg08", "10", "How often does the weapon ssg08 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_aug", "10", "How often does the weapon aug get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_sg550", "10", "How often does the weapon sg550 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_g3sg1", "10", "How often does the weapon g3sg1 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_scar20", "10", "How often does the weapon scar20 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_awp", "10", "How often does the weapon awp get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_mac10", "10", "How often does the weapon mac10 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_ump45", "10", "How often does the weapon ump45 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_p90", "10", "How often does the weapon p90 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_bizon", "10", "How often does the weapon bizon get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_mp7", "10", "How often does the weapon mp7 get jammed.", _, true, 1.0, true, 1000.0);
	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(gH_Enabled))
	{
		return Plugin_Continue;
	}
	
	new String:sWeapon[30];
	GetClientWeapon(client, sWeapon, sizeof(sWeapon));
	ReplaceString(sWeapon, sizeof(sWeapon), "weapon_", "sm_weaponjam_propability_");
	new client = GetClientOfUserId(GetEventInt(event, "userid")), gun = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon"), iPropability = GetConVarInt(FindConVar(sWeapon));
	new randomnum = GetRandomInt(0, 9999);
	
	x += 499;
	if(randomnum > 499 && randomnum <= x)
	{
		SetEntProp(gun, Prop_Send, "m_iClip1", 0, 1);
		
		switch(GetConVarInt(gH_PrintWho))
		{
			case 1:
			{
				PrintToChat(client, "\x04[SM] \x01Weapon jammed, reload!");
			}
			case 2:
			{
				for(new i = 1; i < MaxClients; i++)
				{
					if(IsClientInGame(i) && GetClientTeam(i) == GetClientTeam(client))
					{
						PrintToChat(i, "\x04[SM] \x05%N \x01: My weapon got jammed! I need to reload!", client);
					}
				}
			}
			case 3:
			{
				PrintCenterText(client, "[SM] Weapon jammed, reload!");
			}
		}
	}
	return Plugin_Continue;
}
As you can see I added prefixes to the variables (but client, just used to it, and i, as it already signatures int), it helps you and others remember what the variable (type) is, "g" for global, "H" for Handle, and so on for other types. I also removed all the handles you defined for the convars, instead I made the plugin take the used weapon's name and replace "weapon_" with "sm_weaponjam_probability_", which ends up as the convar for the weapon.

Last edited by DorCoMaNdO; 05-16-2014 at 03:28.
DorCoMaNdO is offline
VJScope
Senior Member
Join Date: Jul 2012
Location: Finland
Old 05-19-2014 , 15:38   Re: [CSGO] Weapon Jam
Reply With Quote #12

row 56: undefined symbol "client"
solution?: new client = GetClientOfUserId(GetEventInt(event, "userid"));
row 61: undefined symbol x, expression has no effect
row 62: undefined symbol x
row 58: symbol is assigned a value that is never used: "iPropability"

And x needs to be added to iPropability (if I understood your suggestion correctly)?
__________________
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-21-2014 , 00:16   Re: [CSGO] Weapon Jam
Reply With Quote #13

Quote:
Originally Posted by VJScope View Post
row 56: undefined symbol "client"
solution?: new client = GetClientOfUserId(GetEventInt(event, "userid"));
row 61: undefined symbol x, expression has no effect
row 62: undefined symbol x
row 58: symbol is assigned a value that is never used: "iPropability"

And x needs to be added to iPropability (if I understood your suggestion correctly)?
iProbability is x, its my mistake, replace x by iPropability.
also "GetClientWeapon(client, sWeapon, sizeof(sWeapon));" should be under the definition of "client", another mistake of mine. I didn't test the code, and I wasn't editing it in the editor, I was editing it here, so couldn't really see if i did something wrong lol
DorCoMaNdO is offline
VJScope
Senior Member
Join Date: Jul 2012
Location: Finland
Old 05-26-2014 , 22:03   Re: [CSGO] Weapon Jam
Reply With Quote #14

I tried the new version... didn't seem to work (no errors while compiling).

Here's the modifications:
Code:
#include <sourcemod>
#include <sdktools>

new Handle:gH_Enabled;
new Handle:gH_PrintWho;

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%
	gH_Enabled = CreateConVar("sm_weaponjam_enabled", "1", "Enable/Disable the plugin. Enable = 1.", _, true, 0.0, true, 1.0);
	gH_PrintWho = CreateConVar("sm_weaponjam_chat", "1", "Who can see when your weapon gets jammed. 0 = nobody, 1 = you (chat), 2 = team, 3 = you (center)", _, true, 0.0, true, 3.0);
	CreateConVar("sm_weaponjam_propability_glock", "10", "How often does the weapon glock get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_hkp2000", "10", "How often does the weapon hkp2000 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_elite", "10", "How often does the weapon elite get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_p250", "10", "How often does the weapon p250 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_fiveseven", "10", "How often does the weapon fiveseven get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_tec9", "10", "How often does the weapon tec9 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_deagle", "10", "How often does the weapon deagle get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_galilar", "10", "How often does the weapon galilar get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_famas", "10", "How often does the weapon famas get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_ak47", "10", "How often does the weapon ak47 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_m4a1", "10", "How often does the weapon m4a1 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_ssg08", "10", "How often does the weapon ssg08 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_aug", "10", "How often does the weapon aug get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_sg550", "10", "How often does the weapon sg550 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_g3sg1", "10", "How often does the weapon g3sg1 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_scar20", "10", "How often does the weapon scar20 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_awp", "10", "How often does the weapon awp get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_mac10", "10", "How often does the weapon mac10 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_ump45", "10", "How often does the weapon ump45 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_p90", "10", "How often does the weapon p90 get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_bizon", "10", "How often does the weapon bizon get jammed.", _, true, 1.0, true, 1000.0);
	CreateConVar("sm_weaponjam_propability_mp7", "10", "How often does the weapon mp7 get jammed.", _, true, 1.0, true, 1000.0);
	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(gH_Enabled))
	{
		return Plugin_Continue;
	}
	
	new String:sWeapon[30];
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	GetClientWeapon(client, sWeapon, sizeof(sWeapon));
	ReplaceString(sWeapon, sizeof(sWeapon), "weapon_", "sm_weaponjam_propability_");
	new gun = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon"), iPropability = GetConVarInt(FindConVar(sWeapon));
	new randomnum = GetRandomInt(0, 9999);
	
	iPropability += 499;
	if(randomnum > 499 && randomnum <= iPropability)
	{
		SetEntProp(gun, Prop_Send, "m_iClip1", 0, 1);
		
		switch(GetConVarInt(gH_PrintWho))
		{
			case 1:
			{
				PrintToChat(client, "\x04[SM] \x01Weapon jammed, reload!");
			}
			case 2:
			{
				for(new i = 1; i < MaxClients; i++)
				{
					if(IsClientInGame(i) && GetClientTeam(i) == GetClientTeam(client))
					{
						PrintToChat(i, "\x04[SM] \x05%N \x01: My weapon got jammed! I need to reload!", client);
					}
				}
			}
			case 3:
			{
				PrintCenterText(client, "[SM] Weapon jammed, reload!");
			}
		}
	}
	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; 05-26-2014 at 22:04.
VJScope is offline
DorCoMaNdO
Senior Member
Join Date: Feb 2012
Old 05-28-2014 , 11:42   Re: [CSGO] Weapon Jam
Reply With Quote #15

Did it print errors to the server's console?
DorCoMaNdO is offline
VJScope
Senior Member
Join Date: Jul 2012
Location: Finland
Old 05-29-2014 , 02:59   Re: [CSGO] Weapon Jam
Reply With Quote #16

Couldn't see any errors in errorlogs. That's all I can do...
__________________
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
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 04:00.


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