This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

[DOD] Weapons Equipment by Steam ID


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Admin Commands       
TheVaskov
Member
Join Date: Sep 2021
Location: Russia
Old 05-13-2024 , 06:23   [DOD] Weapons Equipment by Steam ID
Reply With Quote #1

This plugin opens a simple menu when you respawn after death with a choice of weapons that are available to you as a VIP player.



It reads from the ini file the list of available weapons for a specific steam ID
After the first launch, it creates a file with the following content:
addons/amxmodx/configs/ck_custom_equip.ini
PHP Code:
STEAM_0:1:168151617 weapon_enfield weapon_sten 
I can make the plugin work in two modes:
classic is when your current weapon falls out of your hands and a new one comes out.
and secondary is when two primary weapons are placed in 1 slot. it's like having two rifles.

___________
The plugin was created at the request of the administrator. However, before continuing my work, I want to ask the professionals.

Each time it spawns, the plugin again accesses the text file and processes it. It's fast and easy when I test it on a home server. but when such a function is repeated every respawn for 32 players, I suspect it will be difficult.
Can we translate a list of weapons into bitmasks.
or does it make sense to create a multidimensional text array for each player and parse the data into it, and then process it from the RAM?
Attached Files
File Type: sma Get Plugin or Get Source (dod_ck_customequip.sma - 17 views - 7.9 KB)
__________________

Last edited by TheVaskov; 05-13-2024 at 08:11.
TheVaskov is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-13-2024 , 22:18   Re: [DOD] Weapons Equipment by Steam ID
Reply With Quote #2

  1. You're not doing anything that requires precaching or being in the precache forward. Create a function to "check for config file, if it doesn't exist, create it" and then simply call that from plugin_init().
  2. Using recursion is not necessary where you're doing it. If the directory creation or the file creation fail, you've created an infinite loop.
  3. When using the AMX Mod X configs directory, the directory path should be obtained using get_configsdir() and any subsequent file paths built using this instead of hard coding these paths. Also, when using this, there is no reason to check for its existence, it is guaranteed to exist. You only need to check for the config file itself.
  4. I don't see anything in the name of the plugin that implies an abbreviation of "ck" so I'm curious what this is a reference to. If it's not related to the plugin it probably doesn't make sense to use it in any plugin-specific file names.
  5. The fgets() returns a number of characters written to the buffer string so checking if it's not equal to 1 is not correct, you should check for non-zero value or simply "while(fgets())".
  6. You define "line_num" as a variable in two overlapping scopes. This is often avoided in plugins by adding a prefix like "g_" to variables that are defined in the global scope meaning that it would never conflict with a lower scope's variable of the otherwise same name.
  7. Hard coding your personal SteamID to automatically get privileges on other peoples' servers is ethically questionable (if not worse). If it was just forgotten after original debuggin, then fair enough, but it should be removed. Even better would be to add documentation to the file using file comments (which requires you to filter out comment lines in your processing of the file).
  8. You MUST ALWAYS check if the user is alive in the Ham_Spawn callback. Seems counter-intuitive but that's how it is.
  9. There are functions specifically for parsing string like you have in your config file e.g. argparse(). The documentation provides an example to loop through an indeterminite number of arguments. This will significantly simplify your loop for parsing the string and adding items to the menu. As the saying goes, no need to re-invent the wheel.
  10. client_putinserver() should be changed to client_authorized().
__________________
fysiks 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:46.


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