Raised This Month: $ Target: $400
 0% 

Loops


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 02-25-2005 , 20:48   Loops
Reply With Quote #1

How would I make something loop 5 times with for()?

Edit: Is this right?
Code:
 for (i=1; i<=5; i++) {    something[i] }
__________________
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
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 02-25-2005 , 21:54  
Reply With Quote #2

Yep, just make sure to declare i
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 02-25-2005 , 21:56  
Reply With Quote #3

Heh, knew that. Thanks .

Only ones I've ever worked with are while() loops using MySQL..
__________________
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
BlueRaja
Senior Member
Join Date: Nov 2004
Old 02-26-2005 , 00:28  
Reply With Quote #4

uhh..but remember that arrays go from 0 to n-1...
That is, to access all the elements of array something[]...
Code:
new something[5] for (new i=0; i<5; i++)     something[i]
__________________
STEPS IN TROUBLESHOOTING <insert anything here>:
1. Narrow down the problem to a specific condition or conditions.
2. Fix it.
BlueRaja is offline
Send a message via AIM to BlueRaja Send a message via MSN to BlueRaja
Peli
Veteran Member
Join Date: Mar 2004
Location: San Diego, CA
Old 02-26-2005 , 00:40  
Reply With Quote #5

Sorry to steal his attention but , how would you loop a task? For example , one to take away 5 hp every second for 10 seconds , thanks.
Peli is offline
Send a message via MSN to Peli
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 02-26-2005 , 01:08  
Reply With Quote #6

Quote:
Originally Posted by Peli
Sorry to steal his attention but , how would you loop a task? For example , one to take away 5 hp every second for 10 seconds , thanks.
Like rings of regeneration on WC3, hehe..

Anyhow, I'd like to know that too .
__________________
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
Peli
Veteran Member
Join Date: Mar 2004
Location: San Diego, CA
Old 02-26-2005 , 01:33  
Reply With Quote #7

Yeah , because I'm working on a plugin that needs that... but I tried looking into the WC3 code... one of them just linked me to a piece of code , another was so huge I couldn't even find the functions I was looking for...
Peli is offline
Send a message via MSN to Peli
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 02-26-2005 , 01:35  
Reply With Quote #8

OOO, actually...take a look @ xeroblood's AIO menu .

Poison..
Code:
public poison_loop( p_aCmdArgs[] ) {     new vID = p_aCmdArgs[0]     if( is_user_alive(vID) && (g_nHasEffect[vID-1] & AIO_POISON) )     {         new userHealth = get_user_health( vID )         new nDmgAmount = get_cvar_num( "sv_aio_poison_damage" )         new nNewHP = (userHealth - nDmgAmount)         set_user_health( vID, nNewHP )         if( nNewHP < 1 )         {             message_begin( MSG_BROADCAST, g_nMsgDeath, {0,0,0}, 0 )             write_byte( vID )             write_byte( vID )             write_byte( 0 )             write_string( "infection" )             message_end()         }         new korigin[3]         get_user_origin( vID, korigin )         message_begin( MSG_ONE, g_nMsgDamage, {0,0,0}, vID )         write_byte( 30 )             // dmg_save         write_byte( 30 )             // dmg_take         write_long( 1 << 16 )        // visibleDamageBits         write_coord( korigin[0] )    // damageOrigin.x         write_coord( korigin[1] )    // damageOrigin.y         write_coord( korigin[2] )    // damageOrigin.z         message_end()         emit_sound( vID, CHAN_AUTO, g_szSndPoison, 0.6, ATTN_NORM, 0, PITCH_HIGH )         set_task( 1.0, "poison_loop", 0, p_aCmdArgs, 2 )     }
__________________
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
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 02-26-2005 , 12:14  
Reply With Quote #9

Yes, that method will work, and is called Recursion (when a functon calls itself).

Here is a simpler example:

Code:
#include <amxmodx> // variable to keep track of each players loop times new g_iLoops[33] = 0 public plugin_init() {     register_clcmd( "do_slap_loop", "SlapLoop" ) } public SlapLoop( id ) {     g_iLoops[id] = 10     new victimID[2]     victimID[0] = id     set_task( 1.0, "MyLoopFunc", 0, victimID, 1 )     return PLUGIN_HANDLED } public MyLoopFunc( aCmdArgs[] ) {     new victimID = aCmdArgs[0]     // do stuff here...     user_slap( victimID, 5 ) // Slap victim with 5 hp     // Minus 1 from loops     --g_iLoops[victimID]     // Call self again in 1 second..     if( g_iLoops[victimID] > 0 )         set_task( 1.0, "MyLoopFunc", 0, aCmdArgs, 2 )     return }
xeroblood is offline
Send a message via MSN to xeroblood
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 02-26-2005 , 12:24  
Reply With Quote #10

Nice .
__________________
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
Reply


Thread Tools
Display Modes

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 14:02.


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