Aller au contenu

Photo

Two Questions


  • Veuillez vous connecter pour répondre
27 réponses à ce sujet

#1
JediMindTrix

JediMindTrix
  • Members
  • 283 messages
Hello again, I'm back with two more seemingly simple questions!

The first question pertains to a OnPercieved script for an NPC, the first one the player see's upon loading the module. She is supposed to scream and make a run for a waypoint inside the inn they are next too. The building has three doors, and while the one she is closest too is unlocked, and the waypoint is right next to the transition on the other side, the NPC makes a run for the only other accessible locked door and just stands there. O.o

The script is as follows:

void main()
{
ExecuteScript("nw_c2_default2", OBJECT_SELF);

object oPC = GetLastPerceived();
if (!GetIsPC(oPC)) return;
if (!GetLastPerceptionSeen()) return;
string sTag = GetTag(OBJECT_SELF);
if (GetLocalInt(oPC, sTag)) return;
SetLocalInt(oPC, sTag, TRUE);

location lDestination = GetLocation(GetWaypointByTag("pt_vessa1stencounter"));
DelayCommand(5.0, ActionSpeakString("AIIEEE!! How'n th' hells did ye do that!?"));
ActionMoveToLocation(lDestination, TRUE);


Now, for my second question: I have a script that runs a Search check, and if that fails, a spot check, to see if the player finds a a secret stash in the woods when they pass by. However, the check's appear in the chat window, and if the player fails the search/spot check then it will tip the player off there's a secret there. Is there anyway to make those checks "hidden"?

Here's the code for that script as well:

object oTarget = GetWaypointByTag("pt_secretpantr");
location lTarget = GetLocation(oTarget);

void main()
{
object oPC = GetEnteringObject();

string sTag = GetTag(OBJECT_SELF);
if (GetLocalInt(oPC, sTag)) return;

if (GetIsSkillSuccessful(oPC, SKILL_SEARCH, 10))
   {
   CreateObject(OBJECT_TYPE_PLACEABLE, "pt_secretpantr", lTarget);
   AssignCommand(oPC, PlayVoiceChat(VOICE_CHAT_LOOKHERE));
   GiveXPToCreature(oPC, 35);
   SendMessageToPC(oPC, "You have received an exploration bonus!");
   SetLocalInt(oPC, sTag, TRUE);
   }
else if (GetIsSkillSuccessful(oPC, SKILL_SPOT, 10))
   {
   CreateObject(OBJECT_TYPE_PLACEABLE, "pt_secretpantr", lTarget);
   AssignCommand(oPC, PlayVoiceChat(VOICE_CHAT_LOOKHERE));
   GiveXPToCreature(oPC, 35);
   SendMessageToPC(oPC, "You have received an exploration bonus!");
   SetLocalInt(oPC, sTag, TRUE);
   }
}


Thank you for the help!

-NineCoronas

#2
meaglyn

meaglyn
  • Members
  • 807 messages
For the first problem you could put a first waypoint just in front
of the door you want to use. Then move to that and add an
ActionJumpToLocation to the original destination.


For the second, the lexicon page for GetIsSkillSuccessful has a private
version you can use instead. Put the whole routine up top in your script
or in an include of your own.


// Function to do a private version of this skill check, no result
// is told to the PC
int GetIsSkillSuccessfulPrivate(object oTarget, int nSkill, int nDifficulty)
{
// Do the roll for the skill
if(GetSkillRank(nSkill, oTarget) + d20() >= nDifficulty)
{
// They passed the DC
return TRUE;
}
// Failed the check
return FALSE;
}

#3
JediMindTrix

JediMindTrix
  • Members
  • 283 messages
So, for the first:

location lDestinationA = GetLocation(GetWaypointByTag("pt_vessa1stencounter2")); //Placed by the door on the exterior
location lDestinationB = GetLocation(GetWaypointByTag("pt_vessa1stencounter")); //Placed by the door on the other side of the transition (ultimate destination)
DelayCommand(5.0, ActionSpeakString("AIIEEE!! How'n th' hells did ye do that!?"));
ActionMoveToLocation(lDestinationA, TRUE);
ActionMoveToLocation(lDestinationB, TRUE);


I don't need to throw in any DelayCommands to make sure the waypoints are followed correctly or anything like that?

-NineCoronas

#4
Baragg

Baragg
  • Members
  • 271 messages

NineCoronas2021 wrote...

So, for the first:

location lDestinationA = GetLocation(GetWaypointByTag("pt_vessa1stencounter2")); //Placed by the door on the exterior
location lDestinationB = GetLocation(GetWaypointByTag("pt_vessa1stencounter")); //Placed by the door on the other side of the transition (ultimate destination)
DelayCommand(5.0, ActionSpeakString("AIIEEE!! How'n th' hells did ye do that!?"));
ActionMoveToLocation(lDestinationA, TRUE);
ActionMoveToLocation(lDestinationB, TRUE);


I don't need to throw in any DelayCommands to make sure the waypoints are followed correctly or anything like that?

-NineCoronas


Are you moving the NPC to both locations? If so I would delay the second moveto command a bit to insure the NPC moves to the first location . You may have to fiddle with the timing a bit, it would be easiest to set the float as a final in you script so you can change it without having to scroll thro the script to find it.

#5
meaglyn

meaglyn
  • Members
  • 807 messages

NineCoronas2021 wrote...

So, for the first:

location lDestinationA = GetLocation(GetWaypointByTag("pt_vessa1stencounter2")); //Placed by the door on the exterior
location lDestinationB = GetLocation(GetWaypointByTag("pt_vessa1stencounter")); //Placed by the door on the other side of the transition (ultimate destination)
DelayCommand(5.0, ActionSpeakString("AIIEEE!! How'n th' hells did ye do that!?"));
ActionMoveToLocation(lDestinationA, TRUE);
ActionMoveToLocation(lDestinationB, TRUE);


I don't need to throw in any DelayCommands to make sure the waypoints are followed correctly or anything like that?

-NineCoronas


The second one is going to a different area, yes? I'd just do ActionJumpToLocation for that one. It'll look like
about like a transition and not run the risk of trying to run out the other door again.

You should not need a delay since these are actions which go in the NPC's action queue. They should be completed in order. So first NPC move to iDestinationA, when that completes the move (or jump) to
iDestinationB starts.

You may not see the SpeakString though since that'll go in the action queue after these moves. By then
then NPC should be on the other side of the door. As long as it takes less than 5.0 seconds to get
to the first waypoit you might just use SpeakString and not ActionSpeakString.


Cheers,
Meaglyn

#6
Fester Pot

Fester Pot
  • Members
  • 1 393 messages

meaglyn wrote...

For the second, the lexicon page for GetIsSkillSuccessful has a private
version you can use instead.


EDIT: After posting the script.
Haha. Really? REALLY? *slaps forehead* I'm such a newb. :happy:

I'll leave the below script for reference.

NineCoronas2021 wrote...
Now, for my second question: I have a script that runs a Search check, and if that fails, a spot check, to see if the player finds a a secret stash in the woods when they pass by. However, the check's appear in the chat window, and if the player fails the search/spot check then it will tip the player off there's a secret there. Is there anyway to make those checks "hidden"?


void main()
{
object oPC = GetEnteringObject();

object oTarget = GetWaypointByTag("pt_secretpantr");
location lTarget = GetLocation(oTarget);

string sTag = GetTag(OBJECT_SELF);
if (GetLocalInt(oPC, sTag)) return;

// How hard will it be, to spot the hidden object
// Change values as required
  int cDC_TO_SEARCH = 10;

// How hard will it be, to search the hidden object
// Change values as required
  int cDC_TO_SPOT = 10;

  int SpotRoll;
  int SpotSkill;

  int SearchRoll;
  int SearchSkill;

if (SearchSkill = GetSkillRank(SKILL_SEARCH, oPC))
   {
      SearchRoll = SearchSkill + d20();

      if (SearchRoll < 1)
        SearchRoll = 1;

      if (SearchRoll >= cDC_TO_SEARCH)
      {

      CreateObject(OBJECT_TYPE_PLACEABLE, "pt_secretpantr", lTarget);
      AssignCommand(oPC, PlayVoiceChat(VOICE_CHAT_LOOKHERE));
      GiveXPToCreature(oPC, 35);
      SendMessageToPC(oPC, "You have received an exploration bonus!");
      SetLocalInt(oPC, sTag, TRUE);

      }
   }

else if (SpotSkill = GetSkillRank(SKILL_SPOT, oPC))

      {
        SpotRoll = SpotSkill + d20();

        if (SpotRoll < 1)
          SpotRoll = 1;

        if (SpotRoll >= cDC_TO_SPOT)
        {

        CreateObject(OBJECT_TYPE_PLACEABLE, "pt_secretpantr", lTarget);
        AssignCommand(oPC, PlayVoiceChat(VOICE_CHAT_LOOKHERE));
        GiveXPToCreature(oPC, 35);
        SendMessageToPC(oPC, "You have received an exploration bonus!");
        SetLocalInt(oPC, sTag, TRUE);

        }
      }
}


Additionally, depending on how many times you're going to have such little secret triggers in your module, it might be best to store the cDC_TO_SPOT and cDC_TO_SEARCH as variables on the trigger itself. Then just read those variables instead. This is so you only need one script to do what you want, for all of these kind of triggers - rather than multiple scripts with different SPOT and SEARCH values.

The script above has the SPOT and SEARCH values set to 10.

FP!

Modifié par Fester Pot, 21 mai 2012 - 03:49 .


#7
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
if (SearchSkill == GetSkillRank(SKILL_SEARCH, oPC))...

...else if (SpotSkill ==GetSkillRank(SKILL_SPOT, oPC))


EDIT: pardon me I was not reading close enough.  Searves me right for just scanning through.

Modifié par Lightfoot8, 22 mai 2012 - 04:44 .


#8
JediMindTrix

JediMindTrix
  • Members
  • 283 messages

Lightfoot8 wrote...

if (SearchSkill == GetSkillRank(SKILL_SEARCH, oPC))...

...else if (SpotSkill ==GetSkillRank(SKILL_SPOT, oPC))


What is the difference in "==" versus "=" ?

#9
JediMindTrix

JediMindTrix
  • Members
  • 283 messages
How would one get a script to look for a local string with only the first few characters of the string and then return with all of the string?

I.E., is it possible to tell a script to search for LocalString("pt_stashxxx") and return each localstring that begins with pt_stash?

I ask this because this way I will also be able to store the tag's of the secret containers that spawn on the trigger.

EDIT:
Also, is it possible to check to see if a local string simply exists (not for it's value, but just to see if it's there)

Modifié par NineCoronas2021, 22 mai 2012 - 04:51 .


#10
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
' = ' is an assiment assignment .
' == ' is a comparison.

Modifié par Lightfoot8, 22 mai 2012 - 05:10 .


#11
JediMindTrix

JediMindTrix
  • Members
  • 283 messages

Lightfoot8 wrote...

' = ' is an assiment.
' == ' is a comparison.


If you're comparing the result of a skill roll against a DC, wouldn't "==" be appropriate then?

P.S. What is an assiment? :innocent:

Modifié par NineCoronas2021, 22 mai 2012 - 05:04 .


#12
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

NineCoronas2021 wrote...
Also, is it possible to check to see if a local string simply exists (not for it's value, but just to see if it's there)


if (GetLocalString(oObject, "STRING_NAME") != ""))

#13
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

NineCoronas2021 wrote...

Lightfoot8 wrote...

' = ' is an assiment.
' == ' is a comparison.


If you're comparing the result of a skill roll against a DC, wouldn't "==" be appropriate then?



in the script given, no.  

He is doing something that I would not expect to see in a script for instruction to a new scripter.  

He is really not doing a compairson there.   He is taking the skill rank for the skill, assigning to to a variable, and testing it to see if it is 0 or not.   if the skill rank was not 0, the PC then has at leas some ranks in the skill it therefor allows the PC to use the skill to find the object.   If the PC has no ranks in the skill 0 was assigned to the var and no search takes place.

Edit:  P.S.   An assignment takes the value on the right side and assigns its value to the Left side.  So ' x = y ' would take the value of y and place it in the memory location represented by the Lable x.  

Modifié par Lightfoot8, 22 mai 2012 - 05:17 .


#14
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

NineCoronas2021 wrote...
P.S. What is an assiment? :innocent:


Respect the L8. English might not be his first language but he could script circles around many of us.

#15
JediMindTrix

JediMindTrix
  • Members
  • 283 messages

GhostOfGod wrote...

NineCoronas2021 wrote...
Also, is it possible to check to see if a local string simply exists (not for it's value, but just to see if it's there)


if (GetLocalString(oObject, "STRING_NAME") != ""))


Can something similar be done with integers?

EDIT:

GhostOfGod wrote...

Respect the L8. English might not be his first language but he could script circles around many of us.


Uhm, I did not mean any disrespect. There are plenty of funky terms that go right over my head and assinment could've just as easily been one of them.

Modifié par NineCoronas2021, 22 mai 2012 - 05:11 .


#16
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

NineCoronas2021 wrote...

GhostOfGod wrote...

NineCoronas2021 wrote...
Also, is it possible to check to see if a local string simply exists (not for it's value, but just to see if it's there)


if (GetLocalString(oObject, "STRING_NAME") != ""))


Can something similar be done with integers?


if (GetLocalInt(oObject, "INT_NAME"))   <----exists

if (!GetLocalInt(oObject, "INT_NAME"))   <----does not exist

Edited

Modifié par GhostOfGod, 22 mai 2012 - 05:19 .


#17
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

GhostOfGod wrote...

NineCoronas2021 wrote...
P.S. What is an assiment? :innocent:


Respect the L8. English might not be his first language but he could script circles around many of us.



lol,  Sadly english is my first and only language.  Spelling has always been my weak point.   As I get tired it gets even worse.   Add to that my bad typing and there are times when I can not even read what I have posted.

Modifié par Lightfoot8, 22 mai 2012 - 05:13 .


#18
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

Lightfoot8 wrote...

GhostOfGod wrote...

NineCoronas2021 wrote...
P.S. What is an assiment? :innocent:


Respect the L8. English might not be his first language but he could script circles around many of us.



lol,  Sadly english is my first and only language.  Spelling has always been my weak point.   As I get tired it gets even worse.   Add to that my bad typing and there are times when I can not even read what I have posted.


LOL. j/k j/k. Good spelling or not you still rock :o

#19
JediMindTrix

JediMindTrix
  • Members
  • 283 messages

Lightfoot8 wrote...
in the script given, no.  

He is doing something that I would not expect to see in a script for instruction to a new scripter.  

He is really not doing a compairson there.   He is taking the skill rank for the skill, assigning to to a variable, and testing it to see if it is 0 or not.   if the skill rank was not 0, the PC then has at leas some ranks in the skill it therefor allows the PC to use the skill to find the object.   If the PC has no ranks in the skill 0 was assigned to the var and no search takes place.


I had no idea that this is something I wanted my script to do until you explained it like this. Thank you!

#20
JediMindTrix

JediMindTrix
  • Members
  • 283 messages

if (SearchRoll < 1)
SearchRoll = 1;


What specifically is happening here?
I see that is checking to see if SearchRoll returns as less than 1,
But why does it set SearchRoll = 1 afterwords?

Also,

int iXPBonus = GetLocalInt(OBJECT_SELF, "iXPBonus");

if (GetLocalInt(OBJECT_SELF, iXPBonus))

does not compile until you add quotations around it.

However,

string sMessage = GetLocalString(OBJECT_SELF, "StashMessage");

   if (GetLocalString(OBJECT_SELF, sMessage)!= "")


does compile.

How come GetLocalString will use the pre-defined string but GetLocalInt will not use the pre-defined int?

Modifié par NineCoronas2021, 22 mai 2012 - 05:36 .


#21
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Using your example:

int iXPBonus = GetLocalInt(OBJECT_SELF, "iXPBonus");

if (GetLocalInt(OBJECT_SELF, iXPBonus))

iXPBonuse is supposed to be a string. You are looking for an int named "iXPBonus". So if you did it like this...

string sXPBonus = "iXPBonus";

if (GetLocalInt(OBJECT_SELF, sXPBonus))

...it should work. But it is a bit unnecessary when you can just put the string for the name right in there like...

if (GetLocalInt(OBJECT_SELF, "XPBonus"))

Hopefully that makes sense.

#22
JediMindTrix

JediMindTrix
  • Members
  • 283 messages
iXPBonus being a string does not make sense to me because it has been defined as an int earlier in the script.

"string sXPBonus = "iXPBonus";" being redundant to add in makes sense.

Modifié par NineCoronas2021, 22 mai 2012 - 06:16 .


#23
JediMindTrix

JediMindTrix
  • Members
  • 283 messages

He is taking the skill rank for the skill, assigning to to a variable,
and testing it to see if it is 0 or not. if the skill rank was not 0,
the PC then has at leas some ranks in the skill it therefor allows the
PC to use the skill to find the object. If the PC has no ranks in the
skill 0 was assigned to the var and no search takes place.

      if (SearchRoll < 1) //If SearchRoll is less than 1
        SearchRoll = 1;  //Set SearchRoll to 1

Shouldn't SearchRoll = 1 actually be SearchRoll = 0 in order to achieve the effect Lightfoot8 describes in the quote above?

EDIT:

if (SearchSkill = GetSkillRank(SKILL_SEARCH, oPC))  //Performs the search skill check on the player using the trigger's stored DC
    {
     SearchRoll = SearchSkill;
     if (SearchRoll < 1)
         SearchRoll = -20;

     if (SearchRoll  + d20() >= iSearchDC)
     {


I believe this is one way to achieve the affect Lightfoot8 mentioned. Am I correct?

EDIT 2:
Alternatively, is this a possibility?

     if (SearchRoll < 1)
         return;


Modifié par NineCoronas2021, 22 mai 2012 - 06:45 .


#24
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
It just breaks down like this:

if (SearchSkill = GetSkillRank(SKILL_SEARCH, oPC)) [color="#99cc00"]<---This could potentially return a -1[/color] [color="#99cc00"]according to the Lexicon information.[/color]
   {
      SearchRoll = SearchSkill + d20(); [color="#99cc00"]<--so if "SearchRoll did return a -1 (no skill) [/color][color="#99cc00"]and the d20() just rolls a 1, you end up with 0.[/color]

      if (SearchRoll < 1) [color="#99cc00"]<--If the roll ends up being less than 1 ( 0 )....[/color]
        SearchRoll = 1;
<--...we don't want that so let's just force
it to be a 1.



Pretty sure that is what's going on here.

#25
JediMindTrix

JediMindTrix
  • Members
  • 283 messages
For anyone interested in what the final version of this code looks like:

// Created By: NineCoronas 5/21/2012 9:45 pm
// Special thanks to Lightfoot8, Meaglyn, Fester Pot, and GhostOfGod for putting
// up with my incessant questions and providing assistance. You guys rock!
//
// Usage: This system allows the user to set up 'Secret Stashes' anywhere, using
// triggers, waypoints, and variables, which can only be discovered upon passing
// private search and spot checks. It will first run a search check, and if the
// pc fails that, run a spot check. If successful, the script spawns in the
// stash and the pc will speak a message saying he/she found something. If desired
// the pc can also be awarded some xp along with an accompanying message. If the
// PC does not succeed either skill check, he/she will be none the wiser.
//
// INSTRUCTIONS
// 1) Make sure you have a unique container with a unique tag in the palette.
// Now, lay down a trigger and give it a unique tag where you'd like the PC to
// find the secret stash.
// 2) Lay down a waypoint where you'd like the container to spawn. Give it the
// same tag as the trigger.
// 3) Open the "Variables" menu on the trigger. Now we will begin adding the
// necessary variables.
//    REQUIRED VARIABLES
//    * Create a String named "StashType" without the quotations. In the value
//      section, type the tag of the placeable container you want to spawn in.
//    * Create an Integer named "iSearchDC" without the quotations. In the value
//      section, type the value that will be the search DC. I.E. "25" for a DC
//      of 25.
//    * Create an Integer named "iSpotDC" without the quotations. In the value
//      section, type the value that will be the spot DC. I.E. "25" for a DC of
//      25.
//    OPTIONAL VARIABLES
//    * Create a String named "StashMessage" without the quotations. In the
//      value section, type out the message you wish the player to receive in
//      the chat window upon finding the stash.
//    * Create an Integer named "iXPBonus" without the quotations. In the value
//      section, type in the amount of xp you would like the player to be
//      awarded upon finding the stash.
//
//    NOTES
//    * Keep in mind that a Level 1 player with 1 point in either Spot or search
//      is capable of passing a DC of 21. Usually, however, they will have 4,
//      and thus a DC of 24 would be passable.
//    * The skill checks will not be made if the player has no skill ranks in
//      either skill.
//    * This script will fire only once per player.
//

void main()
{
object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;
object oTarget = GetWaypointByTag(GetTag(OBJECT_SELF));
location lTarget = GetLocation(oTarget);
string sStash = GetLocalString(OBJECT_SELF, "StashType");       //Checks the trigger for the tag of container placeable to be created
string sMessage = GetLocalString(OBJECT_SELF, "StashMessage");  //Checks the trigger for the message the player is to receive
int iSearchDC = GetLocalInt(OBJECT_SELF, "iSearchDC");          //Checks the trigger for the search DC
int iSpotDC = GetLocalInt(OBJECT_SELF, "iSpotDC");              //Checks the trigger for the spot DC
int iXPBonus = GetLocalInt(OBJECT_SELF, "iXPBonus");            //Checks the trigger for the XP to be awarded to the player
int SpotRoll;
int SpotSkill;
int SearchRoll;
int SearchSkill;

string sTag = GetTag(OBJECT_SELF);
if (GetLocalInt(oPC, sTag)) return;






if (SearchSkill = GetSkillRank(SKILL_SEARCH, oPC))  //Performs the search skill check on the player using the trigger's stored DC
    {
     SearchRoll = SearchSkill;
     if (SearchRoll < 1)                                          //If the player has less then 1 skill rank, then the script will set the result to -20
         SearchRoll = -20;                                        //so it isn't possible for the player to succeed in a roll

     if (SearchRoll  + d20() >= iSearchDC)                        //Player's Skill Rank + d20 vs. DC
     {
     CreateObject(OBJECT_TYPE_PLACEABLE, sStash, lTarget);        //Creates the stash at the waypoint with the same tag as the trigger
     AssignCommand(oPC, PlayVoiceChat(VOICE_CHAT_LOOKHERE));      //"I found something!"
      if (GetLocalInt(OBJECT_SELF, "iXPBonus"))                   //Checks to see if the iXPBonus integer is set, if it isn't, script moves on
      {
      GiveXPToCreature(oPC, iXPBonus);                            //Gives the amount of xp stored on the integer to the player
      }
      if (GetLocalString(OBJECT_SELF, sMessage)!= "")             //Checks to see if the there is a message to send to the player, if not, script moves on
      {
      SendMessageToPC(oPC, sMessage);                             //Sends the message stored on the string to the player
      }
     SetLocalInt(oPC, sTag, TRUE);                                //Sets an integer on the player that will be checked next time the player enters the trigger.
     }                                                            //If the script finds the integer, then the script will not fire.
    }
if (SpotSkill = GetSkillRank(SKILL_SPOT, oPC))                    //Performs the search skill check on the player using the trigger's stored DC
    {
     SpotRoll = SpotSkill + d20();
     if (SpotRoll < 1)
         SpotRoll = -20;

     if (SpotRoll >= iSpotDC)
     {
      CreateObject(OBJECT_TYPE_PLACEABLE, sStash, lTarget);
      AssignCommand(oPC, PlayVoiceChat(VOICE_CHAT_LOOKHERE));
      if (GetLocalInt(OBJECT_SELF, "iXPBonus"))
       {
       GiveXPToCreature(oPC, iXPBonus);
       }
      if (GetLocalString(OBJECT_SELF, sMessage)!= "")
       {
       SendMessageToPC(oPC, sMessage);
       }
      SetLocalInt(oPC, sTag, TRUE);
     }
    }
}

I'm quite proud of this :D

P.S. Meaglyn, thanks for helping me figure out the issue's with the waypoints. It indeed took a lot of fiddling.