PDA

View Full Version : Get Hate Random bugged?


NatedogEZ
03-13-2013, 12:42 AM
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?

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?

Secrets
03-13-2013, 02:17 AM
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?

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.

NatedogEZ
03-13-2013, 03:29 AM
this part is what i'm asking secrets


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



I understand it would be 0 to 5 for a 6 man party

But INSIDE the for loop ... it removes another 1!

for (int i = 0; i < random-1; i++)

So for a 6 man party it would be 0 to 4 .. which leaves someone off...

Ive been testing it for awhile.. it never casts on the LAST person to aggro they never get picked by GetHateRandom

lerxst2112
03-13-2013, 07:45 AM
Read what Secrets wrote again. It sounded like a confirmation to me.

Assuming a uniform distribution of random numbers over time, I would assume the next to last person on the list will be picked twice as often as anyone else, and the last person will never be picked.

It's also not very efficient code. No need to walk the list when there's a Count() function that returns the number of elements in the list.

NatedogEZ
03-13-2013, 08:23 AM
Aye ya the last person to be added to the Hatelist never gets picked.


I'd re-write it to be all fancy and nice .. but I am not the best at C++ heh

sorvani
03-13-2013, 02:51 PM
just remove the -1 after the random and it will work, there you don't have to rewrite anything.

NatedogEZ
03-13-2013, 10:34 PM
Well ya I know that.. but he said it "could" be written better... not that I'm actually gonna do it... the simple fix is just removing the -1 lol

NatedogEZ
03-14-2013, 05:44 AM
Updated my source and removed that number and its working nicely now.

If anyone wants to update it on the Github that would be awesome!

lerxst2112
03-14-2013, 06:40 PM
I bet if you made a pull request someone would commit it.