EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Archive::Development (https://www.eqemulator.org/forums/forumdisplay.php?f=621)
-   -   Added code for random numbers in quests =) (https://www.eqemulator.org/forums/showthread.php?t=8186)

used_pawn 06-20-2003 09:34 AM

Added code for random numbers in quests =)
 
Ok, here it is! :worship:

usage is: $random(x)
where x is the upper limit of a random number 0 < n < x

also, put it in quotes when you use it (ie. givecash("random(10)","random(10)","random(5)","ra ndom(5)"

enjoy! 8)

../zone/parser.cpp : line 1456 (or thereabouts) INSERT this
Code:

//used_pawn
        else if (!strcmp(varname,"random")) {
                char temp[10];
                Replace(origstring,format,itoa(rand()%varparms[0],temp,10));
        }
//used_pawn


used_pawn 06-21-2003 08:57 PM

bah, i hadnt updated my cvs lately, try putting it here

../zone/parser.cpp : line 1497

Code:

        else if (!strcmp(varname,"chr")) {
                char temp[4];
                memset(temp, 0x0, 4);
                temp[0] = atoi(varparms);
                Replace(origstring,format,temp);
        }
//used_pawn
        else if (!strcmp(varname,"random")) {
                char temp[10];
                Replace(origstring,format,itoa(rand()%varparms[0],temp,10));
        }
//used_pawn
        else if (!strcmp(varname,"asc")) {
                char temp[10];
                Replace(origstring,format,itoa(varparms[0],temp,10));
        }

Sorry, Im not very good at my postings.

Trumpcard 06-21-2003 09:36 PM

ok.. got it

killspree 06-22-2003 08:49 PM

I've been testing this out and it doesn't seem to use the amount you enter in $random() as the max.

Bigpull 06-23-2003 02:06 AM

are yoou using $random("10") or $random(10) ?

killspree 06-23-2003 05:42 AM

Tried with both, neither work 100% of the time.

And this is with creating a script to where the npc responds with all of the possible numbers in the quest.

Bigpull 06-23-2003 06:16 AM

Bleh

Change:
Replace(origstring,format,itoa(rand()%varparms[0],temp,10));
To:
Replace(origstring,format,itoa(rand()%atoi(varparm s[0]),temp,10));


Should maybe do the trick

used_pawn 06-23-2003 02:44 PM

the number you put in will never be chosen, that is by design.
as I stated 0<n<x where x is the number you put in random(x), easy to put in one number higher than you need, or change it in the code, doesnt really matter to me either way.

I have noticed strange things with quotes on many commands, some use them, some dont, some dont seem to work the same way twice in a row. Wasnt sure if it was things ive done to my code or if everyone had the problem

ah well, these things happen


All times are GMT -4. The time now is 10:05 PM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.