PDA

View Full Version : Chance to spawn NPC on another NPC's death


lordnivek1
10-03-2016, 03:42 PM
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.


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)
{
}

Uleat
10-03-2016, 03:47 PM
Just remember that if you open something, you must close it - correctly.



( ... )
[ ... ]
{ ... }

ghanja
10-03-2016, 03:55 PM
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);
}
}



perl -c checkcode.pl

atrayas
10-03-2016, 04:40 PM
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.

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");

}

lordnivek1
10-03-2016, 05:37 PM
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);
}
}



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)?

ghanja
10-03-2016, 05:41 PM
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:


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


to


if(quest::ChooseRandom(0..4) == 0) {


as the prior is 3:1 odds, or 25% chance.

Fridgecritter
12-27-2016, 12:25 PM
This snippet goes in the particular NPC's quest file, correct?

Jorin
10-11-2018, 06:50 PM
If I wanted this to apply to all mobs I would just stick it in my Global.pl right?