Aller au contenu

Photo

Trying to make a shopkeeper disappear at night


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

#1
nametab

nametab
  • Members
  • 70 messages
I am trying to create a script that makes a shopkeeper disappear from his store at night. The trick is I don't want it to happen while the PC is inside the store (if the PC enters the building at 18:00 and decides to stay there all night, the shopkeeper will remain there until the player leaves). I've tried doing it with the area's OnEnter and OnExit scripts but they don't seem to be able to assign any action or effect to the aforemoentioned NPC. Has anyone done such a thing for their module before?

#2
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Can you post the script you have so far, doesn't matter if it seems to work or not? That will help us help you.

#3
nametab

nametab
  • Members
  • 70 messages
Of course. I tried to use this in the area's OnEnter and OnClientEnter script slots.



void main()

{

object oShopkeeper = GetObjectByTag("Shopkeeper");

int nAbsoluteTime = GetTimeHour();

int nCloseTime = 20;

int nOpenTime = 6;

effect eScale = EffectSetScale(0.001f);

effect eSupernaturalScale = SupernaturalEffect(eScale);



if ((nAbsoluteTime >= nCloseTime) && (nAbsoluteTime < nOpenTime))

{

ActionDoCommand(ApplyEffectToObject(DURATION_TYPE_PERMANENT,eSupernaturalScale, oShopkeeper));

}

if ((nAbsoluteTime >= nOpenTime) && (nAbsoluteTime < nCloseTime))

{

effect eEffect = GetFirstEffect(oShopkeeper);

int nEffectValid =GetIsEffectValid(eEffect);

while (nEffectValid == TRUE)

{

RemoveEffect(oShopkeeper,eEffect);

eEffect = GetFirstEffect(oShopkeeper);

nEffectValid =GetIsEffectValid(eEffect);

}

}

}

#4
Quilistan

Quilistan
  • Members
  • 111 messages
Some spawn systems do this kind of thing with ease. Check out NESS it can do this with a simple setting on the spawns point.



There is a small learning curve with the system, but I think it is worth it and faster in the long run.

#5
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
Do you want to be able to go inside the shop when the shopkeeper is not present?


If not, then another option is to make a script that locks the shop at night, thus circumventing the problem of the disappearing shopkeeper.

If you do want to be able to go in the shop when the shopkeeper is gone, than you could make a trigger located right outside of the shop and put your script on that.  It would need to be located in such a way that the PC has to cross it to get into the shop.

Matt

Modifié par M. Rieder, 08 août 2010 - 05:34 .


#6
nametab

nametab
  • Members
  • 70 messages
No, I've already created a script that locks the door at night yet still allows the player to pick the lock on it (like in Oblivion). So I guess I'll try using a trigger.

#7
Orion7486

Orion7486
  • Members
  • 161 messages
Well, try this.  Put it in onclient enter.  Rather than doing the scaling down, use script hidden.  It causes the npc to not be able to react, do anything while he is script hidden.  Compiles, not tested.

void main()
{
     object oEnter = GetEnteringObject();
     object oShopkeeper = GetObjectByTag("Shopkeeper");
     int nGametime = GetTimeHour();
     int nClosetime = 20;
     int nOpentime = 6;
 
    //Stop script if entering object isn't PC.
    if (!GetIsPC(oEnter)) return;
 
    //If time is between 6AM-8PM, store is open
    if ((nGametime >= 6) && (nGametime <= 20))
    {
        //If shopkeeper is hidden, unhide him. If already
        //unhidden will do nothing.
       SetScriptHidden(oShopkeeper, FALSE);
    }
   //Time is between 8:01PM-5:59AM, store is closed.
   else
   {
      //If shopkeeper isn't hidden, will hide him.
      //If already hidden, will keep him hidden.
     SetScriptHidden(oShopkeeper, TRUE, TRUE);
   }
}

#8
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Just a note to you there Orion, as written your script just looks at the game hour, so the shop will be considered "open" until 9PM (ie. 8:00 to 8:59 inclusive). Not a big deal, just thought I'd point it out.

#9
nametab

nametab
  • Members
  • 70 messages

Orion7486 wrote...

Well, try this.  Put it in onclient enter.  Rather than doing the scaling down, use script hidden.  It causes the npc to not be able to react, do anything while he is script hidden.  Compiles, not tested.

void main()
{
     object oEnter = GetEnteringObject();
     object oShopkeeper = GetObjectByTag("Shopkeeper");
     int nGametime = GetTimeHour();
     int nClosetime = 20;
     int nOpentime = 6;
 
    //Stop script if entering object isn't PC.
    if (!GetIsPC(oEnter)) return;
 
    //If time is between 6AM-8PM, store is open
    if ((nGametime >= 6) && (nGametime <= 20))
    {
        //If shopkeeper is hidden, unhide him. If already
        //unhidden will do nothing.
       SetScriptHidden(oShopkeeper, FALSE);
    }
   //Time is between 8:01PM-5:59AM, store is closed.
   else
   {
      //If shopkeeper isn't hidden, will hide him.
      //If already hidden, will keep him hidden.
     SetScriptHidden(oShopkeeper, TRUE, TRUE);
   }
}


Thanks, that did the trick :) I'll probably change the time the store opens and closes but the most important thing is that the script works.

#10
Orion7486

Orion7486
  • Members
  • 161 messages

_Knightmare_ wrote...

Just a note to you there Orion, as written your script just looks at the game hour, so the shop will be considered "open" until 9PM (ie. 8:00 to 8:59 inclusive). Not a big deal, just thought I'd point it out.

Ah, right you are, sir.

#11
rjshae

rjshae
  • Members
  • 4 485 messages
A nice addition would be to have the shopkeeper announce the store closing a minute before it happens, then have them move to stand by the door expectantly. You could also mark up the prices if the PC tries to buy anything after the closing time.

#12
nametab

nametab
  • Members
  • 70 messages

rjshae wrote...

A nice addition would be to have the shopkeeper announce the store closing a minute before it happens, then have them move to stand by the door expectantly. You could also mark up the prices if the PC tries to buy anything after the closing time.


That is a good idea, although I think I'll just alter the shopkeeper's conversation, so that he won't buy or sell anything after 19:00 and before 6:00 or 7:00.