View Single Post
  #2  
Old 03-13-2013, 02:17 AM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,449
Default

Quote:
Originally Posted by NatedogEZ View Post
Code:
	if ($timer eq "fear")
	{	
		my $hate_target = $npc->GetHateRandom();
		my $hate_name = $hate_target->GetName();
		my $hate_id = $hate_target->GetID();  
		quest::shout("Burn in HELL $hate_name"); 
		$npc->CastSpell(27418, $hate_id);
		undef $hate_target;
	}

The timer is working.. it is correctly casting the spell..

But.. heres the problem



2 Players on Hatelist will only NUKE 1 player never the other...

3 Players on Hatelist will ONLY Nuke 2 of the players .. never the 3rd...

and so on...

Tested with 4 and it only would nuke 3 out of the 4.

Is there something wrong with the GetHateRandom?

Code:
Mob *HateList::GetRandom()
{
    int count = 0;
    LinkedListIterator<tHateEntry*> iterator(list);
    iterator.Reset();
while(iterator.MoreElements())
    {
        iterator.Advance();
        count++;
    }
if(!count)
return NULL;

    int random = MakeRandomInt(0, count-1);
    iterator.Reset();
    for (int i = 0; i < random-1; i++)
        iterator.Advance();
    return iterator.GetData()->ent;
}

the Random seems to be (Count -1)

Then the For loop ... Removes another 1 from Random?

Is this possibly why it always cuts 1 player off the list?
Yes, that's actually why. If there's 6 people in a group, random = 5, 0-5 would be chosen.

Then, it chooses between 0-4 when it does the for loop.

That is precisely why.
Reply With Quote