Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
random setfreq rather than a static number
Goto page 1, 2  Next
 
Post new topic   Reply to topic Printable version
 View previous topic  A plugin Post :: Post Plugin Request: ASSS style soccer bal...  View next topic  
Author Message
bigshot3754
Guest


Offline

PostPosted: Wed Aug 18, 2004 2:57 pm    Post subject: random setfreq rather than a static number Reply to topic Reply with quote

i'm editing the tv vex plugin, and it sets kicked people to freq 0 initially, i changed this to 85, but now i want this to be a random freq in 3-99 instead

sendPrivate(parse->item, "*setfreq 85");

thats what it is right now, i've read over the mervbot tutorial, with the section on random numbers and players, but it failed to work, and yes, i did include time.h tongue.gif

my guess is that my syntax was wrong or something, this is what i thought it should have been:

srand(time(NULL));
rand();
int tempkickofffreq = (int) (99 * ((float)rand()/RAND_MAX));
sendPrivate(parse->item, "You were kicked from the freq");
sendPrivate(parse->item, "*setfreq " + tempkickofffreq);

tho that would do 0-99 correct? (still didn't work btw)
i also tried putting the last tempkickofffreq as: int(tempkickofffreq)

and vegito suggested this to me:

srand(time(NULL));
int Random = rand()%51 + 1;
sendPrivate(parse->item, "You were kicked from the freq");
sendPrivate(parse->item, "*setfreq " + Random);

none have worth thus far, i'm hoping someone here will know what i'm talking about and can correct me

ty in advanced
Back to top
Solo Ace
Yeah, I'm in touch with reality...we correspond from time to time.


Age:37
Gender:Gender:Male
Joined: Feb 06 2004
Posts: 2583
Location: The Netherlands
Offline

PostPosted: Wed Aug 18, 2004 3:25 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide
inline int randrange(int low, int high)
{
    return rand() / (RAND_MAX / (high - low + 1)) + low;
}


It crashed my program when I passed values with a too big difference to it I think, but I guess you won't have such problems.
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Wed Aug 18, 2004 4:49 pm    Post subject: Reply to topic Reply with quote

Should work:
Code: Show/Hide
rand() * 97 + 2

_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Underlord
Novice


Gender:Gender:Male
Joined: Feb 17 2004
Posts: 55
Offline

PostPosted: Wed Aug 18, 2004 5:33 pm    Post subject: Reply to topic Reply with quote

sendPrivate(parse->item, "*setfreq " + tempkickofffreq);

should be:

sendPrivate(parse->item, "*setfreq " + (String) tempkickofffreq);
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
bigshot3754
Guest


Offline

PostPosted: Fri Aug 27, 2004 12:03 pm    Post subject: Reply to topic Reply with quote

ty you three, i'll try yours first underlord
Back to top
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Aug 27, 2004 12:35 pm    Post subject: Reply to topic Reply with quote

rand() % 97 + 3 will result in numbers from 3 to 99
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Fri Aug 27, 2004 2:32 pm    Post subject: Reply to topic Reply with quote

rand % 97? you mean rand() * 97?
_________________



Last edited by D1st0rt on Fri Aug 27, 2004 2:43 pm, edited 1 time in total
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Fri Aug 27, 2004 2:34 pm    Post subject: Reply to topic Reply with quote

No, rand gives an int. The modulo operator (%) will take the remainder when devided by 97. Means you get a random number from 0 to 96.

+3 gives the proper offset.
_________________
Hyperspace Owner

Smong> so long as 99% deaths feel lame it will always be hyperspace to me
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Fri Aug 27, 2004 2:44 pm    Post subject: Reply to topic Reply with quote

I thought rand gave a decimal between 0 and 1
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Deadly
Seasoned Helper


Age:34
Gender:Gender:Male
Joined: Oct 15 2003
Posts: 148
Location: Ontario Canada
Offline

PostPosted: Fri Aug 27, 2004 3:33 pm    Post subject: Reply to topic Reply with quote

blah, that random stuff confuses me.. i tried making a lottery plugin didnt work, gay random

its wierd.. it chooses a random number, then i make it say "*arena Number: " +(String)temp or whatever, for testing so i can guess the number and see if it works.. but it didnt work, i think when it sends the arena its choosing a new number by doing +(String)temp..

Code: Show/Hide
         if(countdown[0] == 14){
            srand(time(NULL));
             rand();
            int temp = (int) (51 * ((float)rand()/RAND_MAX));

            sendPublic("*arena Number for this round is " +(String)temp +".");
         }


if someone can help me out with that.. that would be good tongue.gif
_________________
Known as DeadlySoldier!! in-game..

http://deadly.sscentral.com -- My Bots
Back to top
View users profile Send private message Add User to Ignore List Visit posters website AIM Address MSN Messenger
Underlord
Novice


Gender:Gender:Male
Joined: Feb 17 2004
Posts: 55
Offline

PostPosted: Fri Aug 27, 2004 4:09 pm    Post subject: Reply to topic Reply with quote

that code works fine deadly

rand() returns an int between 0 and RAND_MAX (32767)

never use something like 'rand() % 97'. The way the random number generator works, doing that will give 'less random' numbers, and often cycle between odd/even numbers.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Aug 27, 2004 6:12 pm    Post subject: Reply to topic Reply with quote

Ooops. I got confused with BASIC for a sec there. icon_sad.gif

Underlord wrote:
never use something like 'rand() % 97'. The way the random number generator works, doing that will give 'less random' numbers, and often cycle between odd/even numbers.

I've never noticed a problem doing it that way (which is always how I do it).
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Fri Aug 27, 2004 7:23 pm    Post subject: Reply to topic Reply with quote

shows how much I know, in Java Math.random() returns a double between 0 and 1
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Aug 27, 2004 8:34 pm    Post subject: Reply to topic Reply with quote

Underlord wrote:
that code works fine deadly

rand() returns an int between 0 and RAND_MAX (32767)

never use something like 'rand() % 97'. The way the random number generator works, doing that will give 'less random' numbers, and often cycle between odd/even numbers.


That's retarded. If rand() is unreliable, then you should not use it at all. Going through a floating point conversion of it, makes it less efficient also, but doesn't make it any more random. If you don't like rand(), then download a better RNG, but always use the MOD operator.


Last edited by Mr Ekted on Fri Aug 27, 2004 11:44 pm, edited 1 time in total
Back to top
View users profile Send private message Add User to Ignore List
Deadly
Seasoned Helper


Age:34
Gender:Gender:Male
Joined: Oct 15 2003
Posts: 148
Location: Ontario Canada
Offline

PostPosted: Fri Aug 27, 2004 10:09 pm    Post subject: Reply to topic Reply with quote

Underlord wrote:
that code works fine deadly


ok.. well the way i ahve it is when a player types !guess <number> it stores set_tag(p, GUESS, playersnumber), then when time is over, it goes through the tag list, taking everyones number, and seeing if it matches by doing

Code: Show/Hide

if(get_tag(p, GUESS) == temp){
winner = p->name;
}


Didnt seem to work icon_sad.gif
Back to top
View users profile Send private message Add User to Ignore List Visit posters website AIM Address MSN Messenger
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Aug 27, 2004 11:32 pm    Post subject: Reply to topic Reply with quote

Can we see a little more of that code, please?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Sat Aug 28, 2004 12:09 am    Post subject: Reply to topic Reply with quote

Uint16 random_range(Uint16 lowest_number, Uint16 highest_number)
{
if(lowest_number > highest_number){
swap(lowest_number, highest_number);
}
Uint16 range = highest_number - lowest_number + 1;
return lowest_number + Uint16(range * rand()/(RAND_MAX + 1.0));
}


this is the function that i have used to do random ranges. I think i got it off a website. Its more efficient to just use the modulus operator.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
_D1st0rt
Guest


Offline

PostPosted: Sat Aug 28, 2004 12:34 am    Post subject: Reply to topic Reply with quote

Merv comes with a prng
Back to top
bigshot3754
Guest


Offline

PostPosted: Fri Sep 03, 2004 1:03 pm    Post subject: Reply to topic Reply with quote

ok, this is still failing to work for me

Quote:

if (name == parse->item->name)
{
if (parse->item->team != i)
{
sendPrivate(p, "The player is not on the freq");
return;
}
srand(time(NULL));
rand();
int tempkickofffreq = (int) (99 * ((float)rand()/RAND_MAX));
sendPrivate(parse->item, "You were kicked from the freq");
sendPrivate(parse->item, "*setfreq " + (String) tempkickofffreq);
return;
}




that what i have so far

Quote:

command.cpp(556) : error C2664: 'void __thiscall botInfo::sendPrivate(struct Player *,char *)' : cannot convert parameter 2 from 'class String' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.


if anyone could help me, it would be great, if u can't, i understand
Back to top
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Sep 03, 2004 2:16 pm    Post subject: Reply to topic Reply with quote

Replace
Code: Show/Hide
sendPrivate(parse->item, "*setfreq " + (String) tempkickofffreq);

with
Code: Show/Hide
sendPrivate(parse->item, String("*setfreq " + (String) tempkickofffreq)).msg;

Should work.

Really it's better do do something like:
Code: Show/Hide
String message("*setfreq");
message += tempkickofffreq;
sendPrivate(parse->item, message.msg);

More lines of C++, less lines of ASM (without optimization).
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
bigshot3754
Guest


Offline

PostPosted: Thu Oct 21, 2004 4:18 pm    Post subject: Reply to topic Reply with quote

i know this is an old thread, but thank you very much cyan~fire, what you posted worked perfectly

if anyone knows how to make this 2-99, that would be great:
Code: Show/Hide

int tempkickofffreq = (int) (99 * ((float)rand()/RAND_MAX));
Back to top
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Thu Oct 21, 2004 5:48 pm    Post subject: Reply to topic Reply with quote

Wow, you really didn't understand anything we told you?

First of all, rand() returns an int. Why are you float-ing it?

Second, learn what the % operator does and then modify the code yourself (to use it).
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Underlord
Novice


Gender:Gender:Male
Joined: Feb 17 2004
Posts: 55
Offline

PostPosted: Thu Oct 21, 2004 9:25 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide

srand(time(NULL));
rand();
int tempkickofffreq = (int) (97 * ((float)rand()/RAND_MAX)) + 2;
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Thu Oct 21, 2004 10:36 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide
int tempkickofffreq = (rand() % 97) + 2;
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
bigshot3754
Guest


Offline

PostPosted: Thu Oct 21, 2004 10:51 pm    Post subject: Reply to topic Reply with quote

Again, thank you for the resonses

@Cyan~Fire:
I'm very sorry I couldn't comprehend much from reading some lines of code involving the simplicities of random numbers. I'm always thankful for the help, but nothing provided to me so far has actually worked (what you gave me compiled fine but doesn't work when the command is sent :S) but I'm not complaining, I'm going to continue to use the items given here and hopefully get it working properly.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 368 page(s) served in previous 5 minutes.

phpBB Created this page in 0.556155 seconds : 50 queries executed (92.0%): GZIP compression disabled