Aller au contenu

Photo

Script doesn't quite work


12 réponses à ce sujet

#1
Sonmeister

Sonmeister
  • Members
  • 167 messages
In my earlier post I was having problems getting the placeable when clicked on to make a creature appear with
SetObjectActive(oCreature, TRUE), so I wrote the script below which works to make the creatures appear but they do not attack.  They are hostile but just stand and make mean gestures (not with that finger either)...   any ideas?




// 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);
}
}

#2
TimelordDC

TimelordDC
  • Members
  • 923 messages
Maybe the PC is outside their perception range? Do they attack if you move closer to them?

#3
Phaenan

Phaenan
  • Members
  • 315 messages
Actually I'm not quite sure that perception is initialized during EVENT_TYPE_SPAWN, as the creature_core doesn't seem to do anything about that during the spawn handling. Don't necessarily trust me on that, tho, could have missed something or it may be handled in the ambient system provided it's enabled for that creature.
But if I'm not totally off the mark you may want to push a command attack down that creature queue after it's spawned. Something like that~ish :
WR_AddCommand(OBJECT_SELF, CommandAttack(GetMainControlled()));

TimelordDC wrote...
Maybe the PC is outside their perception range? Do they attack if you move closer to them?


Normally the party members should drop into combat stance if the hostile creature is close enough when it spawns ; if they don't then the spawn point is prolly too far away indeed. :o

Modifié par Phaenan, 01 juin 2010 - 01:58 .


#4
BillHoyt

BillHoyt
  • Members
  • 109 messages
An addendum to Timelord's question, does the "battle music" kick on (if you have it assigned)?

#5
DavidSims

DavidSims
  • BioWare Employees
  • 196 messages
One thing that can cause a creature to be hostile but not attack is if there isn't valid pathfinding between it and the player. You can quickly check where the valid pathfinding is in the area by selecting view - environment - pathfnding points.



The other main thing to check is that the creature is using creature_core. If it has a custom script, make sure the custom script is allowing all events to pass down to creature_core.



If you're not entering combat mode at all, then the PC's group and the creature's group probably aren't hostile to each other. Can the PC attack other creatures placed in the area that are in the hostile group?

#6
Sonmeister

Sonmeister
  • Members
  • 167 messages
First to answer TimeLord, I got in their faces and they still didn't attack.
Phaenan I tried adding WR_AddCommand(OBJECT_SELF, CommandAttack (GetMainControlled())); which compiled fine but had no visible affect. Then I got to thinking maybe I should make a creature script (after reading DavidSims post) and add your suggested line to that script instead of the placeable script and still no luck.
BillHoyt I haven't been using sound so I don't know but the player assumes the position of battle as soon as the creatures are summoned.
DavidSims I checked the pathfinding points and they are all green I wondered about the pathfinding earlier so I moved the creature and the placeable and tried various placements and then added 3 more creatures so the player is essentially surrounded and still get the same result from all creatures. My custom script does fall through to the creature_core but I wasn't using a script until I took Phaenan's advice and tried some other things. The PC assumes the battle position (as said above) on spawn of the creature.
Even though the creatures appear hostile I tried adding UT_TeamGoesHostile (TEAM_MY_CREATURE, TRUE); to the creature script and it didn't change anything.

I'm running out of ideas...

EDITED:  So I moved the placeable and creatures from my outdoor area to an indoor area and the creatures are all acting appropriately.  They are quite violent.  The first script using

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

still compiles but does nothing but the one using

  case EVENT_TYPE_USE:
UT_TeamAppears(SARC_UNDEAD);

Works fine.

Modifié par Sonmeister, 01 juin 2010 - 11:25 .


#7
DavidSims

DavidSims
  • BioWare Employees
  • 196 messages
I'm quite baffled by your problem. I have no idea why the area itself is causing a difference, or why grabbing the object by tag isn't working.



Is it possible that something is happening in the one area but not the other, maybe a trigger you run through or something on the area script? Some thing that's effecting either the hostility of the group or somehow altering the creatures in any way? Do both areas have a script, either area_core or something that falls through to that? Maybe that's affecting the spawn/levelup behavior?



The only other thing I can think of is the combatant flag on the creatures. A creature flagged as combatant false won't fight properly. However, that's set on the template, so moving the creatures between areas shouldn't affect that.

#8
TimelordDC

TimelordDC
  • Members
  • 923 messages
Is it possible that having an entry in the areadata.xls with min and max level not specified for that area would result in creatures unable to attack due to uninitialized stats?



I still don't understand why GetObjectByTag doesn't work. Are you sure you don't have more than one creature with the same tag in the area (or arealist)? You can do a quick check by using GetObjectsInArea and checking the arraysize (use PrintToLog to output the value). You can also add a couple of check conditions in the script - IsObjectValid (after you get the creature object using tag) and IsObjectHostile (after setting it active) and see what they return.

#9
Sonmeister

Sonmeister
  • Members
  • 167 messages
DavidSims there is no trigger to run through but there is a stage. I don't think it overlaps into the spot of the placeable though. There is no area scripts on either area. The creature template is set as _hostile.



Timelord I have one creature with the tag in the area but another area I have some others with the same tag. So I will try deleting those and see if the GetObjectByTag version works and get back to you guys.



I may make up a little area for conducting experiments at some point. I've been thinking about it for awhile. To test scripts and stuff for my mod. The GetObjectByTag has been purplexing but I'm so new to scripting I don't always know what to expect. Sometimes I'm just happy to see them compile after I write them.

#10
TimelordDC

TimelordDC
  • Members
  • 923 messages
You can also try using UT_GetNearestObjectByTag instead of GetObjectByTag and see if that works (if you need same-tagged creatures in another area within the area list)

#11
Sonmeister

Sonmeister
  • Members
  • 167 messages
TimeLord,

I made up a new creature and used the script with
case EVENT_TYPE_USE:
object oCreature =GetObjectByTag(SARC_UNDEAD);
SetObjectActive(oCreature, TRUE); //your special code goes here

and it worked fine. So I think you nailed it for me. I had some of the same instances of the undead creatures in a different area not thinking it would matter (not thinking about area list tying it all together).

So the bonus is now that I have two scripts that work I'm starting to feel a little more confident in my scripting (except for the dumb things I either take for granted or don't realize from a lack of understanding, of course).

Is there logical reasoning over using GetNearestObjectByTag over UT_TeamAppears? Or is it all tied to the number of creatures your grabbing?

And BTW, thanks guys.

Modifié par Sonmeister, 02 juin 2010 - 11:38 .


#12
CID-78

CID-78
  • Members
  • 1 124 messages
GetNeareatObjectByTag() get the nearest object which also mean that there can be more object and the script can be reused several times, while the team is a one time deal because you can only have a team once and the last also loop through all members.

Modifié par CID-78, 03 juin 2010 - 01:00 .


#13
Sonmeister

Sonmeister
  • Members
  • 167 messages
Thanks CID.