How Random is random.#?

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
7 years 10 months ago - 7 years 10 months ago #4538 by Krell
How Random is random.#? was created by Krell
I've been working on a MOB trigger on my local copy of the MUD as follows:

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.

* 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: 7 years 10 months ago by Krell. Reason: The entire trigger wasn't neccessary.

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
7 years 10 months ago #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.

      * 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
7 years 10 months ago #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
This email address is being protected from spambots. You need JavaScript enabled to view it.

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
7 years 10 months ago - 7 years 10 months ago #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%.

    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: 7 years 10 months ago by Krell. Reason: slight improvement in my posted script

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago - 6 years 3 months ago #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. :-/
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: 6 years 3 months ago by Krell. Reason: Changing Title of Post

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

Time to create page: 0.088 seconds