Aller au contenu

Photo

Help with Resting Script


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

#1
niapet

niapet
  • Members
  • 41 messages
Hey everyone,

I need to make a simple mod to my resting script.  I am using this one from the vault by Sorceress Ashura:

void main()
{

object oPC = GetLastPCRested();

if (GetLocalInt(oPC, "PlayerRestVariable")== 1)
   {
   //Do nothing rest as normal.
  
   }
else
   {
   if (GetItemPossessedBy(oPC, "ROR_Bedroll")!= OBJECT_INVALID)
   {
  
   //Do nothing, rest as usual.
  
   }
else
   {
   // Clear Actions, canceling rest..
   SendMessageToPC(oPC, "You need a bedroll to rest, find a campfire or Inn.");
   AssignCommand(oPC, ClearAllActions());
   }
   }

}


What I want to change is the second condition.  I dont want it to check for an item in the inventory I want to check to see if the PC is close to a fire as created by the PC tools.  The tag for the Fire that is created is HSS_CAMPFIRE_01

I just dont seem to have the scripting skills to figure out how to do this.

#2
Guest_Chaos Wielder_*

Guest_Chaos Wielder_*
  • Guests
Use this as the new if condition:



if(GetDistanceBetween(oPC, GetNearestObjectByTag("HSS_CAMPFIRE_01", oPC))<=5.0f)



Now, the final number at the end can be adjusted by how much distance you want between the player the fire. 2.5f for closer...you get the idea.

#3
niapet

niapet
  • Members
  • 41 messages
Thanks for the help, quick question can i just add in a requirement for the tent being close as well like this:



if(GetDistanceBetween(oPC, GetNearestObjectByTag("HSS_CAMPFIRE_01", oPC))<=5.0f) && if(GetDistanceBetween(oPC, GetNearestObjectByTag("HS_TENT_01", oPC))<=5.0f)


#4
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages
To check multiple conditions the syntax is

if ( this && that )

So you do not need the second "if" and you need an additional set of parantheses around everything after the first "if".

Like so:
if ( (GetDistanceBetween(oPC, GetNearestObjectByTag("HSS_CAMPFIRE_01", oPC)) <= 5.0f )
    && (GetDistanceBetween(oPC, GetNearestObjectByTag("HS_TENT_01", oPC)) <= 5.0f ) )
{
 // your code here
}

Regards

Modifié par Kaldor Silverwand, 15 février 2011 - 03:49 .


#5
The Fred

The Fred
  • Members
  • 2 516 messages
What Kaldor said, although, for the record, you can nest if statements. So you can put:

if(this)
{
    if(this also)
    {
        //Your code here
    }
}

It's normally better to use if(this && that), though, unless your condition list is long and messy (e.g. using a big mess of ANDs - && - and ORs - || - or something).

Modifié par The Fred, 20 février 2011 - 10:31 .