5 posts,
4 people · 865 views
Thread Rating: ★★★★★
| closedCreating and calling an ini file |
| Started by Tank on 02-06-2009, 11:04 AM |
started this thread
Posts: 581Threads: 59
Joined: Jan 2007
02-06-2009, 11:04 AM
#1
Hey guys,rnrnIm working on a plugin where I need to create two files (prolly ini but if can be anything else, thats fine as well) which holds certain maps.rnrnHow do I call the files in my coding?rnrn
get_configsdir(config_dir,32)rn format(config_holder,48,"%s/mymaps.ini",config_dir)rnrnrnI came across this, not sure how to use it though. Can someone shed some light on this subject?posted here
Posts: 776Threads: 75
Joined: Nov 2007
02-06-2009, 11:11 AM
#2
You can create a file and a dir like this:rnrn#define UNLUCKY_LOG_NAME "unlucky_players.txt"rnrn
public failure_log()rn{rn if(dir_exists("addons/amxmodx/data/dod_combat_bonus_failure_log"))rn return PLUGIN_HANDLEDrn rn new LogFile[128]rn get_datadir(LogFile, sizeof LogFile - 1)rn add(LogFile, sizeof LogFile - 1, "/dod_combat_bonus_failure_log")rn if(!dir_exists(LogFile)) rn {rn mkdir(LogFile) rn format(LogFile, sizeof LogFile - 1, "%s/%s", LogFile, UNLUCKY_LOG_NAME) rn new iFile = fopen(LogFile, "wt+")rn rn new CurrentTime[21] rn get_time("%m/%d/%Y - %H:%M",CurrentTime,20) rn rn fprintf(iFile,"//This file stores people that missed there combat bonus^n//Plugin made by Dr.G - www.clan-go.net^n//Log started: %s",CurrentTime)rn fclose(iFile)rn }rn return PLUGIN_HANDLEDrn}rnrnWrite to it like this:rnrn new LogFile[128]rn new steamid = get_user_userid(killer)rn rn get_datadir(LogFile, sizeof LogFile - 1)rn format(LogFile, sizeof LogFile - 1, "%s/dod_combat_bonus/%s", LogFile, BONUS_LOG_NAME)rn rn new iFile = fopen(LogFile, "a+")rn fprintf(iFile,"[DoD Combat Bonus]%s | STEAMID (%d) | got a godmode bonus!^n", name, steamid)rn fclose(iFile)rnrni havent try to get info from a file, but take a look at the clanmatch plugin or so, that should have its own cfg file...ive heard :Prnrn*EDIT*rnrnIve made may files txt so i can hook a say command to show_motd and see whats inside it. If u want a ini just make it #define UNLUCKY_LOG_NAME "unlucky_players.ini" in case above...posted here
Posts: 2,068Threads: 103
Joined: May 2005
02-06-2009, 11:54 AM
#3
you can also skim thru this for some more infonnhttp://forums.alliedmods.net/showthread.php?t=46218
posted here
Posts: 277Threads: 15
Joined: Mar 2007
02-06-2009, 04:12 PM
#4
Definitely use the new file commands like in Dr.G's post. The old write_file, while easier, is like trying to stick a fruitcake down a drain hole and read_file is OK but better to use something like this with the new commands:nnn
nnew file_contents[64][128] // Holds each line in a filennew total_lines // Keeps track of how many lines there were in totalnpublic func_load_file() {n // Load file if it existsn if(file_exists(file_name))n {n new temp_holder[128]n new file = fopen(file_name,"rt")n n // Load names into arrayn while(!feof(file))n {n fgets(file,temp_holder,127) // Load a line into temp arrayn replace(temp_holder,127,"^n","") // Cut off the new line n format(file_contents[total_lines],127,"%s",temp_holder) // Store the contents into the main arrayn total_lines++n }n fclose(file)n }n}nnAs for the get configsdir, that is basically grabbing the current directory path for the amxmodx config directory it is running on. While most installations would be dodaddonsamxmodxconfigs , someone might put it somewhere else and this will help alleviate that problem. Format is just combining this path with a file name which can then be used to check to see if the file exists, fopen or other file functions.posted here
Posts: 776Threads: 75
Joined: Nov 2007
02-07-2009, 06:30 PM
#5
how do u get lastest logged action first and not last?

