Log in

View Full Version : npc-addloot not working


javewow
12-22-2012, 01:22 AM
it's real difficult. I was messing with it for a half hour and couldn't quite get it to do what I wanted it to do.

my $rands = quest::ChooseRandom(15270,15275,15075,15271,15279, 15212,15079,15274,15272);
my $randa = quest::ChooseRandom(2031,2036,2030,2034,2027,2038, 2026,2029,2025,2032,2028,2033);
my $randw = quest::ChooseRandom(5043,6032,6030,7022,7024,94155 ,6031);

sub EVENT_COMBAT {
my $NPCRace = $npc->GetRace();
if($combat_state == 1)
{
$npc->Heal();
if($NPCRace==54)
{
quest::say("your blood will spill.");

}
else {
quest::say("Time to die $name!");
}
}
}

sub EVENT_DEATH
{
my $rewardr = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10);
if($NPCRace!=54){
if($rewardr < 4)
{
quest::addloot($rands,1);
}
if($rewardr < 7 && $rewardr > 3)
{
quest::addloot($randw,1);
}
if($rewardr < 10 && $rewardar > 6)
{
quest::addloot($randa,1);
}
if($rewardr > 9)
{
quest::addloot($randw,1);
}
}
}

Kill Npc ---npc not loot

Help!!

ghanja
12-22-2012, 01:34 AM
my $rands = quest::ChooseRandom(15270,15275,15075,15271,15279, 15212,15079,15274,15272);
my $randa = quest::ChooseRandom(2031,2036,2030,2034,2027,2038, 2026,2029,2025,2032,2028,2033);
my $randw = quest::ChooseRandom(5043,6032,6030,7022,7024,94155 ,6031);

sub EVENT_COMBAT {
my $NPCRace = $npc->GetRace();
if($combat_state == 1)
{
$npc->Heal();
if($NPCRace==54)
{
quest::say("your blood will spill.");

}
else {
quest::say("Time to die $name!");
}
}
}

sub EVENT_DEATH
{
my $rewardr = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10);
if($NPCRace!=54){
if($rewardr < 4)
{
quest::addloot($rands,1);
}
if($rewardr < 7 && $rewardr > 3)
{
quest::addloot($randw,1);
}
if($rewardr < 10 && $rewardar > 6)
{
quest::addloot($randa,1);
}
if($rewardr > 9)
{
quest::addloot($randw,1);
}
}
}


http://www.perlmonks.org/index.pl?node_id=105446

ghanja
12-22-2012, 01:45 AM
I'd place the rands in an EVENT_SPAWN sub, and I'm not quite sure when EVENT_DEATH is called (from a server source stand point) at the moment (yes, common sense says after the NPC is dead, thus death but...). :)

ghanja
12-22-2012, 02:02 AM
sub EVENT_SPAWN {
my $rands = quest::ChooseRandom(15270,15275,15075,15271,15279, 15212,15079,15274,15272);
my $randa = quest::ChooseRandom(2031,2036,2030,2034,2027,2038, 2026,2029,2025,2032,2028,2033);
my $randw = quest::ChooseRandom(5043,6032,6030,7022,7024,94155 ,6031);
my $rewardr = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10);

if($NPCRace!=54)
{

if($rewardr < 4) {quest::addloot($rands,1);}
if($rewardr < 7 && $rewardr > 3) {quest::addloot($randw,1);}
if($rewardr < 10 && $rewardr > 6) {quest::addloot($randa,1);}
if($rewardr > 9) {quest::addloot($randw,1);}
}
}


Really untested, didn't check your logic (besides the mistype of $rewardar instead of $rewardr in one instance), am on the laptop at the moment..

c0ncrete
12-22-2012, 02:09 AM
yeah, lexical scope is your issue.

add the following to the top of your scripts and run them from a command line to catch things like what you are experiencing.

use warnings;you should be using if/elsif/else in logic chains, not just if. it won't stop looking for matches after the first one is found otherwise.

you can also use the range (..) and smart match (~~) operators to see if a value is in a range of numbers like this:

if($rewardr ~~ [7..9]) {
...;
}

c0ncrete
12-22-2012, 05:04 AM
use List::Util qw(first);

sub EVENT_COMBAT
{
return()unless($combat_state);
$npc->Heal();
quest::say(($npc->GetRace()==54?"Your blood will spill.":"Time to die, $name!"));
}

sub EVENT_DEATH
{
return()if($npc->GetRace()==54);
my($extra_loot)={
join(' ',1..3)=>[15270,15275,15075,15271,15279,15212,15079,15274,15 272],
join(' ',4..6)=>[5043,6032,6030,7022,7024,94155,6031],
join(' ',7..9)=>[2031,2036,2030,2034,2027,2038,2026,2029,2025,2032, 2028,2033]
};
$extra_loot->{'10 10'}=$extra_loot->{join(' ',4..6)};
my($roll)=quest::ChooseRandom(1..10);
quest::addloot(quest::ChooseRandom(@{$extra_loot->{first{$roll~~[split(' ',$_)]}keys(%$extra_loot)}}),1);
}

javewow
12-28-2012, 12:55 AM
Thank youR very much!!!

javewow
01-04-2013, 11:48 PM
use List::Util qw(first);

sub EVENT_COMBAT
{
return()unless($combat_state);
$npc->Heal();
quest::say(($npc->GetRace()==54?"Your blood will spill.":"Time to die, $name!"));
}

sub EVENT_DEATH
{
return()if($npc->GetRace()==54);
my($extra_loot)={
join(' ',1..3)=>[15270,15275,15075,15271,15279,15212,15079,15274,15 272],
join(' ',4..6)=>[5043,6032,6030,7022,7024,94155,6031],
join(' ',7..9)=>[2031,2036,2030,2034,2027,2038,2026,2029,2025,2032, 2028,2033]
};
$extra_loot->{'10 10'}=$extra_loot->{join(' ',4..6)};
my($roll)=quest::ChooseRandom(1..10);
quest::addloot(quest::ChooseRandom(@{$extra_loot->{first{$roll~~[split(' ',$_)]}keys(%$extra_loot)}}),1);
}

you's .pl no working no loot!

ghanja
01-04-2013, 11:58 PM
you's .pl no working no loot!


use warnings;

sub EVENT_SPAWN {
my $rands = quest::ChooseRandom(15270,15275,15075,15271,15279, 15212,15079,15274,15272);
my $randa = quest::ChooseRandom(2031,2036,2030,2034,2027,2038, 2026,2029,2025,2032,2028,2033);
my $randw = quest::ChooseRandom(5043,6032,6030,7022,7024,94155 ,6031);
my $rewardr = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10);

if($NPCRace!=54)
{

if($rewardr < 4) {
quest::addloot($rands,1);
}
elsif($rewardr ~~ [4..6]) {
quest::addloot($randw,1);
}
elsif($rewardr ~~ [7..9]) {
quest::addloot($randa,1);
}
elsif($rewardr > 9)
{quest::addloot($randw,1);
}
}
}

sub EVENT_COMBAT {
my $NPCRace = $npc->GetRace();

if($combat_state == 1) {
$npc->Heal();
}

if($NPCRace==54) {
quest::say("your blood will spill.");
}
else {
quest::say("Time to die $name!");
}
}


sub EVENT_DEATH
{
quest::say("Arrg defeated by a subroutine reversion!");
}


I did not test the above, give it a try, or, try changing:


sub EVENT_DEATH
{


to


sub EVENT_SPAWN
{


To see if it returns more favorable results. Perl therefore quests are indeed working otherwise right?

*edited: excuse the odd code format, copy/pasted from a PM I sent and I see it retained it's odd format once again.. wierd.

javewow
01-05-2013, 12:02 AM
Below for random drop of class----loot

You can add more later in the class ???? HELP

%item = ("Warrior" => 76600,
"Rogue" => 76601,
"Monk" => 76602,
"Berserker" => 76603,
"Shadowknight" => 76604,
"Paladin" => 76605,
"Ranger" => 76607,
"Bard" => 76608,
"Beastlord" => 76609,
"Cleric" => 76610,
"Druid" => 76611,
"Shaman" => 76612,
"Wizard" => 76613,
"Magician" => 76614,
"Enchanter" => 76615,
"Necromancer" => 76616);
sub EVENT_AGGRO {
my $Phrase1 = "Your faithless devotion to a false god leaves me no choice.";
my $Phrase2 = "I shall rid the land of another infamous villain.";
my $Phrase3 = "Your foul deeds have earned my contempt.";
my $Phrase4 = "${class}s like you are better left dead than alive.";
my $Phrase5 = "It's ${race}s like you who have ruined your own lands, You'll not ruin mine!";
my $Phrase6 = "Heathen! Unbeliever! Norrath must be cleansed!";
my $Phrase7 = "Your beliefs are an insult to us all!";
my $Phrase8 = "Your actions and history are a personal affront to all I stand for.";
my $Phrase9 = "Your intolerable reputation insults all in this realm.";
my $Phrase10 = "It's time for you to take your blasphemy into the next realm.";
my $Phrase11 = "${race}s like you are better left dead than alive.";
my $class_item = $item{$class};
my $Phrase = quest::ChooseRandom($Phrase1,$Phrase2,$Phrase3,$Ph rase4,$Phrase5,$Phrase6,$Phrase7,$Phrase8,$Phrase9 ,$Phrase10,$Phrase11);
quest::say("Rrrrrrrrooooaaakkk!");
my $Chance = quest::ChooseRandom(1,2,3,4);
if ($Chance == '1') {
quest::say("$Phrase");
quest::addloot($class_item,1);
}
}
--------------------------------------------------------

%item = ("Warrior" => 76600, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Rogue" => 76601, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Monk" => 76602, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Berserker" => 76603, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Shadowknight" => 76604, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Paladin" => 76605, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Ranger" => 76607, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Bard" => 76608, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Beastlord" => 76609, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Cleric" => 76610, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Druid" => 76611, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Shaman" => 76612, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Wizard" => 76613, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Magician" => 76614, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Enchanter" => 76615, XXXX, XXXXX, XXXXXX, XXXX, XXXX,
"Necromancer" => 76616),XXXX, XXXXX, XXXXXX, XXXX, XXXX, ;
sub EVENT_AGGRO {
my $Phrase1 = "Your faithless devotion to a false god leaves me no choice.";
my $Phrase2 = "I shall rid the land of another infamous villain.";
my $Phrase3 = "Your foul deeds have earned my contempt.";
my $Phrase4 = "${class}s like you are better left dead than alive.";
my $Phrase5 = "It's ${race}s like you who have ruined your own lands, You'll not ruin mine!";
my $Phrase6 = "Heathen! Unbeliever! Norrath must be cleansed!";
my $Phrase7 = "Your beliefs are an insult to us all!";
my $Phrase8 = "Your actions and history are a personal affront to all I stand for.";
my $Phrase9 = "Your intolerable reputation insults all in this realm.";
my $Phrase10 = "It's time for you to take your blasphemy into the next realm.";
my $Phrase11 = "${race}s like you are better left dead than alive.";
my $class_item = $item{$class};
my $Phrase = quest::ChooseRandom($Phrase1,$Phrase2,$Phrase3,$Ph rase4,$Phrase5,$Phrase6,$Phrase7,$Phrase8,$Phrase9 ,$Phrase10,$Phrase11);
quest::say("Rrrrrrrrooooaaakkk!");
my $Chance = quest::ChooseRandom(1,2,3,4);
if ($Chance == '1') {
quest::say("$Phrase");
quest::addloot($class_item,1);
}
}

ghanja
01-05-2013, 12:09 AM
Edit that post and use the code blocks please. I left my ANSI terminal back in 1990. <grin>

javewow
01-05-2013, 12:36 AM
Edit that post and use the code blocks please. I left my ANSI terminal back in 1990. <grin>

Please!
Help!
breakdown method! pleas

c0ncrete
01-05-2013, 12:37 AM
you's .pl no working no loot!

sorry, it is quite possible that's because i changed when the events are run in my source. previously, they were fired off after the corpse was created and the npc in question was removed from the entity list, if i remember correctly. i moved the block that runs the events up to right before those things occur in my source.

you could also change it to where the loot is added in EVENT_COMBAT (where $combat_state is 1). then you could save the itemID that is added in an EntityVariable for that npc, then remove the item it in EVENT_COMBAT (where $combat_state is 0).

c0ncrete
01-05-2013, 12:39 AM
Please!
Help!
breakdown method! pleas

indent your scripts and post them inside of CODE tags (it's the # symbol) in the message toolbar.

lerxst2112
01-05-2013, 01:40 AM
Well, for sure, all the XXX aren't gonna work.

javewow
01-05-2013, 04:54 AM
Well, for sure, all the XXX aren't gonna work.

yes ! I Iwant back plus Items,


For example:

69800,69801,69802,69803,69804......


is ok?

lerxst2112
01-05-2013, 05:33 AM
I'm afraid I don't understand what you want the script to do. The original thread was about adding random loot to a mob. I'm not sure what the classes have to do with that.

c0ncrete
01-05-2013, 06:13 AM
are you trying to add random loot to the npc based on the class(es) of the character(s) involved in the encounter?