AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   how can i read from file (https://forums.alliedmods.net/showthread.php?t=213765)

Podarok 04-18-2013 14:54

how can i read from file
 
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?

Blizzard_87 04-18-2013 15:54

Re: how can i read from file
 
try pcvar then you can set the amount from any configuration file that gets exec. ?

ConnorMcLeod 04-18-2013 16:24

Re: how can i read from file
 
Ask layka_lubii, he is the king of pop.

Or look there : https://forums.alliedmods.net/showthread.php?t=46218

Podarok 04-18-2013 23:58

Re: how can i read from file
 
Quote:

Originally Posted by ConnorMcLeod (Post 1935348)
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 :D Thanks for the link, I read and didnt get the idea =(

Blizzard_87 04-19-2013 00:32

Re: how can i read from file
 
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

Podarok 04-19-2013 00:40

Re: how can i read from file
 
@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

Blizzard_87 04-19-2013 00:43

Re: how can i read from file
 
Quote:

Originally Posted by Podarok (Post 1935533)
@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.

fysiks 04-19-2013 00:46

Re: how can i read from file
 
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.

Podarok 04-19-2013 01:32

Re: how can i read from file
 
Thanks for response, fysiks. I was looking for some simple plugin, but i didnt get the idea. Could u please provide a descriptive example?

fysiks 04-19-2013 03:32

Re: how can i read from file
 
Quote:

Originally Posted by Podarok (Post 1935548)
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().


All times are GMT -4. The time now is 10:56.

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