Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Custom

Quests::Custom Custom Quests here

Reply
 
Thread Tools Display Modes
  #1  
Old 10-03-2016, 03:42 PM
lordnivek1
Sarnak
 
Join Date: Feb 2013
Posts: 65
Default Chance to spawn NPC on another NPC's death

So I am teaching myself how to code perl. I have zero background in any coding at all. Was wondering if someone could take a look at this and tell me how this looks. The bases is there is a 20% chance when a mob dies that another mob will spawn at its location. The mob that spawns will be 1 of 3 different possibilities.

Code:
 
sub EVENT_DEATH_COMPLETE 
{
    my $random = int(rand 4);
    if($random == 0);
    {
    my @npc_type_id = ('123', '124', '125')
    my $random = int(rand 2);
    my $npc = $npc_type_id[$random];
        quest::say("I am free of this mortal cell! Prepare for my wrath!")
	quest::spawn($npc, 0, 0, $x, $y, $Z, $H)
    {
}
Reply With Quote
  #2  
Old 10-03-2016, 03:47 PM
Uleat's Avatar
Uleat
Developer
 
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
Default

Just remember that if you open something, you must close it - correctly.


Code:
( ... )
[ ... ]
{ ... }
__________________
Uleat of Bertoxxulous

Compilin' Dirty
Reply With Quote
  #3  
Old 10-03-2016, 03:55 PM
ghanja's Avatar
ghanja
Dragon
 
Join Date: Aug 2012
Location: Hershey, PA
Posts: 499
Default

Code:
sub EVENT_DEATH_COMPLETE {
	if(quest::ChooseRandom(0..3) == 0) {
		quest::say("I am free of this mortal cell! Prepare for my wrath!");
		quest::spawn(quest::ChooseRandom(123..125), 0, 0, $x, $y, $z);
	}
}
Code:
perl -c checkcode.pl
Reply With Quote
  #4  
Old 10-03-2016, 04:40 PM
atrayas
Hill Giant
 
Join Date: Jun 2010
Posts: 105
Default

Something simple yet effective here, seems like you wanted a percent chance for it to spawn, this would do the trick. In this version its just a basic percent chance a mob splits into two.

Code:
sub GET_RANDOM_NUMBER
{
    $minimum = 1;
    $maximum = 101;
   
    $rnd_number = $minimum + int(rand($maximum - $minimum));
 
    return $rnd_number;
}

sub EVENT_DEATH_COMPLETE
{
    my $randomized = GET_RANDOM_NUMBER();
 
    if($randomized <= 90)#90 out of 100
    {
        quest::spawn2(2990,0,0,$x,$y,$z,$y);
	quest::spawn2(2990,0,0,$x,$y,$z,$y);
    }
	quest::stoptimer("silence");
    
}
Reply With Quote
  #5  
Old 10-03-2016, 05:37 PM
lordnivek1
Sarnak
 
Join Date: Feb 2013
Posts: 65
Default

Quote:
Originally Posted by ghanja View Post
Code:
sub EVENT_DEATH_COMPLETE {
	if(quest::ChooseRandom(0..3) == 0) {
		quest::say("I am free of this mortal cell! Prepare for my wrath!");
		quest::spawn(quest::ChooseRandom(123..125), 0, 0, $x, $y, $z);
	}
}
Code:
perl -c checkcode.pl
Thank your for all the feed back and info from everyone. Being able to condense that down to three lines showed me some new stuff. the ChooseRandom I hadn't seen before. Could you use that to pick between numbers that are not X..X but instead a list of numbers. Like if i did ChooseRandom(123, 125, 1001, 2005)? Or even have both ChooseRandom(123, 125, 1001..2005)?
Reply With Quote
  #6  
Old 10-03-2016, 05:41 PM
ghanja's Avatar
ghanja
Dragon
 
Join Date: Aug 2012
Location: Hershey, PA
Posts: 499
Default

Quote:
Originally Posted by lordnivek1 View Post
Thank your for all the feed back and info from everyone. Being able to condense that down to three lines showed me some new stuff. the ChooseRandom I hadn't seen before. Could you use that to pick between numbers that are not X..X but instead a list of numbers. Like if i did ChooseRandom(123, 125, 1001, 2005)? Or even have both ChooseRandom(123, 125, 1001..2005)?
Yes.

Also, having read atrayas post just now, I see I missed you stated you wanted a 20% chance (4:1 odds), thus change:

Code:
if(quest::ChooseRandom(0..3) == 0) {
to

Code:
if(quest::ChooseRandom(0..4) == 0) {
as the prior is 3:1 odds, or 25% chance.
Reply With Quote
  #7  
Old 12-27-2016, 12:25 PM
Fridgecritter
Hill Giant
 
Join Date: Feb 2008
Posts: 189
Default

This snippet goes in the particular NPC's quest file, correct?
Reply With Quote
  #8  
Old 10-11-2018, 06:50 PM
Jorin
Sarnak
 
Join Date: Aug 2018
Posts: 48
Default

If I wanted this to apply to all mobs I would just stick it in my Global.pl right?
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 06:44 AM.


 

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