AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ SOLVED ] Make .ini or .cfg file to plugin? (https://forums.alliedmods.net/showthread.php?t=274809)

CrazY. 11-15-2015 10:10

[ SOLVED ] Make .ini or .cfg file to plugin?
 
How to make basic .ini or .cfg to configure the weapons?
This is the code:
Code:
#include < amxmodx > #include < fun > #include < cstrike > #include < hamsandwich > #include < zombieplague > /*===============================================     "weapon_xm1014"     // XM1014     "weapon_mac10"      // MAC10     "weapon_aug"        // AUG     "weapon_ump45"      // UMP45     "weapon_sg550"      // SG550     "weapon_gali"       // GALIL     "weapon_famas"      // FAMAS     "weapon_mp5navy"    // MP5     "weapon_m249"       // M249     "weapon_m3"     // M3     "weapon_m4a1"       // M4A1     "weapon_tmp"        // TMP     "weapon_g3sg1"      // G3SG1     "weapon_sg552"      // SG552     "weapon_ak47"       // AK47     "weapon_p90"        // P90 ===============================================*/ new cvar_botquota, g_hamczbots; new bot_weapons[][] = {     "weapon_m4a1",     "weapon_sg552",     "weapon_ak47" } public plugin_init() {     register_plugin("[ZP] CS/CZ Bot Weapons", "1.0", "CrazY");     cvar_botquota = get_cvar_pointer("bot_quota"); } public client_putinserver(id) {     if (is_user_bot(id) && !g_hamczbots && cvar_botquota)         set_task(0.1, "register_ham_czbots", id); } public register_ham_czbots(id) {     if (g_hamczbots || !is_user_bot(id) || !get_pcvar_num(cvar_botquota))         return;     RegisterHamFromEntity(Ham_Spawn, id, "fw_HamBotSpawn_Post", 1);     g_hamczbots = true; } public fw_HamBotSpawn_Post(id) {     new size_bot_weapons = random(sizeof bot_weapons);     give_item(id, bot_weapons[size_bot_weapons]);     cs_set_user_bpammo(id, get_weaponid(bot_weapons[size_bot_weapons]), 90); } public zp_user_humanized_post(id) {     if(is_user_bot(id) && !zp_get_user_survivor(id) && !zp_get_user_sniper(id))     {         new size_bot_weapons = random(sizeof bot_weapons);         give_item(id, bot_weapons[size_bot_weapons]);         cs_set_user_bpammo(id, get_weaponid(bot_weapons[size_bot_weapons]), 90);     } }

fysiks 11-15-2015 12:32

Re: [ HELP ] Make .ini or .cfg file to plugin?
 
Simply learn how to read a file and then use that strings that you get from the file to insert into the bot_weapons array.

CrazY. 11-15-2015 12:35

Re: [ HELP ] Make .ini or .cfg file to plugin?
 
Tutorials about it?

fysiks 11-15-2015 13:47

Re: [ HELP ] Make .ini or .cfg file to plugin?
 
About what? Have you tried searching? Also, one simple example of reading a file can be found in my "Bot Apology for TK" in my signature.

CrazY. 11-15-2015 16:36

Re: [ HELP ] Make .ini or .cfg file to plugin?
 
Tutorials about how to make config file :lol:
I will take a look.

Bugsy 11-15-2015 17:09

Re: [ HELP ] Make .ini or .cfg file to plugin?
 
Is the goal of this to replace what the bot_weapons[] array holds? Is this just a list of weapon names that will be used?

CrazY. 11-15-2015 20:18

Re: [ HELP ] Make .ini or .cfg file to plugin?
 
Yes.

fysiks 11-15-2015 20:31

Re: [ HELP ] Make .ini or .cfg file to plugin?
 
If you want a tutorial, search for it. You don't really need a tutorial because the code I told you to look at does everything that you need already. You just need to convert it for your purpose.

P.S. A "config" file is just a text file.
P.P.S. The file that you are describing wouldn't really be a cfg file, IMO. In the context of HLDS, a .cfg file contains commands/cvars and can be executed fully standalone with the exec command.
P.P.P.S Note that this was early in my plugin scripting experience so you would want to update this:

Code:

new g_sorry_phrases[SORRYS_MAX][SORRYS_LEN+1]
to

Code:

new g_sorry_phrases[10][65]
And then SORRYS_LEN should be replaced by charsmax(g_sorry_phrases[]) and SORRYS_MAX should be replaced by sizeof(g_sorry_phrases).

Bugsy 11-15-2015 20:44

Re: [ HELP ] Make .ini or .cfg file to plugin?
 
File needs to be in below format (supports exclusion by using ';' or '//'):
Code:

weapon_ak47
;weapon_glock
//weapon_awp
weapon_fiveseven
weapon_deagle

PHP Code:

#include <amxmodx>
#include <amxmisc>

new g_szWeaponList30 ][ 20 ] , g_WeaponsLoaded;

public 
plugin_init()
{
    
LoadWeapons();
    
    
server_print"Random weapon = [%s]" g_szWeaponListrandomg_WeaponsLoaded ) ] );
}

public 
LoadWeapons()
{
    new 
iFile szFile64 ];
    
formatexszFileget_configsdirszFile charsmaxszFile ) ) ] , charsmaxszFile ) , "/weapons.ini" );
    
    
g_WeaponsLoaded 0;
    
    if ( ( 
iFile fopenszFile "rt" ) ) )
    {
        while ( 
g_WeaponsLoaded sizeofg_szWeaponList ) && fgetsiFile g_szWeaponListg_WeaponsLoaded ] , charsmaxg_szWeaponList[] ) ) )
        {
            
trimg_szWeaponListg_WeaponsLoaded ] );
            
            if ( !
g_szWeaponListg_WeaponsLoaded ][ ] || g_szWeaponListg_WeaponsLoaded ][ ] == ';' || ( g_szWeaponListg_WeaponsLoaded ][ ] == '/' && g_szWeaponListg_WeaponsLoaded ][ ] == '/' ) )
            {
                continue;
            }
            else
            {
                
g_WeaponsLoaded++;
            }
        }
        
fcloseiFile );
    }



fysiks 11-15-2015 20:45

Re: [ HELP ] Make .ini or .cfg file to plugin?
 
And how is he supposed to learn anything if you do it all for him?


All times are GMT -4. The time now is 17:15.

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