Raised This Month: $ Target: $400
 0% 

Is there a faster way to do this?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lunarwolfx
Member
Join Date: Feb 2005
Old 03-22-2005 , 20:38   Is there a faster way to do this?
Reply With Quote #1

I'm was thinking the other day about changing speeds based on levels, and I came up with this.
Code:
if(level[id] == 1) {

set_user_maxspeed(id,320.0)
}
else if(level[id] == 2) {

set_user_maxspeed(id,321.0)

}
etc....

I was just wondering if there is a faster way then making a mess of ifs and else ifs.
lunarwolfx is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 03-22-2005 , 20:45  
Reply With Quote #2

Code:
// ..     switch(level[id]) {         case 1: set_user_maxspeed(id,320.0)         case 2: set_user_maxspeed(id,321.0)         case 3: set_user_maxspeed(id,321.0)         // etc..     }
Should work .
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
|2eM!x
Member
Join Date: Mar 2005
Old 03-22-2005 , 20:46  
Reply With Quote #3

ooh i like that idea! Is that your whole code?
|2eM!x is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 03-22-2005 , 22:47  
Reply With Quote #4

Depending on the max levels, that could take forever, and it would use up a huge amount of space in the plugin. Just use a simple formula for it.

Code:
new Float:maxspeed = 319.0 + float(level); set_user_maxspeed(id,maxspeed);
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
lunarwolfx
Member
Join Date: Feb 2005
Old 03-22-2005 , 23:30  
Reply With Quote #5

/me slaps forehead

so simple! Yet I couldn't figure it out.

Wow, you totally opened up a new line of thinking for me. Thanks again.
lunarwolfx is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-23-2005 , 09:45  
Reply With Quote #6

Quote:
Originally Posted by XxAvalanchexX
Depending on the max levels, that could take forever, and it would use up a huge amount of space in the plugin. Just use a simple formula for it.

Code:
new Float:maxspeed = 319.0 + float(level); set_user_maxspeed(id,maxspeed);
Yep. Algorithims are the best way to get things done.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
dwelty
New Member
Join Date: Feb 2005
Old 03-23-2005 , 11:17  
Reply With Quote #7

Quote:
Originally Posted by v3x
Code:
// ..     switch(level[id]) {         case 1: set_user_maxspeed(id,320.0)         case 2: set_user_maxspeed(id,321.0)         case 3: set_user_maxspeed(id,321.0)         // etc..     }
Should work :).

I see a lot of this. Common mistake. You forgot your breaks. Case execution falls through. it should look like this:

Code:
// ..   switch(level[id])   {     case 1:     {       set_user_maxspeed(id,320.0);       break;     }     case 2:     {       set_user_maxspeed(id,321.0);       break;     }     case 3:     {       set_user_maxspeed(id,322.0);       break;     }     // etc..   }


XxAvalanchexX had the right idea though. That's your best bet.
__________________
dwelty is offline
twistedeuphoria
Veteran Member
Join Date: Jul 2004
Old 03-23-2005 , 11:20  
Reply With Quote #8

Small doesn't require breaks
__________________
twistedeuphoria is offline
dwelty
New Member
Join Date: Feb 2005
Old 03-23-2005 , 11:23  
Reply With Quote #9

Oh.
Thanks for letting me know.
__________________
dwelty is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-23-2005 , 11:24  
Reply With Quote #10

SMALL breaks when it reaches a case that matches. No fall through.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
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 09:55.


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