Aller au contenu

Photo

generic foraging system


  • Veuillez vous connecter pour répondre
Aucune réponse à ce sujet

#1
kamal_

kamal_
  • Members
  • 5 250 messages
This is an generic, flexible foraging system that is backwards compatible with wyrin's foraging system (http://nwvault.ign.c...s.Detail&id=225). It uses the same script name, so it can be retrofit to any module that uses his system with no additional work, or used as an override by a player.

Differences:
Allows customization of rewards (stack size supported), skills to check, skill dc, animations/sounds/messages to play. These are stored as local variables on the placeable. Partial success is allowed, with separate rewards and player messages. Skill checks are party-wide, not just the user of the placeable (not fully tested that bit yet).

Usage: In addition to the normal foraging of plants, you could "forage" a painting by checking appraise and or lore, discover a sword is heirloom quality with craft weapon, make the pc dance a jig on success, etc.

Support for wyrin's system:
Wyrin's system includes placeables, and these are treated as a special case, checked for by their tag. Wyrin's items all start their tag "forage_", so that's what's checked for (so don't tag your new forage-able placeable that way). Script includes both wyrin's original skill checks (item user only), and party-wide skill checking, so you can pick what you prefer.

linked erf includes the script and a sample placeable.
dl.dropbox.com/u/3879894/improved_foraging.erf

code dump follows....

/*
gerneic foraging system. checks entire party for highest skills, which skills, animations, dc's etc are stored on the placeable.
wyrin's foraging system is included here as a special case in two versions, the new version checks the entire party for the skills, the original is also included but commented out, it only checks the placeable user.
wyrin's system has hardcoded skills.

*/

void main()
{
//we need to track who actually used the object, so they can play the animation
//even though another members skills may be used.
object oItemUser = GetLastUsedBy();

//will be used to cycle through party
object oPC = GetFirstFactionMember(GetFirstPC(), FALSE);

// oPartyHighest are objects created to store which party member has the highest relevant skill values in party
// when skillchecking, since regular skill checking is only pc
object oPartyHighest1;
object oPartyHighest2;

//controls how many we give to player, we'll make it one if unspecified
int iStack = GetLocalInt(OBJECT_SELF, "iStack");

//tag of item received for success and partial success
string sReward = GetLocalString(OBJECT_SELF, "sReward");
string sPReward = GetLocalString(OBJECT_SELF, "sPReward");

// sound and animation to play
string sSound = GetLocalString(OBJECT_SELF, "sSound");
int iAnimation = GetLocalInt(OBJECT_SELF, "iAnim");
//reference
//ANIMATION_LOOPING_GET_LOW =12
//ANIMATION_LOOPING_GET_MID =13


// we can also play any success, partial success, or failure message
string sSuccess = GetLocalString(OBJECT_SELF, "sSuccess");
string sPSuccess = GetLocalString(OBJECT_SELF, "sPSuccess");
string sFailure = GetLocalString(OBJECT_SELF, "sFailure");

//give ourselves control over what skills
// we're using the same int base as a standard skill check
int iSkill1 = GetLocalInt(OBJECT_SELF, "iSkill1");
int iSkill2 = GetLocalInt(OBJECT_SELF, "iSkill2");

//and give control over DC, plus make sure they're valid.
int iDCSkill1 = GetLocalInt(OBJECT_SELF, "iDC1");
if (iDCSkill1 == 0)
{iDCSkill1 = 15;}
int iDCSkill2 = GetLocalInt(OBJECT_SELF, "iDC2");
if (iDCSkill2 == 0)
{iDCSkill2 = 15;}



/*
we're checking the entire party for the skills, so find highest values in party
*/

object oMember = GetFirstFactionMember(oPC);
//initialize the int to record highest party skill, we're using these to record them for later
int iPartyHighForSkill1 = 0;
int iPartyHighForSkill2 = 0;

//find highest skill in party of skill we're checking
while (GetIsObjectValid(oMember))
{
//store the skill of the party member we're checking
int iPartyMemberSkill1 = GetSkillRank(iSkill1,oMember, FALSE);
oPartyHighest1 = oMember;
//compare member's skill against party high, and set new high if member's skill higher
if (iPartyMemberSkill1 > iPartyHighForSkill1)
{
iPartyHighForSkill1 = iPartyMemberSkill1; //store party high
oPartyHighest1 = oMember; //remember this is the party member with highest skill for later skill checking
}
oMember=GetNextFactionMember(oMember, FALSE);

string sTest1 = IntToString(iPartyHighForSkill1);
SendMessageToPC(oItemUser, "party's skill1 high = " + sTest1);
}

// now record party high for skill 2


object oMember2 = GetFirstFactionMember(oPC);
while(GetIsObjectValid(oMember2))
{
int iPartyMemberSkill2 = GetSkillRank(iSkill2,oMember2, FALSE);
oPartyHighest2 = oMember2;
if (iPartyMemberSkill2 > iPartyHighForSkill2)
{
iPartyHighForSkill2 = iPartyMemberSkill2;
oPartyHighest2 = oMember2;
}
oMember2 = GetNextFactionMember(oMember, FALSE);

string sTest2 = IntToString(iPartyHighForSkill2);
SendMessageToPC(oItemUser, "party's skill2 high = " + sTest2);
}


// detect wyrin's original forage items and all others using the same tag system, applies wyrin's system, except redone to use party high for skills.
//comment this out and use the next section for wyrin's original behavior.
if (FindSubString(GetTag(OBJECT_SELF), "forage_")!=-1)
{
FloatingTextStringOnCreature("Using wyrin's system", oItemUser);
if (GetLocalString (OBJECT_SELF, "sProduce") == "produce_reeds")
{
iStack = 10;
}
string sProduce = GetLocalString(OBJECT_SELF,"sProduce");
string sForage = GetLocalString(OBJECT_SELF,"sForage");

if ((GetIsSkillSuccessful(oItemUser, SKILL_SURVIVAL, GetLocalInt(OBJECT_SELF, "iSurvival"))) && (GetIsSkillSuccessful(oItemUser, SKILL_CRAFT_ALCHEMY, GetLocalInt(OBJECT_SELF, "iAlchemy"))))
{

AssignCommand(oItemUser, ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0f, 1.0f));
CreateItemOnObject(sProduce, oItemUser, iStack);
SendMessageToPC(oItemUser, "You successfully forage the " + sForage);
FloatingTextStringOnCreature("This " + sForage + " should come in useful!", oItemUser);
GiveXPToCreature(oItemUser, 30);
PlaySound("as_na_leafmove3");
}
else
{
AssignCommand(oItemUser, ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0f, 1.0f));
SendMessageToPC(oItemUser, "You fail to gather the " + sForage + " correctly and the plant is wasted");
FloatingTextStringOnCreature("Curses! I'll have to find another source!", oItemUser);
}
DestroyObject(OBJECT_SELF, 0.5);
}

/*
// detect wyrin's original forage items and all others using the same tag system, applies wyrin's system, does not check party, same as wyrin's original system
if (FindSubString(GetTag(OBJECT_SELF), "forage_"))
{
if (GetLocalString (OBJECT_SELF, "sProduce") == "produce_reeds")
{
iStack = 10;
}
string sProduce = GetLocalString(OBJECT_SELF,"sProduce");
string sForage = GetLocalString(OBJECT_SELF,"sForage");

if ((GetIsSkillSuccessful(oItemUser, SKILL_SURVIVAL, GetLocalInt(OBJECT_SELF, "iSurvival"))) && (GetIsSkillSuccessful(oItemUser, SKILL_CRAFT_ALCHEMY, GetLocalInt(OBJECT_SELF, "iAlchemy"))))
{

AssignCommand(oItemUser, ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0f, 1.0f));
CreateItemOnObject(sProduce, oItemUser, iStack);
SendMessageToPC(oItemUser, "You successfully forage the " + sForage);
FloatingTextStringOnCreature("This " + sForage + " should come in useful!", oItemUser);
GiveXPToCreature(oItemUser, 30);
PlaySound("as_na_leafmove3");
}
else
{
AssignCommand(oItemUser, ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0f, 1.0f));
SendMessageToPC(oItemUser, "You fail to gather the " + sForage + " correctly and the plant is wasted");
FloatingTextStringOnCreature("Curses! I'll have to find another source!", oItemUser);
}
DestroyObject(OBJECT_SELF, 0.5);
}

*/



/*
Kamal
draw on local ints on the placeable to determine what skills to check, what dc, message, reward, animation, sound etc.
*/
else
{
//player succeeds in both skillchecks
if (GetIsSkillSuccessful(oPartyHighest1, iSkill1, iDCSkill1) && GetIsSkillSuccessful(oPartyHighest2, iSkill2, iDCSkill2))
{
//actions to take on success
AssignCommand(oItemUser, ActionPlayAnimation(iAnimation, 1.0f, 1.0f));
CreateItemOnObject(sReward, oItemUser, iStack);
PlaySound(sSound);
SendMessageToPC(oItemUser, sSuccess); //note the message is stored on the object
DestroyObject(OBJECT_SELF, 0.5);
}
//failed at least one check, check again for partial success.
else if (GetIsSkillSuccessful(oPartyHighest1, iSkill1, iDCSkill1) || GetIsSkillSuccessful(oPartyHighest2, iSkill2, iDCSkill2))
{
//actions to take on partial success
AssignCommand(oItemUser, ActionPlayAnimation(iAnimation, 1.0f, 1.0f));
CreateItemOnObject(sPReward, oItemUser, iStack);
PlaySound(sSound);
SendMessageToPC(oItemUser, sPSuccess);
DestroyObject(OBJECT_SELF, 0.5);
}
//well party failed
else
{
//what to do on failure
AssignCommand(oItemUser, ActionPlayAnimation(iAnimation, 1.0f, 1.0f));
SendMessageToPC(oItemUser, sFailure);
PlaySound(sSound);
DestroyObject(OBJECT_SELF, 0.5);
}
}
}

Modifié par kamal_, 21 décembre 2011 - 12:40 .