Aller au contenu

Photo

unlock a door by scripting


19 réponses à ce sujet

#1
slaaleth

slaaleth
  • Members
  • 71 messages
hi

I want to unlock a door by scripting.

I have an area door that I set the initial state to lock and the pick lock level to impossible. and I want when the player recieve the quest from the npc (who is in the same area) the door come unlock. I try this code, but it doesn't work:



#include "events_h"
#include "plt_quest_armure"
#include "wrappers_h"

void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);

    switch(nEventType)
    {
        case EVENT_TYPE_SET_PLOT:
        {
            int iprog=WR_GetPlotFlag(PLT_QUEST_ARMURE, TUER_LES_MONSTRE_SOUS_LA_CHANTRIE, TRUE);
            object odoor=GetObjectByTag("door_sanctuaire_ch");

            if(iprog== TRUE)
            {
                SetPlaceableState(odoor, PLC_STATE_DOOR_UNLOCKED);
            }

            // Insert event-handling code here.
            break;

        }

    }
    HandleEvent(ev, RESOURCE_SCRIPT_AREA_CORE);
}

is someone can help me?

Modifié par slaaleth, 12 janvier 2010 - 09:29 .


#2
anakin5

anakin5
  • Members
  • 258 messages
Look at plot scripts in Background - Human Noble folder :



object oFergusDoor = GetObjectByTag("bhn200ip_door_fergus");
SetPlaceableActionResult(oFergusDoor, PLACEABLE_ACTION_UNLOCK, TRUE);


#3
Craig Graff

Craig Graff
  • Members
  • 608 messages
Alternately, use SetPlaceableState(oDoor, PLC_STATE_DOOR_UNLOCKED) as you already are, but find the problem in your plot flag or your tag, since that would more likely be the problem.

Modifié par Craig Graff, 12 janvier 2010 - 11:02 .


#4
slaaleth

slaaleth
  • Members
  • 71 messages
ok I'll try but is the event I use in the switch case in correct for doing this job?

#5
DavidSims

DavidSims
  • BioWare Employees
  • 196 messages
That seems to be a plot script, but you don't have a switch/case statement to branch based on which flag is set. Technicaly that works, if you're okay with the script running no matter which flag is set.



However, if looks like maybe instead of the switch you're trying to grab the value of the flag and check it. Flags are set after the plot script runs, not before. That flag would have to be set twice before the door would open, assuming the tag is correct and everything is hooked up properly.

#6
Craig Graff

Craig Graff
  • Members
  • 608 messages
Heh, I'm embarrassed I didn't catch that, but I must admit I had only glanced at your code.

No, the event is for plot file scripts, not areas. The proper way to do that is to attach a plot script to your plot. See my second post in this thread for an example: social.bioware.com/forum/1/topic/71/index/524374&lf=8

Just replace the
[dascript]
                resource rCutscene = R"attack.cut";
                CS_LoadCutscene(rCutscene);
with
            object odoor=GetObjectByTag("door_sanctuaire_ch");
            SetPlaceableState(odoor, PLC_STATE_DOOR_UNLOCKED);
[/dascript]

Modifié par Craig Graff, 12 janvier 2010 - 11:48 .


#7
slaaleth

slaaleth
  • Members
  • 71 messages
I found this in the single player module into the background human-noble and i modifie it for my module. I put this script on the door script and it work


case EVENT_TYPE_USE:
        {
            if (WR_GetPlotFlag(PLT_QUEST_ARMURE,TUER_LES_MONSTRE_SOUS_LA_CHANTRIE))
            {
                SetPlaceableActionResult(OBJECT_SELF,PLACEABLE_ACTION_UNLOCK,TRUE);
            }
        }

#8
slaaleth

slaaleth
  • Members
  • 71 messages
craig I look the link you give.

in this exemple:
switch(nFlag)
        {
            case MY_PLOT_CUTSCENE_RUN:
            {
                resource rCutscene = R"attack.cut";
                CS_LoadCutscene(rCutscene);
                break;
            }
        }

how is set the variable nFlag? is it the WR_GetPlotFlag() ? and what type of variable is it?

and in the case the MY_PLOT_CUTSCENE_RUN is it the plot or the flag I have to put?

and this script I have to put it in the script of the area or the script of the door?

Modifié par slaaleth, 13 janvier 2010 - 07:51 .


#9
Craig Graff

Craig Graff
  • Members
  • 608 messages
You set the flag with either WR_SetPlotFlag (notice that it is "Set" and not "Get"). In a switch-case statement like the one above each case is a value of the nFlag variable, so, it is the flag name you want. And please note that the example talks about the fact that this is a PLOT script, attached to a plot file (the instructions for creating and attaching the script to the plot file are in the link I gave at the bottom of the second post). If you need to take a step back and make your plot file first, let me know and I'll try to put together a step-by-step for you (which I will prettify and post to the wiki when I get some time).

#10
slaaleth

slaaleth
  • Members
  • 71 messages
I have already made a plot file, but the script won't get export.

the error is the following:

script_door.nss - script_door.nss(8): Mismatched types (while compiling var_constants_h.nss)

and the line 8 is the line in red

#include "events_h"
#include "plt_quest_armure"
#include "wrappers_h"


void main()
{         
    int nFlag=WR_SetPlotFlag(PLT_QUEST_ARMURE, TUER_LES_MONSTRE_SOUS_LA_CHANTRIE, TRUE);
    switch(nFlag)
    {
        case START_QUEST:
        {
            object oDoor=GetObjectByTag("door_test_script");
            SetPlaceableState(oDoor, PLC_STATE_DOOR_UNLOCKED);
            break;
        }
    }
    HandleEvent(ev, RESOURCE_SCRIPT_PLOT_CORE);
}



And I have to put this script to the plot file and just set the right action in the plot and scripting panel in the conversation right?

#11
slaaleth

slaaleth
  • Members
  • 71 messages
sorry for the double post missclick

Modifié par slaaleth, 13 janvier 2010 - 09:18 .


#12
Craig Graff

Craig Graff
  • Members
  • 608 messages
That is an incomplete script. You need to follow all the directions in the link. Most especially the first two steps:
- In the new blank script click on the Templates button in the upper right corner of the script editor.
- Double-click Custon plot events.txt in the templates list - this will insert the template into the blank script.

And I have to put this script to the plot file and just set the right
action in the plot and scripting panel in the conversation right?

Yes.

Modifié par Craig Graff, 13 janvier 2010 - 09:24 .


#13
slaaleth

slaaleth
  • Members
  • 71 messages
yes it work thank's a lot



juste a question is it the same thing for active a pin on the map? just change this :



SetPlaceableState(oDoor, PLC_STATE_DOOR_UNLOCKED);

#14
Craig Graff

Craig Graff
  • Members
  • 608 messages
Pretty much, though you need to go back to object oMapPin = GetObjectByTag("TagOfYourMapPin); in order to get the pin.

And of course, SetMapPinState(oMapPin, TRUE); is the function you would use.

Modifié par Craig Graff, 13 janvier 2010 - 04:14 .


#15
slaaleth

slaaleth
  • Members
  • 71 messages
ok thank's a lot for your answers

#16
slaaleth

slaaleth
  • Members
  • 71 messages
sorry for posting this here but this way I don't create a new topic.

I saw on a screenshot in the wiki in the level editor tutorial and on this screen there is a model name fxp_candlbra which is, I think, the flame for the candle. I search it in the models for add it in my level, but I don't find it... I search in the fxp folder, and then I hide all the folder and I search again, but it isn't here.

Is this model still present on the toolset, or is there another for the flame of a candle?

#17
slaaleth

slaaleth
  • Members
  • 71 messages
it's ok found it

#18
slaaleth

slaaleth
  • Members
  • 71 messages
hem I try to active a map pin in the same script I have unlock the door. so I set the map pin to initial state not active in the map file.
And then I try to add this in the script:

case ALLER_A_LA_CAVERNE:     
            {                          
                object oMapPin=GetObjectByTag("map_main");
                SetMapPinState(oMapPin , TRUE);
                break;
            }

like you tell me in your last post
where map_main is the tag of my pin

The script is exported correctly, but it do nothing in the game, when I update the quest nothing happend and the pin stay hide

is it normal?

#19
Craig Graff

Craig Graff
  • Members
  • 608 messages
Is "map_main" the tag of your map, or your map pin? (It would need to be the map pin in order to work.) Are you certain that the map pin has been assigned a tag (I ask only because there are separate fields for Area Tag and Tag)?

#20
slaaleth

slaaleth
  • Members
  • 71 messages
No it's the right tag, but are you sur this is the parametre TRUE for the SetMapPinState, and not a thing like for the door? something like that: MAP_STATE_PIN_ACTIVE (I don't know if it exist)?

because if you want to set for example the location grayed out instead active, I don't understant how to set the different statement of the pin wit TRUE or FALSE...

Modifié par slaaleth, 19 janvier 2010 - 08:19 .