AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help : int <-> float conversion ?! (https://forums.alliedmods.net/showthread.php?t=84295)

sappounet 01-23-2009 20:35

Help : int <-> float conversion ?!
 
Hello,

I'm facing a stupid problem ...

I'm creating a program that allows players to get all weapon ammo free.

To do that, i check when they can by (between the respawn and the end of buytime) : freezetime + buytime

So i did that :

Code:

new mp_buytime;
new mp_freezetime;

mp_buytime=get_cvar_num("mp_buytime");  // 0.25
mp_freezetime=get_cvar_num("mp_freezetime");  // 10

I want to know the total duration in second.

Since buytime is in minutes, i did that to get in seconds :

Code:

new buytime_total;
buytime_total=(mp_buytime*60)+mp_freezetime;

When i try to use the buytime_total var, it's not set to the right value (it's not (0.25*60)+10)

Both vars are float ... and i'm bored by float ! :)

So the question is :

Is there an easy way to convert between float and int ?

I'm only using <amxmodx> and <cstrike> includes, and i would like as much as possible to not use other files.

Thank you for your help.

Drak 01-23-2009 20:38

Re: Help : int <-> float conversion ?!
 
floatround() ?
float() ?

Exolent[jNr] 01-23-2009 22:02

Re: Help : int <-> float conversion ?!
 
This is how you would do it with floats.
Also, you should use pcvars.

Code:
new mp_buytime; new mp_freezetime; public plugin_init() {     mp_buytime = get_cvar_pointer("mp_buytime");     mp_freezetime = get_cvar_pointer("mp_freezetime"); }
Code:
new Float:buytime_total = get_pcvar_float(mp_buytime) * 60.0 + get_pcvar_float(mp_freezetime);

SnoW 01-24-2009 05:13

Re: Help : int <-> float conversion ?!
 
Quote:

Originally Posted by Exolent[jNr] (Post 749022)
Also, you should use pcvars.

Also, you should read a Pawn tutorial.

sappounet 01-24-2009 09:22

Re: Help : int <-> float conversion ?!
 
Thanks for your answers !

I got another question :

For server performance, is it better to have 1 big plugin/file or many small ?

Thanks

SnoW 01-24-2009 11:13

Re: Help : int <-> float conversion ?!
 
Quote:

Originally Posted by sappounet (Post 749242)
Thanks for your answers !

I got another question :

For server performance, is it better to have 1 big plugin/file or many small ?

Thanks

We are going out of topic here aren't we? Anyway, one big. Though it's so much easier to handle plugins if they are separately.

Exolent[jNr] 01-24-2009 17:56

Re: Help : int <-> float conversion ?!
 
Quote:

Originally Posted by SnoW (Post 749284)
We are going out of topic here aren't we? Anyway, one big. Though it's so much easier to handle plugins if they are separately.

Not completely true.
If there are multiple plugins using frequently-called forwards (such as PreThink, ServerFrame, etc.), then it is better to combine them.
Otherwise, it doesn't make much of a difference.

SnoW 01-25-2009 05:34

Re: Help : int <-> float conversion ?!
 
Quote:

Originally Posted by SnoW (Post 749284)
Though it's so much easier to handle plugins if they are separately.

Here I meant, that if you combine all your server plugins to one sma, and after that want to take one off, it's pretty OPS!
Quote:

Originally Posted by SnoW (Post 749284)
Anyway, one big.

Here I meant exactly what you are saying, it's better for the server performance to combine them(one big).
Quote:

Originally Posted by Exolent[jNr] (Post 749511)
Not completely true.
If there are multiple plugins using frequently-called forwards (such as PreThink, ServerFrame, etc.), then it is better to combine them.
Otherwise, it doesn't make much of a difference.

Don't know what there wasn't completely true in my post, maybe you'll tell me.

Exolent[jNr] 01-25-2009 13:39

Re: Help : int <-> float conversion ?!
 
For example, if you have 5 plugins calling PreThink, PostThink, and ServerFrame, then your server's performance would improve if you combined them.
This is because it has to call the function into each plugin.
If you don't have multiple plugins that use high-cpu forwards, then it won't matter as much to combine them.
Please note that the performance increase won't be very significant.

SnoW 01-25-2009 14:53

Re: Help : int <-> float conversion ?!
 
I know that, I agree that, and I said that(at least meant that). But what a hey, there is pretty much people who don't understand anything I'm saying most of the time. Btw, if the part what was wrong, was that I didn't mention how much it will take effect or in what cases, then let's just leave it over, I was just saying which is better. (For server performance)


All times are GMT -4. The time now is 01:40.

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