Aller au contenu

Photo

Script compiles but not working with placeable


7 réponses à ce sujet

#1
Sonmeister

Sonmeister
  • Members
  • 167 messages
My script below is attached to a placeable and I have a creature with Active set to False.  When you click on the placeable nothing happens.  Am I missing something, perhaps a variable on the placeable or script that I need to set?

#include "placeable_h"

const string SARC_UNDEAD = "my_ruins_undead";

void main()
{
    event ev     = GetCurrentEvent();
    int   nEvent = GetEventType(ev);
    int nEventHandled = FALSE;          //keep track of whether the event has been handled
   
switch (nEvent)
    {
        //---------------------------------------------------------------------
        //  Sent by engine when creature clicks on the placeable.
        //---------------------------------------------------------------------
        case EVENT_TYPE_USE:

        object oCreature = GetObjectByTag(SARC_UNDEAD);
        SetObjectActive(oCreature, TRUE);               //your special code goes here

            nEventHandled = TRUE;

            break;
    }
    if (!nEventHandled) //If this event wasn't handled by this script, let the core script try
    {
        HandleEvent(ev, RESOURCE_SCRIPT_PLACEABLE_CORE);
    }
}

#2
Phaenan

Phaenan
  • Members
  • 315 messages
You're missing an opening { after the case statement but if it does compile properly that prolly a typo in here. The code looks correct other than that, maybe the placeable was spawned before the handler script was defined in its resource ? If that's the case you'll want to destroy/respawn it anew.

#3
Sonmeister

Sonmeister
  • Members
  • 167 messages
"you'll want to destroy/respawn it anew"



Is this something I need to add to the script then? Can you show me an example?

#4
DavidSims

DavidSims
  • BioWare Employees
  • 196 messages
Possibilities I can think of:



1. The script isn't hooked up to the placeable

2. The placeable or the script hasn't been exported

3. The tag is incorrect

4. There is more than one creature with that tag

5. The pc isn't getting close enough to the placeable, and no use event is firiing.



The script compiles, so number 2 seems unlikely, and you said the script is hooked up, so if you double check that we can eliminate 1. If the player is walking up and you've clicked multiple times, 3 probably isn't the issue.

After double checking the tags, my next move would be to make the script is running at all, and see if you can get that script to do something. Log messages would work if you know how to use them. You could also put some simple actions, maybe a SetObjectInteractive(OBJECT_SELF, FALSE), to see if you can still click on it. If you can’t get the script to do anything at all, then you know the problem isn’t inside the script.

#5
DavidSims

DavidSims
  • BioWare Employees
  • 196 messages
Just a question relating to Phaenan's advice, is this an object placed in your own area, or an object spawned into the main campaign using PRCSCR/area load scripts? Also, are you testing from a save game, or starting fresh when you test?

#6
Sonmeister

Sonmeister
  • Members
  • 167 messages
While I was waiting for some replies I re-vamped the script below and it works but I'm still confused as to why the other one would not work. I don't know how to use logs and I'm not sure if I could decipher them anyway.

// Working Script

#include "placeable_h"

//const string SARC_UNDEAD = "my_ruins_undead";
const int SARC_UNDEAD = 15;
void main()
{
event ev = GetCurrentEvent();
int nEvent = GetEventType(ev);
int nEventHandled = FALSE; //keep track of whether the event has been handled
switch (nEvent)
{
//---------------------------------------------------------------------
// Sent by engine when creature clicks on the placeable.
//---------------------------------------------------------------------
case EVENT_TYPE_USE:

//object oCreature = GetObjectByTag(SARC_UNDEAD);
// SetObjectActive(oCreature, TRUE); //your special code goes here
UT_TeamAppears(SARC_UNDEAD);

nEventHandled = TRUE;
break;
}
if (!nEventHandled) //If this event wasn't handled by this script, let the core script try
{
HandleEvent(ev, RESOURCE_SCRIPT_PLACEABLE_CORE);
}
}

Modifié par Sonmeister, 31 mai 2010 - 11:59 .


#7
Sonmeister

Sonmeister
  • Members
  • 167 messages
The object is a placeable set into my own area and I am using a savegame but I am in a different area and traveling to my area. I've run into the issue of making changes and not seeing them and being perplexed enough to have finally learned not to use a savegame in my area.

EDITED:

DavidSims,
I did as you suggested and added this line and when you click on the object it goes non-interactive as prescribed.

SetObjectInteractive(OBJECT_SELF, FALSE)

So the script seems to be working fine except to make the creature activate.

Modifié par Sonmeister, 31 mai 2010 - 11:46 .


#8
Phaenan

Phaenan
  • Members
  • 315 messages

Sonmeister wrote...
The object is a placeable set into my own area and I am using a savegame but I am in a different area and traveling to my area. I've run into the issue of making changes and not seeing them and being perplexed enough to have finally learned not to use a savegame in my area.


I'm not clear on how objects work in areas, but I guess the objects are actually spawned into the gameworld upon the first visit in the area. So if you saved your game before the script was hooked to the placeable resource and use this savegame for your next tests, I'd say the placeable object remained hooked to its previous handler.
If that's the case, you can destroy it easily with a simple script called via the console but then again I'm not sure how to make it respawn at the right place. (got experience with dynamically spawned stuff, not with custom areas)


// Edit :
Oh, seeing what you just wrote above that's not it, your script triggers just fine. :o

Modifié par Phaenan, 31 mai 2010 - 11:55 .