|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quests::Custom Custom Quests here |
10-03-2016, 03:42 PM
|
Sarnak
|
|
Join Date: Feb 2013
Posts: 65
|
|
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)
{
}
|
10-03-2016, 03:47 PM
|
|
Developer
|
|
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
|
|
Just remember that if you open something, you must close it - correctly.
Code:
( ... )
[ ... ]
{ ... }
__________________
Uleat of Bertoxxulous
Compilin' Dirty
|
10-03-2016, 03:55 PM
|
|
Dragon
|
|
Join Date: Aug 2012
Location: Hershey, PA
Posts: 499
|
|
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
|
10-03-2016, 04:40 PM
|
Hill Giant
|
|
Join Date: Jun 2010
Posts: 105
|
|
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");
}
|
10-03-2016, 05:37 PM
|
Sarnak
|
|
Join Date: Feb 2013
Posts: 65
|
|
Quote:
Originally Posted by ghanja
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)?
|
10-03-2016, 05:41 PM
|
|
Dragon
|
|
Join Date: Aug 2012
Location: Hershey, PA
Posts: 499
|
|
Quote:
Originally Posted by lordnivek1
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.
|
12-27-2016, 12:25 PM
|
Hill Giant
|
|
Join Date: Feb 2008
Posts: 189
|
|
This snippet goes in the particular NPC's quest file, correct?
|
10-11-2018, 06:50 PM
|
Sarnak
|
|
Join Date: Aug 2018
Posts: 48
|
|
If I wanted this to apply to all mobs I would just stick it in my Global.pl right?
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 04:17 PM.
|
|
|
|
|
|
|
|
|
|
|
|
|