Raised This Month: $ Target: $400
 0% 

Mother Zombie selection not random


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jargon
SourceMod Donor
Join Date: Jun 2012
Location: Sydney, Australia
Old 07-11-2014 , 20:45   Mother Zombie selection not random
Reply With Quote #1

Hi Richard,

I've been noticing this for awhile and it's probably a near constant complaint from players. The same player or in cases with multiple MZ's, players, are selected for multiple successive rounds as MZ.

MZ selection should be random, I've seen the SMLIB math stock in the sourcecode, but something is off somewhere. I've had this running on Windows and Linux servers now so it seems independant of that, does anyone else have similar issues?
Jargon is offline
veli
Senior Member
Join Date: Apr 2012
Location: Netherlands
Old 07-12-2014 , 00:46   Re: Mother Zombie selection not random
Reply With Quote #2

I have same issue too. Sometimes one person more than 3 times motherzombie in one map.
veli is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 07-12-2014 , 09:04   Re: Mother Zombie selection not random
Reply With Quote #3

Not to be rude, but that is random. People often make the mistake and expect a random number sequence to be a different number each time, but it's certainly possible to get the same number several times in a row (otherwise it's not random, it's removed on purpose). The pseudorandom generator could be bad too of course. We've already moved away from the one in HL2.

To prevent this, ZR give players immunity from mother zombie infection if they were selected. It's only for one round so it's still possible to become mother zombie every odd round (especially if there are few players on the server).

In addition I discovered that ZR ignores immunity when it's passing on mother zombie infection if the last zombie disconnects. I'm not sure whether it's a good idea or not. At least it could be a config setting.

I actually have a thread for discussing a solution to this issue, where you would get immunity for several rounds: https://forums.alliedmods.net/showthread.php?t=180188

I'm trying to make something that performs well and is scalable, but for use in ZR it should be good enough since it's less than 64 elements. Note that my idea in that thread has an issue. There's a group of players that will never be selected in the beginning of the list. It could be simplified by just getting a random player instead of adding at the end.

Edit:
Made a O(1) solution for removing a certain element from an array that should be portable to SourcePawn. My old idea mentioned above did rely on the position in the array to avoid array shifting, but now we don't need to worry about that:

Java snippet:
PHP Code:
/**
 * <p>Removes and returns an element from a list in a O(1) operation.</p>
 * 
 * <p>The last element is moved to replace the element at the specified
 * index, space so elements after the index doesn't need to be shifted
 * up.</p>
 * 
 * @param list Source list to remove element from.
 * @param index Index of element to remove.
 * @return Element at the specified index.
 * @throws IndexOutOfBoundsException List is empty or index is invalid.
 */
public static <EE removeFromListWithoutShifting(List<E> list, int index)
{
    if (list.
isEmpty())
    {
        throw new 
IndexOutOfBoundsException("List is empty.");
    }
    
    
int lastElementIndex = list.size() - 1;
    
    
E elementAtIndex = list.get(index);
    
E lastElement = list.get(lastElementIndex);
    
    list.
set(indexlastElement);
    list.
remove(lastElementIndex);
    
    return 
elementAtIndex;

This snippet can be used to remove a random element from a list in a O(1) operation, which is just what we need. New players that are no longer immune to infection are just added at the end of the list. It doesn't matter where in the list they're added.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)

Last edited by rhelgeby; 07-12-2014 at 10:16.
rhelgeby is offline
Send a message via MSN to rhelgeby
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:43.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode