Welcome to the Builder Academy

Question How Random is random.#?

More
29 Nov 2013 04:23 - 29 Nov 2013 07:25 #4538 by krell
I've been working on a MOB trigger on my local copy of the MUD as follows:

Code:
Name: 'Windmill Technician - Atmosphere Z600', VNum: [60008], RNum: [ 1441] Trigger Intended Assignment: Mobiles Trigger Type: Random , Numeric Arg: 50, Arg list: None Commands: * * Windmill Technician - Atmosphere * Krell - Clockwerx z600 * context %self.id% set short 1 set long 5 set v_long 10 if !%actor.varexists(windmill_quest_z600)% || !%quest_busy_z600% switch %random.6% . . . case 3 * Get the ID of the room the MOB is in. set room_id %self.room% * Get the ID of present PCs as seen by the MOB. set next_char %room_id.people% set count 0 * Count the number of people in the room. The MOB will count * itself last. while %next_char% set tmp_char %next_char.next_in_room% * now STUFF all of the people into a list, 1 to n! eval count %count% + 1 set victim[%count%] %next_char% set next_char %tmp_char% done * Decrement the count by 1 so MOB doesn't talk/act toward itself. eval count %count% - 1 * Randomly pick a PC to torment. random.%count% eval do_vict %%victim[%count%]%% %send% %do_vict% %self.name% glares at your intrusion. %echoaround% %do_vict% %self.name% glares at %do_vict.name%. wait %short% s say You'd better not be involved with those trouble makers who've been lurking around here. break . . . done end

My question revolves around this particular snip.

Code:
* Randomly pick a PC to torment. random.%count% eval do_vict %%victim[%count%]%% %send% %do_vict% %self.name% glares at your intrusion. %echoaround% %do_vict% %self.name% glares at %do_vict.name%. wait %short% s say You'd better not be involved with those trouble makers who've been lurking around here.

It seems to solely pick the first character in the list. I've only tested it so far with two PCs in the same room at the same time. I was under the impression that random.# tried to be as truly random as possible,but this doesn't seem to bear that out.

Can anybody comment to clear this matter up for me, or test it? Perhaps I've fixed the result of random.# in some way?

Thanks in advance.
Last edit: 29 Nov 2013 07:25 by krell. Reason: The entire trigger wasn't neccessary.

Please Log in or Create an account to join the conversation.

More
29 Nov 2013 07:09 #4539 by krell
Replied by krell on topic How Random is random.#?
I think I figured it out. Altered script, observe the new variable num.

Code:
* Randomly pick a PC to torment. eval num %%random.%count%%% eval do_vict %%victim[%num%]%% %send% %do_vict% %self.name% glares at your intrusion. %echoaround% %do_vict% %self.name% glares at %do_vict.name%. wait %short% s say You'd better not be involved with those trouble makers who've been lurking around here.

Newbie mistake! *sigh*

Thanks all the same.

Please Log in or Create an account to join the conversation.

More
29 Nov 2013 22:00 #4541 by Rumble
Replied by Rumble on topic How Random is random.#?
Nice trigger, thanks for posting your own solution to help others.

Rumble
The Builder Academy
tbamud.com 9091
rumble@tbamud.com

Please Log in or Create an account to join the conversation.

More
02 Dec 2013 05:29 - 02 Dec 2013 05:42 #4550 by krell
Replied by krell on topic How Random is random.#?
Thanks Rumble, but I was poking around in src/dg_variables.c and I ran across %findmob%. I posted a possible alternative then realized I made another newbie mistake. Here's the working alternative using %findmob%.

Code:
case 3 * Get the VNUM of the room the MOB is in. set room_vnum %self.room.vnum% * Get the ID of present PCs as seen by the MOB. set next_char %room_vnum.people% * Count the number of people in the room. eval count %%findmob.%room_vnum%(-1)%% set num 0 while %next_char% set tmp_char %next_char.next_in_room% * now STUFF all of the people into a list, 1 to n! eval num %num% + 1 set victim[%num%] %next_char% set next_char %tmp_char% done * Randomly pick a PC to torment. eval count %%random.%count%%% eval do_vict %%victim[%count%]%% %send% %do_vict% %self.name% glares at your intrusion. %echoaround% %do_vict% %self.name% glares at %do_vict.name%. wait %short% s say You'd better not be involved with those trouble makers who've been lurking around here. break

It only reduces the number of lines in the script by one and there are still four eval statements. For a moment, in my previous attempt at an alternative solution, I thought maybe I could get rid of my dynamic list but it almost seems necessary to have it.

It's amazing what you can learn rooting around the source code though.
Last edit: 02 Dec 2013 05:42 by krell. Reason: slight improvement in my posted script

Please Log in or Create an account to join the conversation.

More
07 Jul 2015 05:00 - 07 Jul 2015 12:16 #5414 by krell
I should probably include my latest improvement in script, latest being over a year ago. Apparently I didn't post it like I thought I had. :-/
Code:
Name: 'Windmill Technician - Atmosphere Z600', VNum: [60008], RNum: [ 1453] Trigger Intended Assignment: Mobiles Trigger Type: Random , Numeric Arg: 25, Arg list: None Commands: * * Windmill Technician - Atmosphere * Krell - Clockwerx z600 * context %self.id% set short 1 set long 5 set v_long 10 * Get the VNUM of the room the MOB is in. set room_vnum %self.room.vnum% * Get the ID of present PCs as seen by the MOB. set next_char %room_vnum.people% if !%actor.varexists(windmill_quest_z600)% || !%quest_busy_z600% switch %random.6% . . break case 3 * Removed %findmob.<vnum>()% from script. * 1) Extraneous and unneeded. * 2) Depends on MOB counting itself last. Not guaranteed! * * Point 2 for findmob is similar to subtracting 1 from the * count. Depends on MOB counting itself last. set num 0 while %next_char% set tmp_char %next_char.next_in_room% * Count the number of people in the room. eval num %num% + 1 * now STUFF all of the people into a list, 1 to n! set victim[%num%] %next_char% set next_char %tmp_char% done * Randomly pick a PC to torment. eval num %%random.%num%%% eval do_vict %%victim[%num%]%% if %do_vict% != }%self.id% && %do_vict.pos% != sleeping %send% %do_vict% %self.name% glares at your intrusion. end set next_char %room_vnum.people% set tmp_char while %next_char% if %do_vict% != }%self.id% && %next_char% != }%self.id% && %next_char% != %do_vict% && %next_char.pos% != sleeping %send% %next_char% %self.name% glares at %do_vict.name%. end set tmp_char %next_char.next_in_room% set next_char %tmp_char% done wait %short% s if %do_vict% != }%self.id% && %next_char% != }%self.id% && %next_char% != %do_vict% say You'd better not be involved with those trouble makers who've been lurking around here. end break case 4
Last edit: 07 Jul 2015 12:16 by krell. Reason: Changing Title of Post

Please Log in or Create an account to join the conversation.

Time to create page: 0.186 seconds