View Single Post
  #7  
Old 01-14-2008, 10:19 AM
AndMetal
Developer
 
Join Date: Mar 2007
Location: Ohio
Posts: 648
Default

I think this might be a misunderstanding of the original source.

To start, the headers for the commands are located in the utils/perlxs directory and the actual source for the commands is in the zone directory. If you search through all of the header files (*.h), SetCash() is defined in PlayerCorpse.h:
Code:
SetCash(int16 in_copper, int16 in_silver, int16 in_gold, int16 in_platinum);
So, it looks like the resource should read "Player Corpse" instead of "Corpse". This can be seen in action using this example:
Code:
sub EVENT_SAY {
	if($text=~/Hail/i) {
		my $cash = int(rand(300)+100);
		my $copperstart = $npc->GetCopper();
		quest::say("Right now, I have $copperstart copper");
		quest::say("Giving myself $cash copper.");
		$npc->SetCash($cash,0,0,0);
		my $copperend = $npc->GetCopper();
		quest::say("According to GetCopper, I have $copperend copper.");
	}
}
The quest stops executing at $npc->SetCash:
Quote:
You say, 'Hail, Copper Dropper
Copper Dropper says, 'Right now, I have 0 copper'
Copper Dropper says 'Giving myself 391 copper.'
So now, we probably want to look at mob.h or npc.h. It looks like mob.h definitions concentrate on NPCs that are aggroed, so I'll focus on npc.h. Here are a few excerpts:
Code:
AddCash(int16 in_copper, int16 in_silver, int16 in_gold, int16 in_platinum);
GetCopper()		{ return copper; }
SetCopper(uint32 amt)		{ copper = amt; }
So, if I just change SetCash to AddCash, the script excecutes like normal:
Quote:
You say, 'Hail, Copper Dropper
Copper Dropper says, 'Right now, I have 0 copper'
Copper Dropper says 'Giving mysqlf 246 copper.'
Copper Dropper says 'According to GetCopper, I have 246 copper.'
Auto attack is on.
You crush Copper Dropper for 7726 points of damage.
You have slain Copper Dropper!
You receive 246 copper from the corpse.
So now that the NPC is actually getting the copper, let's see how it will work when we change it to excecute on death:
Code:
sub EVENT_DEATH {
	my $cash = int(rand(300)+100);
	my $copperstart = $npc->GetCopper();
	quest::say("Right now, I have $copperstart copper");
	quest::say("Giving myself $cash copper.");
	$npc->AddCash($cash,0,0,0);
	my $copperend = $npc->GetCopper();
	quest::say("According to GetCopper, I have $copperend copper.");
}
Quote:
Auto attack is on.
You crush Copper Dropper for 2528 points of damage.
You have slain Copper Dropper!
Copper Dropper says 'Right now, I have 0 copper'
Copper Dropper says 'Giving mysqlf 271 copper.'
Copper Dropper says 'According to GetCopper, I have 271 copper.'
However, upon looting, there is no copper on the corpse.

In conclusion, if you change SetCash to AddCash, it will work IF you add it while the NPC is still alive. EVENT_SPAWN is probably the best place for it, so this is the code you should use:
Code:
sub EVENT_SPAWN {
	$npc->AddCash(int(rand(300)+100),0,0,0);
}
__________________
GM-Impossible of 'A work in progress'
A non-legit PEQ DB server
How to create your own non-legit server

My Contributions to the Wiki
Reply With Quote