Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

Reply
 
Thread Tools Display Modes
  #1  
Old 03-13-2013, 12:42 AM
NatedogEZ's Avatar
NatedogEZ
Developer
 
Join Date: Dec 2012
Posts: 515
Default Get Hate Random bugged?

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?
Reply With Quote
  #2  
Old 03-13-2013, 02:17 AM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,450
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
  #3  
Old 03-13-2013, 03:29 AM
NatedogEZ's Avatar
NatedogEZ
Developer
 
Join Date: Dec 2012
Posts: 515
Default

this part is what i'm asking secrets


Code:
    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!

Code:
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
Reply With Quote
  #4  
Old 03-13-2013, 07:45 AM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,743
Default

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.
Reply With Quote
  #5  
Old 03-13-2013, 08:23 AM
NatedogEZ's Avatar
NatedogEZ
Developer
 
Join Date: Dec 2012
Posts: 515
Default

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
Reply With Quote
  #6  
Old 03-13-2013, 02:51 PM
sorvani
Dragon
 
Join Date: May 2010
Posts: 966
Default

just remove the -1 after the random and it will work, there you don't have to rewrite anything.
Reply With Quote
  #7  
Old 03-13-2013, 10:34 PM
NatedogEZ's Avatar
NatedogEZ
Developer
 
Join Date: Dec 2012
Posts: 515
Default

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
Reply With Quote
  #8  
Old 03-14-2013, 05:44 AM
NatedogEZ's Avatar
NatedogEZ
Developer
 
Join Date: Dec 2012
Posts: 515
Default

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!
Reply With Quote
  #9  
Old 03-14-2013, 06:40 PM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,743
Default

I bet if you made a pull request someone would commit it.
Reply With Quote
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 04:07 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3