Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
auth_update crash
Dec 23, 2017, 10:15 pm
By Remcon
check_tumble
Dec 18, 2017, 7:21 pm
By Remcon
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Bing, Yandex, Yahoo!

Members: 0
Guests: 9
Stats
Files
Topics
Posts
Members
Newest Member
478
3,708
19,242
612
Jacki72H
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » Coding » Mprogs and random numbers
Forum Rules | Mark all | Recent Posts

Mprogs and random numbers
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 May 23, 2010, 11:14 am
Go to the top of the page
Go to the bottom of the page

Keirath
Magician
GroupMembers
Posts144
JoinedJan 24, 2008

One of the builders on the MUD I code for requested a way to use a random number in a mprog and store it for use later in the prog. I was curious as to if this was already possible and just missed or if this is something that anyone has tackled? I'm real curious if so how people went about it.

       
Post is unread #2 May 23, 2010, 7:13 pm
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

I thought there was a snippet in the files section here that added something like this but I can't seem to find it. You might also look in the MudBytes repository.
       
Post is unread #3 May 24, 2010, 4:27 am
Go to the top of the page
Go to the bottom of the page

Keirath
Magician
GroupMembers
Posts144
JoinedJan 24, 2008

I've not found it myself.


Any idea how I could tackle this? I'm not real familiar with the mprog code - at least not enough to know where to start.
       
Post is unread #4 May 24, 2010, 9:12 am
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

Me neither, but David is currently working on a revision of the MudProgs stuff that should make things easier for everyone. It might be helpful to see how that turns out. I think the snippet I'm remembering might have been one of Remcon's, so you might poke around in LoP and see if he's done anything like what you're looking for there.
       
Post is unread #5 May 26, 2010, 7:15 pm
Go to the top of the page
Go to the bottom of the page

dbna2
Sorcerer
GroupMembers
Posts600
JoinedDec 2, 2008

does lop have it?
       
Post is unread #6 May 27, 2010, 4:52 pm
Go to the top of the page
Go to the bottom of the page

Keirath
Magician
GroupMembers
Posts144
JoinedJan 24, 2008

Not that I can find
       
Post is unread #7 May 27, 2010, 7:35 pm
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

I've seen, and put in, something very similar. The one I found, this one, has a setvar command for use within progs that lets you assign a value to some variable and reuse it throughout that run-through.

Something like:
>speech_prog p setvar test
setvar 1 $n.race
if race($i) == $1
say We're the same race: $n.race!
else
say We're different races. I'm a $i.race and you're a $n.race...
sigh
endif

This particular system doesn't allow the use of assigning a functions returned value through setvar though. I never thought to try and add it though it shouldn't be too difficult.
       
Post is unread #8 May 28, 2010, 9:14 am
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

Andril said:

This particular system doesn't allow the use of assigning a functions returned value through setvar though. I never thought to try and add it though it shouldn't be too difficult.

Mudprogs don't really have "functions" -- the things in ifchecks only happen to syntactically look like functions. It's one of my biggest complaints with the language, and also something that I hope to address in my work.
       
Post is unread #9 May 28, 2010, 6:19 pm
Go to the top of the page
Go to the bottom of the page

Zeno
Sorcerer
GroupMembers
Posts723
JoinedMar 5, 2005

You have the setvar stuff installed?

I coded this for my MUD, uses the setvar stuff:
void do_mprand( CHAR_DATA *ch, char *argument )
{
    char arg1 [MAX_INPUT_LENGTH];
    char arg2 [MAX_INPUT_LENGTH];
    char arg3 [MAX_INPUT_LENGTH];
    short var;
    char newtext[MAX_STRING_LENGTH];
    int num1, num2, result;

    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );
    argument = one_argument( argument, arg3 );

    if ( !IS_NPC( ch ) || IS_AFFECTED(ch, AFF_CHARM) || ch->desc )
    {
        send_to_char( "Nani?! (Type commands for a list of commands)\n\r", ch );
        return;
    }

    if ( arg1[0] == '\0' || arg2[0] == '\0' || arg3[0] == '\0' )
    {
        progbug("mprand: no arg", ch );
        return;
    }

    if ( !is_number(arg2) )
    {
        progbug("mprand: arg2 not a number", ch );
        return;
    }

    if ( !is_number(arg3) )
    {
        progbug("mprand: arg3 not a number", ch );
        return;
    }

    num1 = atoi( arg2 );
    num2 = atoi( arg3 );

    result = number_range( num1, num2 );


    sprintf( newtext, "%d", result );
    var = atoi(arg1);
    switch(var)
    {
      default:
       bug( "Unknown setvar %s:%d", arg1, ch->pIndexData->vnum );
       return;
      case 1:
       stralloc_printf( &variable.v1, "%s", newtext);
       break;
      case 2:
       stralloc_printf( &variable.v2, "%s", newtext);
       break;
      case 3:
       stralloc_printf( &variable.v3, "%s", newtext);
       break;
      case 4:
       stralloc_printf( &variable.v4, "%s", newtext);
       break;
      case 5:
       stralloc_printf( &variable.v5, "%s", newtext);
       break;
    }

}


mprand 1 10000 12500
Stores rand num between 10k to 12.5k in $1
       
Pages:<< prev 1 next >>