NWN Fishing !
Posted: Sat Aug 09, 2003 11:00 am
I use the script in my own PW aswell, just so you know. Here's the debugged script, it left floating rods around the place when people clicked quick enough. Also, I added two parts of code for a conversation, one should be put in an event where the player sells his fish, the other should be put in an event where the player has his current number of fish counted.
Just put the Fishing Bait and the Rod in the shop.
Good luck !
Needed Items
"Fishing Bait" - Best is to make it look like a scroll (Misc small has something that looks like it), do give it additional value... 2 Gp is a balanced price for one piece of bait.
"Rod" - Doesn't really matter, it won't show up. Mind the magical properties and the price of it; I use around 200 Gp for one Rod
Needed Placables
"Fishing Rod" - Appearance "Spear"
"Bait" - Appearance "Scroll"
"Fishing Spot" - Appearance "Invisible Object"
Main code, should be placed in OnUse of the Fishing Spot
Count number of fishes on a player object. Used in conversations.
Sell all fishes on a player object. Used in conversations
Just put the Fishing Bait and the Rod in the shop.
Good luck !
Needed Items
"Fishing Bait" - Best is to make it look like a scroll (Misc small has something that looks like it), do give it additional value... 2 Gp is a balanced price for one piece of bait.
"Rod" - Doesn't really matter, it won't show up. Mind the magical properties and the price of it; I use around 200 Gp for one Rod
Needed Placables
"Fishing Rod" - Appearance "Spear"
"Bait" - Appearance "Scroll"
"Fishing Spot" - Appearance "Invisible Object"
Main code, should be placed in OnUse of the Fishing Spot
Code: Select all
/*
August 09, 2003 - Eric Ettes - Raiko - zeiren@hotmail.com
This script handles the fishing routines and cleans temporary objects
Do not modify.
*/
#include "nw_i0_plot"
location GetLocationInFrontOf(object oPC, float fDist, float fHeight){
float fDistance = fDist;
object oTarget = (oPC);
object oArea = GetArea(oTarget);
vector vPosition = GetPosition(oTarget);
vPosition.z += fHeight;
float fOrientation = GetFacing(oTarget);
vector vNewPos = AngleToVector(fOrientation);
float vZ = vPosition.z;
float vX = vPosition.x - fDistance * vNewPos.x;
float vY = vPosition.y - fDistance * vNewPos.y;
fOrientation = GetFacing(oTarget);
vX = vPosition.x - fDistance * vNewPos.x;
vY = vPosition.y - fDistance * vNewPos.y;
vNewPos = AngleToVector(fOrientation);
vZ = vPosition.z;
vNewPos = Vector(vX, vY, vZ);
return Location(oArea, vNewPos, fOrientation);
}
void TakeBait(object oPlayer){
object oItem = GetFirstItemInInventory(oPlayer);
int Count = 0;
while(GetIsObjectValid(oItem) == TRUE && Count < 1){
if(GetTag(oItem) == "FishingBait"){
DestroyObject(oItem);
Count++;
}
oItem = GetNextItemInInventory(oPlayer);
}
}
float Height(object oActivator){
float fHeight = 1.7;
if (GetGender(oActivator) == GENDER_MALE){
switch (GetRacialType(oActivator)){
case RACIAL_TYPE_HUMAN : fHeight = 1.3; break;
case RACIAL_TYPE_HALFELF : fHeight = 1.3; break;
case RACIAL_TYPE_ELF : fHeight = 1.15; break;
case RACIAL_TYPE_GNOME : fHeight = 0.85; break;
case RACIAL_TYPE_HALFLING : fHeight = 0.85; break;
case RACIAL_TYPE_DWARF : fHeight = 0.8; break;
case RACIAL_TYPE_HALFORC: fHeight = 1.5; break;
}
}
else{
switch (GetRacialType(oActivator)){
case RACIAL_TYPE_HUMAN : fHeight = 1.2; break;
case RACIAL_TYPE_HALFELF : fHeight = 1.2; break;
case RACIAL_TYPE_ELF: fHeight = 1.05; break;
case RACIAL_TYPE_GNOME: fHeight = 0.7; break;
case RACIAL_TYPE_HALFLING: fHeight = 0.7; break;
case RACIAL_TYPE_DWARF: fHeight = 0.8; break;
case RACIAL_TYPE_HALFORC: fHeight = 1.4; break;
}
}
return fHeight;
}
void Catch(float fDelay, object oActivator, string sFish, int iFishPower){
DelayCommand(fDelay, SendMessageToPC(oActivator, "A fish nibbles on the bait, it seems to be a " + sFish + " !"));
if(d20() + iFishPower <= GetAbilityScore(oActivator, ABILITY_STRENGTH)){
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "...You caught one " + sFish + " !"));
SetLocalInt(oActivator, sFish, GetLocalInt(oActivator, sFish) + 1);
return;
}
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "...But it escaped"));
}
void StartFishing(object oActivator, string sRodTag, string sBaitTag){
object oRod = GetObjectByTag(sRodTag);
object oBait = GetObjectByTag(sBaitTag);
int iTime = 0;
int iTimeout = 5;
float fDelay = 4.0;
DestroyObject(oBait, 4.0);
DestroyObject(oRod, 8.0);
switch(Random(39)){
case 0 : DelayCommand(fDelay, SendMessageToPC(oActivator, "The bait seems to be stuck in something..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "You caught an old boot.")); break;
case 1 : DelayCommand(fDelay, SendMessageToPC(oActivator, "The bait moves along with the waves..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
case 2 : DelayCommand(fDelay, SendMessageToPC(oActivator, "The bait twitches..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
case 3 : DelayCommand(fDelay, SendMessageToPC(oActivator, "The bait doesn't move..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
case 4 : DelayCommand(fDelay, SendMessageToPC(oActivator, "A small sized fish passes the bait..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
case 5 : DelayCommand(fDelay, SendMessageToPC(oActivator, "A medium sized fish passes the bait..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
case 6 : DelayCommand(fDelay, SendMessageToPC(oActivator, "A large sized fish passes the bait..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
case 7 : Catch(fDelay, oActivator, "Trout", 0); break;
case 8 : Catch(fDelay, oActivator, "Salmon", 8); break;
case 9 : Catch(fDelay, oActivator, "Tuna", 12); break;
case 10 : Catch(fDelay, oActivator, "Herring", 4); break;
case 11 : Catch(fDelay, oActivator, "Snapper", 4); break;
case 12 : Catch(fDelay, oActivator, "Eel", 12); break;
case 13 : Catch(fDelay, oActivator, "Amberjack", 8); break;
case 14 : Catch(fDelay, oActivator, "Bass", 8); break;
case 15 : Catch(fDelay, oActivator, "Bluefish", 0); break;
case 16 : Catch(fDelay, oActivator, "Catfish", 4); break;
case 17 : Catch(fDelay, oActivator, "Croaker", 8); break;
case 18 : Catch(fDelay, oActivator, "Gravlax", 12); break;
case 19 : Catch(fDelay, oActivator, "Grouper", 0); break;
case 20 : Catch(fDelay, oActivator, "Haddock", 4); break;
case 21 : Catch(fDelay, oActivator, "Hake", 4); break;
case 22 : Catch(fDelay, oActivator, "Halibut", 12); break;
case 23 : Catch(fDelay, oActivator, "Mackerel", 8); break;
case 24 : Catch(fDelay, oActivator, "Marlin", 12); break;
case 25 : Catch(fDelay, oActivator, "Perch", 8); break;
case 26 : Catch(fDelay, oActivator, "Smelt", 4); break;
case 27 : Catch(fDelay, oActivator, "Snook", 12); break;
case 28 : Catch(fDelay, oActivator, "Sole", 8); break;
case 29 : Catch(fDelay, oActivator, "Tilapia", 4); break;
case 30 : Catch(fDelay, oActivator, "Walleye", 0); break;
case 31 : Catch(fDelay, oActivator, "Whitefish", 0); break;
case 32 : DelayCommand(fDelay, SendMessageToPC(oActivator, "The bait fell off the hook..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "You caught an old boot.")); break;
case 33 : DelayCommand(fDelay, SendMessageToPC(oActivator, "The fish don't show interest in the bait..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
case 34 : DelayCommand(fDelay, SendMessageToPC(oActivator, "The bait dives for a second..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
case 35 : DelayCommand(fDelay, SendMessageToPC(oActivator, "A fish stole the bait off the hook..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
case 36 : DelayCommand(fDelay, SendMessageToPC(oActivator, "The bait falls apart..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
case 37 : DelayCommand(fDelay, SendMessageToPC(oActivator, "A fish is nibbling on the bait..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
case 38 : DelayCommand(fDelay, SendMessageToPC(oActivator, "A fish tries to grab the bait..."));
DelayCommand(fDelay + 4.0, SendMessageToPC(oActivator, "Nothing happened.")); break;
}
}
void CheckForMultipleInstances(string ObjectToCheck){
object oTest = GetFirstObjectInArea();
while(GetIsObjectValid(oTest) == TRUE){
if(GetTag(oTest) == ObjectToCheck)
DestroyObject(oTest);
oTest = GetNextObjectInArea();
}
}
void main(){
object oPlayer = GetLastUsedBy();
object oSpot = OBJECT_SELF;
string sBait = "Bait_" + GetPCPlayerName(oPlayer);
string sRod = "Rod_" + GetPCPlayerName(oPlayer);
if(HasItem(oPlayer, "Rod") && HasItem(oPlayer, "FishingBait")){
AssignCommand(oPlayer, ClearAllActions());
AssignCommand(oPlayer, ActionForceMoveToLocation(GetLocation(oSpot), TRUE));
AssignCommand(oPlayer, SetFacing(GetFacing(oSpot) + 180.0));
AssignCommand(oPlayer, ActionSpeakString("*Throws bait*", TALKVOLUME_TALK));
AssignCommand(oPlayer, ActionPlayAnimation(ANIMATION_LOOPING_TALK_PLEADING, 0.1, 8.0));
TakeBait(oPlayer);
DelayCommand(0.2, SetCommandable(FALSE, oPlayer));
DelayCommand(7.8, SetCommandable(TRUE, oPlayer));
CheckForMultipleInstances(sRod);
CheckForMultipleInstances(sBait);
CreateObject(OBJECT_TYPE_PLACEABLE, "FishingRod", GetLocationInFrontOf(oSpot, 0.25, Height(oPlayer)), FALSE, sRod);
CreateObject(OBJECT_TYPE_PLACEABLE, "Bait", GetLocationInFrontOf(oSpot, 4.0, -1.0), FALSE, sBait);
StartFishing(oPlayer, sRod, sBait);
}
else
if(!HasItem(oPlayer, "Rod")) SendMessageToPC(oPlayer, "You need a Fishing Rod in order to be able to fish.");
if(!HasItem(oPlayer, "FishingBait")) SendMessageToPC(oPlayer, "You need Bait in order to be able to fish.");
}
Code: Select all
/*
August 09, 2003 - Eric Ettes - Raiko - zeiren@hotmail.com
This script reads all localints on a player and displays the number of fish per specie
Do not modify.
*/
void CountFish(object oPlayer, string Fish){
int nFish = GetLocalInt(oPlayer, Fish);
SendMessageToPC(oPlayer, "You have " + IntToString(nFish) + " " + Fish + "(s)");
}
void main(){
object oPlayer = GetPCSpeaker();
CountFish(oPlayer, "Amberjack");
CountFish(oPlayer, "Bass");
CountFish(oPlayer, "Bluefish");
CountFish(oPlayer, "Catfish");
CountFish(oPlayer, "Croaker");
CountFish(oPlayer, "Eel");
CountFish(oPlayer, "Gravlax");
CountFish(oPlayer, "Grouper");
CountFish(oPlayer, "Haddock");
CountFish(oPlayer, "Hake");
CountFish(oPlayer, "Halibut");
CountFish(oPlayer, "Herring");
CountFish(oPlayer, "Mackerel");
CountFish(oPlayer, "Marlin");
CountFish(oPlayer, "Perch");
CountFish(oPlayer, "Salmon");
CountFish(oPlayer, "Smelt");
CountFish(oPlayer, "Snapper");
CountFish(oPlayer, "Snook");
CountFish(oPlayer, "Trout");
CountFish(oPlayer, "Tuna");
CountFish(oPlayer, "Sole");
CountFish(oPlayer, "Tilapia");
CountFish(oPlayer, "Walleye");
CountFish(oPlayer, "Whitefish");
}
Code: Select all
/*
August 09, 2003 - Eric Ettes - Raiko - zeiren@hotmail.com
This script resets all localints on a player and pays the amount of gold
Do not modify.
*/
void BuyFish(object oPlayer, string Fish, int iGold){
int nFish = GetLocalInt(oPlayer, Fish);
SetLocalInt(oPlayer, Fish, 0);
GiveGoldToCreature(oPlayer, nFish * iGold);
}
void main(){
object oPlayer = GetPCSpeaker();
if(GetLocalInt(oPlayer, "Amberjack") > 0) BuyFish(oPlayer, "Amberjack", 15);
if(GetLocalInt(oPlayer, "Bass") > 0) BuyFish(oPlayer, "Bass", 15);
if(GetLocalInt(oPlayer, "Bluefish") > 0) BuyFish(oPlayer, "Bluefish", 5);
if(GetLocalInt(oPlayer, "Catfish") > 0) BuyFish(oPlayer, "Catfish", 10);
if(GetLocalInt(oPlayer, "Croaker") > 0) BuyFish(oPlayer, "Croaker", 15);
if(GetLocalInt(oPlayer, "Eel") > 0) BuyFish(oPlayer, "Eel", 25);
if(GetLocalInt(oPlayer, "Gravlax") > 0) BuyFish(oPlayer, "Gravlax", 25);
if(GetLocalInt(oPlayer, "Grouper") > 0) BuyFish(oPlayer, "Grouper", 5);
if(GetLocalInt(oPlayer, "Haddock") > 0) BuyFish(oPlayer, "Haddock", 10);
if(GetLocalInt(oPlayer, "Hake") > 0) BuyFish(oPlayer, "Hake", 10);
if(GetLocalInt(oPlayer, "Halibut") > 0) BuyFish(oPlayer, "Halibut", 25);
if(GetLocalInt(oPlayer, "Herring") > 0) BuyFish(oPlayer, "Herring", 10);
if(GetLocalInt(oPlayer, "Mackerel") > 0) BuyFish(oPlayer, "Mackerel", 15);
if(GetLocalInt(oPlayer, "Marlin") > 0) BuyFish(oPlayer, "Marlin", 25);
if(GetLocalInt(oPlayer, "Perch") > 0) BuyFish(oPlayer, "Perch", 15);
if(GetLocalInt(oPlayer, "Salmon") > 0) BuyFish(oPlayer, "Salmon", 15);
if(GetLocalInt(oPlayer, "Smelt") > 0) BuyFish(oPlayer, "Smelt", 10);
if(GetLocalInt(oPlayer, "Snapper") > 0) BuyFish(oPlayer, "Snapper", 10);
if(GetLocalInt(oPlayer, "Snook") > 0) BuyFish(oPlayer, "Snook", 25);
if(GetLocalInt(oPlayer, "Trout") > 0) BuyFish(oPlayer, "Trout", 5);
if(GetLocalInt(oPlayer, "Tuna") > 0) BuyFish(oPlayer, "Tuna", 25);
if(GetLocalInt(oPlayer, "Sole") > 0) BuyFish(oPlayer, "Sole", 15);
if(GetLocalInt(oPlayer, "Tilapia") > 0) BuyFish(oPlayer, "Tilapia", 10);
if(GetLocalInt(oPlayer, "Walleye") > 0) BuyFish(oPlayer, "Walleye", 5);
if(GetLocalInt(oPlayer, "Whitefish") > 0) BuyFish(oPlayer, "Whitefish", 5);
}