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

[L4D1] Scope for M16 Rifle


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sunyata
Senior Member
Join Date: Nov 2017
Location: Wherever I am
Old 02-23-2023 , 11:27   [L4D1] Scope for M16 Rifle
Reply With Quote #1

Greetings modding community,

I've been searching the forums for a way to customize the M16 rifle to have a virtual scope, but I can't find anything. So, I'm wondering if it's possible to use some code for the Hunting rifle to achieve the zoom-in function with its scope?

While there is an upgrade perk plugin by Marcus101RR [link here] that can attach a scope to all the weapons, I'm specifically interested in attaching one to the M16 alone.


Here's a snippet of code from the perks/upgrades plugin showing the indices for the scopes for all weapons, not that I think it's going to necessarily help:
Code:
UpgradeIndex[24] = 16777216;
UpgradeTitle[24] = "\x03Sniper Scope \x01(\x04Sniper Zoom Attachment\x01)";
UpgradeShort[24] = "\x03Sniper Scope\x01";
UpgradeEnabled[24] = CreateConVar("survivor_upgrade_scope_enable", "1", "Enable/Disable Sniper Scope", CVAR_FLAGS, true, 0.0, true, 1.0);
PerkTitle[24] = "Sniper Scope";

UpgradeIndex[25] = 33554432;
UpgradeTitle[25] = "\x03Sniper Scope Accuracy \x01(\x04Increased Zoom Accuracy\x01)";
UpgradeShort[25] = "\x03Sniper Scope Accuracy\x01";
UpgradeEnabled[25] = CreateConVar("survivor_upgrade_scope_accuracy_enable", "1", "Enable/Disable Sniper Scope Accuracy", CVAR_FLAGS, true, 0.0, true, 1.0);
PerkTitle[25] = "Sniper Scope Accuracy";
My question is, can Sourcemod be used to achieve this kind of customization? Does anyone know if this is even feasible?

Cheers,

Sunyata

Last edited by Sunyata; 02-27-2023 at 23:24. Reason: display code
Sunyata is offline
Maur0
Senior Member
Join Date: Aug 2020
Old 02-24-2023 , 15:34   Re: [L4D1] Scope for M16 Rifle
Reply With Quote #2

I hope this helps you:
https://forums.alliedmods.net/showthread.php?p=2796323

// weapon list of fake scope feature, separate by comma, no spaces
scope_level_fake_list "weapon_rifle,weapon_rifle_m60,weapon_rifle_a k47,weapon_smg,weapon_smg_silenced,weapon_smg _mp5"
Maur0 is offline
Sunyata
Senior Member
Join Date: Nov 2017
Location: Wherever I am
Old 02-25-2023 , 06:09   Re: [L4D1] Scope for M16 Rifle
Reply With Quote #3

Hi Maur0,

That plugin looks interesting, and it may be what I'm looking for. It's also a recently made plugin too. So that's quite good timing too. I shall test this out later when I have the time. Thanks for sharing that link, else I wouldn't have found it otherwise.

Cheers for that.
Sunyata is offline
Sunyata
Senior Member
Join Date: Nov 2017
Location: Wherever I am
Old 03-04-2023 , 08:42   Re: [L4D1] Scope for M16 Rifle
Reply With Quote #4

Further to my previous posts above, I am curious to know if it's possible to use the upgrade perks script to apply the sniper scope animation specifically to the M16 rifle by using the scope upgrade index numbers "16777216" and/or "33554432" without having to apply it to all weapons. I would appreciate some input from a more experienced coder to know if this is feasible, coz Im trying to brainstorm some ideas here as best as I can.

One approach could be to perhaps create a function that checks the weapon class name and apply the scope upgrade index number based on one weapon type alone, by using a function just to filter out the scope for the specified weapon. For example, the following code block checks if the weapon is an M16 and applies for the scope upgrade number:

Spoiler


Also, the OnPluginStartUp function to hook the item_pickup event:
Spoiler

The global constant string array containing the names of the weapon classes needed for l4d1:
Spoiler


No doubt, some code blocks from the upgrade perk script will also be needed along with any necessary includes/signatures files.
Spoiler


Then finally the call to the 'Event_Weapon_Pickup’ function when a player picks up the weapon just to activate the scope animation for the M16:
Spoiler


Could these code blocks (together with some of the other necessary code from the upgrade perks scripts) perhaps be enough to filter out the scope animation just to work with the M16/SMG weapons?

Anyway, I'm just trying to brainstorm some ideas here, with the hope that some more experienced coder can see a feasible way to apply a filter to the 'scope' animation to work just with the M16/SMG weapons alone.

And if you got this far, thanks for reading.

Sunyata,

Last edited by Sunyata; 03-11-2023 at 12:12. Reason: Hiding this old code, as it's not really needed here anymore, as Ive got better solution below
Sunyata is offline
Sunyata
Senior Member
Join Date: Nov 2017
Location: Wherever I am
Old 03-11-2023 , 12:07   Re: [L4D1] Scope for M16 Rifle
Reply With Quote #5

.
After dedicating significant effort to my previous post, I ultimately discovered a suitable solution for implementing the scoped zoom function with the M16 rifle - and now also the SMG. I accomplished this by utilizing the upgrade perk scope index [33554432], which is applied universally to all weapons, and then adapting it to my preferred weapons. To disable the zoom function, I ostensibly implemented a kind of "NOOP" method by incorporating the following code into my own forked 'upgrade perks' plugin using "OnPlayerRunCmd":

Code:
public Action OnPlayerRunCmd(int client, int& buttons, int& impuls, float vel[3], float angles[3], int& weapon)

{
    if((buttons & IN_ZOOM))
	{		
		int h_mSMG = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
		if(!IsValidEntity(h_mSMG) || IsFakeClient(client)) return Plugin_Handled;
		char classname[256];
		GetEntityClassname(h_mSMG, classname, sizeof(classname));
		if (StrContains(classname, "weapon_autoshotgun", false) != -1)
		{
			buttons &= ~IN_ZOOM; //Sunyata note - this is kind of a 'NOOP', but not in the strictest sense of the term.
			//PrintToChatAll("DeBUG - testing noop function works for zoom key on auto-shotgun");
		}
		else if (StrContains(classname, "weapon_pistol", false) != -1) 
		{
			buttons &= ~IN_ZOOM; 
			//PrintToChatAll("DeBUG - testing noop function works for zoom key on pistol");
		}	
		else if (StrContains(classname, "weapon_pumpshotgun", false) != -1) 
		{
			buttons &= ~IN_ZOOM; 
			//PrintToChatAll("DeBUG - testing noop function works for zoom key on pump-shotgun");
		}	
	}
}
If anyone wishes to implement this 'dirty' code into one of their own plugins, they are welcome to do so.

And finally, I would like to give a big thank you to Mr Sunyata, for solving this issue all by himself.

Sunyata
Sunyata is offline
NoroHime
Veteran Member
Join Date: Aug 2016
Location: bed
Old 04-11-2023 , 17:37   Re: [L4D1] Scope for M16 Rifle
Reply With Quote #6

Quote:
Originally Posted by Sunyata View Post
Further to my previous posts above, I am curious to know if it's possible to use the upgrade perks script to apply the sniper scope animation specifically to the M16 rifle by using the scope upgrade index numbers "16777216" and/or "33554432" without having to apply it to all weapons. I would appreciate some input from a more experienced coder to know if this is feasible, coz Im trying to brainstorm some ideas here as best as I can.

One approach could be to perhaps create a function that checks the weapon class name and apply the scope upgrade index number based on one weapon type alone, by using a function just to filter out the scope for the specified weapon. For example, the following code block checks if the weapon is an M16 and applies for the scope upgrade number:

Spoiler


Also, the OnPluginStartUp function to hook the item_pickup event:
Spoiler

The global constant string array containing the names of the weapon classes needed for l4d1:
Spoiler


No doubt, some code blocks from the upgrade perk script will also be needed along with any necessary includes/signatures files.
Spoiler


Then finally the call to the 'Event_Weapon_Pickup’ function when a player picks up the weapon just to activate the scope animation for the M16:
Spoiler


Could these code blocks (together with some of the other necessary code from the upgrade perks scripts) perhaps be enough to filter out the scope animation just to work with the M16/SMG weapons?

Anyway, I'm just trying to brainstorm some ideas here, with the hope that some more experienced coder can see a feasible way to apply a filter to the 'scope' animation to work just with the M16/SMG weapons alone.

And if you got this far, thanks for reading.

Sunyata,
sir, unfortunately i searched it, m_iItemDefinitionIndex netprop not exists on l4d and l4d2
__________________
NoroHime 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 12:38.


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