Raised This Month: $ Target: $400
 0% 

how can i read from file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-18-2013 , 14:54   how can i read from file
Reply With Quote #1

Lets say I have a menu and i have defined item costs :
Code:
#define COST1 100 #define COST2 300 #define COST3 100 #define COST4 1201 #define COST5 1070

And later on I user them e.g.
Code:
client_print(id, print_center, "This item costs : %d", COST1);

I want to make a new file costs.ini and read COST1, COST2, COST3 and COST4 from there , how can I do that ? Could you please provide an example?
Podarok is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 04-18-2013 , 15:54   Re: how can i read from file
Reply With Quote #2

try pcvar then you can set the amount from any configuration file that gets exec. ?
__________________
Blizzard_87 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-18-2013 , 16:24   Re: how can i read from file
Reply With Quote #3

Ask layka_lubii, he is the king of pop.

Or look there : https://forums.alliedmods.net/showthread.php?t=46218
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-18-2013 at 16:40.
ConnorMcLeod is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-18-2013 , 23:58   Re: how can i read from file
Reply With Quote #4

Quote:
Originally Posted by ConnorMcLeod View Post
Ask layka_lubii, he is the king of pop.

Or look there : https://forums.alliedmods.net/showthread.php?t=46218
Oh, come on, Connor. I apologised for that trolling Thanks for the link, I read and didnt get the idea =(
Podarok is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 04-19-2013 , 00:32   Re: how can i read from file
Reply With Quote #5

here is a basic example with use of pcvars to make item costs...

then just add the cvars to amxx.cfg or another cfg file...



Example
__________________
Blizzard_87 is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-19-2013 , 00:40   Re: how can i read from file
Reply With Quote #6

@Blizzard, I know how to use them but I dont want to use them, I have 2 reasons for that.
1) I want to learn something new
2) I want an .ini file for my plugin, i think its better then cvars
Podarok is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 04-19-2013 , 00:43   Re: how can i read from file
Reply With Quote #7

Quote:
Originally Posted by Podarok View Post
@Blizzard, I know how to use them but I dont want to use them, I have 2 reasons for that.
1) I want to learn something new
2) I want an .ini file for my plugin, i think its better then cvars
ok sorry my bad.
__________________
Blizzard_87 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-19-2013 , 00:46   Re: how can i read from file
Reply With Quote #8

Find a plugin that already does something similar to what you want and get that working. Then modify it for your purposes. After you have done that you should ask specific questions.
__________________
fysiks is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-19-2013 , 01:32   Re: how can i read from file
Reply With Quote #9

Thanks for response, fysiks. I was looking for some simple plugin, but i didnt get the idea. Could u please provide a descriptive example?
Podarok is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-19-2013 , 03:32   Re: how can i read from file
Reply With Quote #10

Quote:
Originally Posted by Podarok View Post
Thanks for response, fysiks. I was looking for some simple plugin, but i didnt get the idea. Could u please provide a descriptive example?
wow . . . you need to learn one thing at a time. Learn how to read a file. There are hundreds of plugins that do this. Both plugins in my signature read from files. If you don't want to use my code as an example, look for plugins that read files with fopen(), fgets(), fclose(), etc.

Once you are able to read the file, you simply need to get the number from the resulting strings with str_to_num().
__________________

Last edited by fysiks; 04-19-2013 at 03:32.
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 10:56.


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