Here is a script I did last night:
NPC Code:
// NPC made by Boco
if (created || playerenters) {
setimgpart bravo_riverpan.gif,0,0,32,32;
}
if (playertouchsme) {
toweapons River Pan;
setimgpart bravo_riverpan.gif,0,0,32,32;
}
if (weaponfired) {
this.testx=int(playerx+1.5+(vecx(playerdir)*2));
this.testy=int(playery+2.5+(vecy(playerdir)*2));
if (board[this.testx+this.testy*64]==322) {
PanRiver();
} else {
setplayerprop #c,On WATER!;
}
}
function PanRiver() {
if (strtofloat(#s(client.Mineral))<strtofloat(#s(clie nt.MineralCount))) {
freezeplayer 0.3;
setani bravo_riverpan,;
sleep 0.3;
this.MineralTest=random(0,1);
if (this.MineralTest<=0.05) { this.MineralType=1; break; }
else if (this.MineralTest<=0.2) { this.MineralType=2; break; }
else if (this.MineralTest<=0.4) { this.MineralType=3; break; }
else { this.MineralType=0; }
if (this.MineralType==1) { GotGold(); }
else if (this.MineralType==2) { GotIron(); }
else if (this.MineralType==3) { GotBrass(); }
else if (this.MineralType==0) { setplayerprop #c,Something screwy...; }
if (strtofloat(#s(client.Mineral))>strtofloat(#s(clie nt.MineralCount))) { setstring client.Mineral,#s(client.MineralCount); }
} else {
setplayerprop #c,Bag full;
}
}
function GotGold() {
this.nuggets=int(random(1,2));
this.Nnuggets=strtofloat(#s(client.Mineral))+this. nuggets;
this.GNnuggets=strtofloat(#s(client.Mineral_Gold)) +this.nuggets;
setstring client.Mineral_Gold,#v(this.GNnuggets);
setstring client.Mineral,#v(this.Nnuggets);
say2 You got #v(this.nuggets) nuggets#bof Gold! You have #s(client.Mineral_Gold) gold nuggets#btotal.;
}
function GotIron() {
this.nuggets=int(random(1,2));
this.Nnuggets=strtofloat(#s(client.Mineral))+this. nuggets;
this.GNnuggets=strtofloat(#s(client.Mineral_Iron)) +this.nuggets;
setstring client.Mineral_Iron,#v(this.GNnuggets);
setstring client.Mineral,#v(this.Nnuggets);
say2 You got #v(this.nuggets) nuggets#bof Iron! You have #s(client.Mineral_Iron) iron nuggets#btotal.;
}
function GotBrass() {
this.nuggets=int(random(1,2));
this.Nnuggets=strtofloat(#s(client.Mineral))+this. nuggets;
this.GNnuggets=strtofloat(#s(client.Mineral_Brass) )+this.nuggets;
setstring client.Mineral_Brass,#v(this.GNnuggets);
setstring client.Mineral,#v(this.Nnuggets);
say2
You got #v(this.nuggets) nuggets#bof Brass! You have #s(client.Mineral_Brass) brass nuggets#btotal.;
}
The problem is that GotGold, GotIron, or the GotBrass functions won't call. At first I thought that the variable this.MineralType wasn't returning values correctly, but 'else if (this.MineralType==0) { setplayerprop #c,Something screwy...; }' proved otherwise, because my player would say "Something screwy..." whenever this.MineralType was equal to 0. I am confused. If you want to try this script out on your own, this is the NPC for the mineral sack:
NPC Code:
// NPC made by Boco
if (playertouchsme) {
say2
You got a bag;
setstring client.MineralCount,5;
setstring client.Mineral,0;
}