Raised This Month: $32 Target: $400
 8% 

Need help making simple code change


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dabosman
Junior Member
Join Date: Mar 2004
Old 10-28-2019 , 18:41   Need help making simple code change
Reply With Quote #1

Hi all - I'm needing help with making what I believe would be a simple code change in an existing plugin (not written by me).

The plugin is a Random Weapons plugin - and it works very well. It was written by a coder from France - but he hasn't been active at all this year. Here is the thread to that plugin with source code:
https://forums.alliedmods.net/showthread.php?p=2671253

I'm not needing necessarily the full functionality of this script - but just needing it to give the SAME random weapon to ALL players for the entire round until everyone dies (casual or comp modes) - instead of giving each player a different random weapon like it does now.

I believe this will probably be a simple code change - to set a variable for whatever the new random weapon is - and just give all players that variable/weapon for that round until everyone dies ... then give them a new random weapon (all the same weapon again) once the new round starts. Seems simple enough - but I've tried various things with the code and can't seem to get it to work.

Any help would be greatly appreciated! Trying to learn some simple coding from this too!
Dabosman is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-29-2019 , 09:47   Re: Need help making simple code change
Reply With Quote #2

I didn't read the full code but looks like you just need to change this var

PHP Code:
    new String:weapons_all[][] =  { "weapon_ak47""weapon_aug""weapon_famas""weapon_galilar""weapon_sg556""weapon_m4a1"
        
"weapon_g3sg1""weapon_scar20""weapon_ssg08""weapon_awp"
        
"weapon_deagle""weapon_elite""weapon_fiveseven""weapon_glock""weapon_hkp2000""weapon_p250""weapon_tec9"
        
"weapon_bizon""weapon_mac10""weapon_mp7""weapon_mp9""weapon_p90""weapon_ump45"
        
"weapon_xm1014""weapon_sawedoff""weapon_nova""weapon_mag7"
        
"weapon_m249""weapon_negev" }; 
To the weapon you want.

E.g.

new String:weapons_all[][] = { "weapon_ak47" };
__________________
Marttt is offline
Dabosman
Junior Member
Join Date: Mar 2004
Old 10-29-2019 , 10:46   Re: Need help making simple code change
Reply With Quote #3

Hey Marttt - thanks for the reply ... but I'm wanting ALL of these weapons as possibilities ... and not just a single weapon. In other words, it chooses a random weapon at the beginning of the round (say P90) ... and ALL players (including bots - which works now) get a P90. So that everyone has level playing field .. and it's player versus player.

Then at start of next round, new random weapon is chosen (set as a variable .. say Shotgun at this point) ... and all players again get that new weapon.

It seems simple since he has the random and 'probability' equation that he has in there ... I unfortunately just don't know how to change this loop below to go from generating a DIFFERENT random weapon for each player (right now, one player gets shotty, next gets P90, next gets AK, etc) ... to where it's instead generating *ONE* new random weapon for everyone (everyone gets same weapon), setting a variable, and then using that one variable to give that one (same) weapon to each player:

Code:
public void GiveRandomWeapon(int client_target)
{
	float totalProba = 0.0;
	for (int i = 0; i < sizeof weapons_all; i++)
	{
		totalProba += GetConVarFloat(h_weapons_cvar[i]);
	}
	
	if (totalProba == 0.0)
	{
		PrintToChat(client_target, "Random Weapons ERROR: All weapons disabled");
	}
	else
	{
		float rdmWeapon = 0.0;
		do
		{
			rdmWeapon = GetRandomFloat(0.0, totalProba);
		} while (rdmWeapon == 0.0);
		float currentProba = 0.0;
		
		for (int i = 0; i < sizeof weapons_all; i++)
		{
			if (rdmWeapon <= (currentProba + GetConVarFloat(h_weapons_cvar[i])))
			{
				kills_per_client[CheckClient(client_target)][3] = i;
				GiveWeapon(weapons_all[i], client_target);
				break;
			}
			currentProba = currentProba + GetConVarFloat(h_weapons_cvar[i]);
		}
	}
	
}

Last edited by Dabosman; 10-29-2019 at 10:49.
Dabosman is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-29-2019 , 13:53   Re: Need help making simple code change
Reply With Quote #4

Sorry I had understood wrong.

Well, I did some modifications but I didn't test since I don't have CSGO.

Maybe it isn't working but can be a way to what u are trying to achieve.

Here is the diff https://www.diffchecker.com/HsIXYoLP

I found the code a bit messy and I think that it doesn't work properly, but I could be wrong.
Attached Files
File Type: sp Get Plugin or Get Source (rdm-weapons-test.sp - 160 views - 10.8 KB)
__________________

Last edited by Marttt; 10-29-2019 at 13:55.
Marttt is offline
Dabosman
Junior Member
Join Date: Mar 2004
Old 11-07-2019 , 00:57   Re: Need help making simple code change
Reply With Quote #5

Quote:
Originally Posted by Marttt View Post
Sorry I had understood wrong.

Well, I did some modifications but I didn't test since I don't have CSGO.

Maybe it isn't working but can be a way to what u are trying to achieve.

Here is the diff https://www.diffchecker.com/HsIXYoLP

I found the code a bit messy and I think that it doesn't work properly, but I could be wrong.

Marttt, you're amazing bro! I've been so busy with work and meaning to reply back to you.

Here's what I've found out and done so far with the plugin:

It's working perfectly (almost, one very small glitch I'll mention below). It spawns everyone with the NEW RANDOM WEAPON (same for everyone) each round just like it should. What I found out I had to do though to get it to work this way:

I had to set the min and max rdm_kills_needed_min and max to 100 .. so that it wouldn't spawn the new random weapon upon each kill made. I could just also hardcode and 'comment out' the portion that does this in code .. but this works for now. The small 'glitch' I mentioned only comes into play once the player has reach 100 total kills (and seems to carry across maps). We only noticed this one time during an extended gaming session .. but happened after about 4 maps. I'll enable and turn on some debugging so that I can confirm this is what caused it - which I'm almost positive it is. Not a big deal though for now. I can correct.

Here are the settings I set:
Code:
rdm_kills_needed_max "100"
rdm_kills_needed_min "100"
rdm_show_kill_count "0"
rdm_spawn_last_weapon "0"
I also figured out server cvars to enable giving armor and also defuse kits to all .. so that's working well. I also had to figure out how to strip some maps (especially the aim maps) of weapons that are already spawned/placed onto the maps. I found a good server cvar for this .. and had to get another cvar enforcer plugin to keep that cvar enforced .. and it's working very well.

Lastly, here is where I took it to the next step:
I actually figured out how to set variables for all the 5 types of grenades .. created variables and even cvars for enable/disable in the code, and coded those into the plugin as well .. so that someone can enable and disable grenades at will (in addition to the random weapon given). I was pretty proud that I was able to look at code and figure this out.

I'll upload this updated version of the plugin very soon to the author's original thread.. I want to make sure to comment a couple things .. and also give original author credit and you as well in it. Hopefully that's the proper way to do that .. as I'm not trying to claim it as my own.

Come check out the server in CSGO with the updated Random Weapons Plugin with your changes and my changes at:
cs.pdelta.info:27015

Thanks so much again. I may hit you up if that's okay for some future tweaking on this .. but your code changes have helped me learn so much on this. Can't thank you enough.


Last edited by Dabosman; 11-07-2019 at 01:07.
Dabosman is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 11-07-2019 , 04:58   Re: Need help making simple code change
Reply With Quote #6

Hi Dabosman, I'm glad I could help and give you a hint to achieve what you were looking for.

As I said previously, I don't think the default plugin works properly because it doesn't "randomize" well the feature of giving weapons,

The default plugin just does a loop inside the weapons list array, and if the "dice" runs greater than the minimum chance it gives the weapon to the player.
So the weapons in the end of the array have a big less propability to be given
What I did was randomize this selection so the chance would be more fair.

Also when I did the modifications I saw this killing count that gives a random weapon, thats what I mean by still having some bugs

I think to "fix" that you have to comment these snippets below (or something like this)

Spoiler


I don't know about CSGO, but in L4D2 I remove some items from the map using the "Stripper" plugin.
__________________

Last edited by Marttt; 11-07-2019 at 04:59.
Marttt is offline
Dabosman
Junior Member
Join Date: Mar 2004
Old 11-07-2019 , 09:28   Re: Need help making simple code change
Reply With Quote #7

Hey Marttt ... yes, I think he designed the plugin to be able to do the 'feature' of giving a new random weapon after someone kills another ... however to me, that makes it a bit too much like 'Arms Race' mode that is a built-in CS mode where you get progressive guns as you do more kills.

Ah - didn't realize you updated the 'random code' a bit ... I may have missed you saying that. Thank you though! It seems decently random from my son and I playing yesterday. I think maybe the MP5 wasn't given if at all .. but it's possible the plugin is old enough that it doesn't include the MP5 since it was released later .. so I can easily look that up and add to the beginning of the script if needed.

Again, you've helped me immensely with this - and I thank you.

Is there any good references for learning SourcePawn that you'd recommend? I've got the links on this forum for the starter's guide, etc. .. FAQ .. etc .. but wondered if there was something personally that helped you learn as well? I know that I learn much better as a 'hands on' approach .. so this helps me more than anything looking over already working and 'real world' type code for these plugins. I do however want to learn EFFICIENT code .. so I'd appreciate any critique you can provide.

I'm about to post the updated version 1.03 that I made on the original author's post - giving someone a chance to download it if they want. Keeping him as the still current author - and giving yourself and myself credit in there. Is that the proper way to do this? (etiquette-wise) ? Definitely don't want to step on any toes - and not trying to claim as mine.

Thanks.
__________________
Dabosman is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 11-07-2019 , 10:58   Re: Need help making simple code change
Reply With Quote #8

Just a final note, I'm not sure if my randomizer is done correctly, it was good to check if the first and last items in the array are being given at some point, maybe are being excluded from the selection. I think I did it OK but would be nice to test it.




Regarding learning, well, I'm not the best developer here, but I have some degree in programming, which helped a lot.

I recommend you download the source code of some simple plugins you use and understand how they got to the end result.

In my case I learned a lot by downloading the source code of some plugins from good developers here in the forum (for L4D2, I could say it's Crasher, Silvers and Lux are one of them) and trying to understand what they did and why they did it, sometimes they give me a few tips that are always welcome, so I'm immensely grateful to them.

It is also good to do some customizations to plugins you already use "improving" the version as you did.
I only modify plugins for L4D2 in general, but always post some improved or tweaked versions that people asked for in the forum (like abandoned plugins).

I just haven't been so active here because the last few months have been busy with appointments and work.

Well, I'm happy that it worked for you. Good luck!
__________________

Last edited by Marttt; 11-07-2019 at 11:01.
Marttt 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 19:05.


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