AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Reading random line. (https://forums.alliedmods.net/showthread.php?t=45549)

stigma 10-05-2006 13:10

Reading random line.
 
If i f.e have these four lines:

---
Haha you died!
KABOOM!
HE powa?
Do not mess with explosives...
---

What should i do if i want a random line to appear when someone is killed by a HE.... - How the event works. I just dont know how to take a random line.

Silencer123 10-05-2006 14:34

Re: Reading random line.
 
Code:
switch(random_num(0,3)) {     case 0:     {         client_print(dead_player_id,print_chat,"Haha you died!")     }     case 1:     {         client_print(dead_player_id,print_chat,"KABOOM!")     }     case 2:     {         client_print(dead_player_id,print_chat,"HE powa?")     }     case 3:     {         client_print(dead_player_id,print_chat,"Do not mess with explosives...")     } }

teame06 10-05-2006 14:50

Re: Reading random line.
 
A better way to do this.
Code:
new const Cows[4][] = {     "Haha you died!",     "KABOOM!",     "HE powa?",     "Do not mess with explosives..." } function_what() {     client_print(dead_player_id, print_chat, "%s", Cows[random(0, 3)]) }

If you were trying to read those 4 lines off of a file and store it into the plugin. There alot of tutorials or people that got help with how to read files in the scripting section.

Xanimos 10-05-2006 15:38

Re: Reading random line.
 
Do you mean a random line from a file? That can be done with the following.

Code:
new szLine[256],txtlen; read_file("filename.ext" , random_num(0 , file_size("filename.ext",1)) , szLine , 255 , txtlen);

stigma 10-05-2006 16:39

Re: Reading random line.
 
No..

teame06:

Why is it random(0,3) - When there's 4 in the "const"

XxAvalanchexX 10-05-2006 16:48

Re: Reading random line.
 
Quote:

Originally Posted by stigma (Post 387961)
Why is it random(0,3) - When there's 4 in the "const"

Because array indexes start at 0. So if you have 4 elements in an array, valid indexes are: 0, 1, 2, and 3. If you used random_num(0,4) and 4 came up, it would be out of bounds, because you are trying to reference the 5th element which doesn't exist.

stigma 10-05-2006 16:55

Re: Reading random line.
 
Okay thanks..

stigma 10-05-2006 16:56

Re: Reading random line.
 
This isent a part of the topic..

But do you know how to get the TEAM's score?

Silencer123 10-05-2006 17:05

Re: Reading random line.
 
Register every time when a Team wins and add 1 to a specific variable.
Use the Search to find what logevents to use. And dont forget to set back to 0 when Game Commencing.

XxAvalanchexX 10-05-2006 22:57

Re: Reading random line.
 
You can register the TeamScore message and remember what its values are in your own variables.


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

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