Aller au contenu

Photo

Appeal for help from a rubbish scripter


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

#26
Clyordes

Clyordes
  • Members
  • 300 messages
Sure - here you go: please try not to point & laugh! :-)



void main()

{



object oPC = GetLastPerceived();



if (!GetIsPC(oPC)) return;



if (!GetLastPerceptionSeen()) return;

int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));



if (DoOnce==TRUE) return;



SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);



object oTarget;

oTarget = GetObjectByTag("cult_guard1");



AssignCommand(oTarget, ClearAllActions());



AssignCommand(oTarget, ActionOpenDoor(GetObjectByTag("guard_door_1")));



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("guard_wp")));



oTarget = GetObjectByTag("guard_door_2");



AssignCommand(oTarget, ActionOpenDoor(oTarget));



oTarget = GetObjectByTag("guard_door_3");



AssignCommand(oTarget, ActionOpenDoor(oTarget));



oTarget = GetObjectByTag("guard_door_4");



AssignCommand(oTarget, ActionOpenDoor(oTarget));



oTarget = GetObjectByTag("reinforcement_1");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp1")));



oTarget = GetObjectByTag("reinforcement_2");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp2")));



oTarget = GetObjectByTag("reinforcement_3");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp3")));



oTarget = GetObjectByTag("reinforcement4_");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp4")));



oTarget = GetObjectByTag("reinforcement_5");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp5")));



oTarget = GetObjectByTag("reinforcement_6");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp6")));



oTarget = GetObjectByTag("reinforcement_7");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp7")));



oTarget = GetObjectByTag("reinforcement_8");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp8")));



oTarget = GetObjectByTag("reinforcement_9");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp9")));



oTarget = GetObjectByTag("reinforcement_10");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp10")));



oTarget = GetObjectByTag("reinforcement_11");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp11")));



oTarget = GetObjectByTag("reinforcement_12");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp12")));



oTarget = GetObjectByTag("cult_guard1");



AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp13")));





oTarget = GetObjectByTag("cult_guard1");



AdjustReputation(oPC, oTarget, -100);



}

#27
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Here's a script for you, seemed to work ok for me tested in game with a simple setup, tested with this script in the first guards OnPerception script slot. You will need to change the various delay times so that actions sync up as they should (the number value after the different DelayCommand calls - the number represent real time seconds, ie. 2.0 = 2 seconds, 2.3 = 2.3 seconds). You can't delay seperate commands to the exact same delay time, so do it with tenths of a second differences if you want them to happen at the "same time."  It would have to be a quite exceptional player to notice something happening one-tenth of a second after something else happens. Note these delays are measured starting from when the script fires, not from when the last command was called or delayed:

void main()
{
object oPC = GetLastPerceived();

// Only continue script if Last Percieved is an actual PC
if (!GetIsPC(oPC)) return;

// Only continue script if Last Percieved was seen
if (!GetLastPerceptionSeen()) return;

int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));

// If done once already, do not do again
if (DoOnce==TRUE) return;

// Set local int so this will only be done once if script fired off again in future
SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);

object oTarget;

// Have first guard run to door and open it
oTarget = GetObjectByTag("cult_guard1");
AssignCommand(oTarget, ClearAllActions());
AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("guard_door_1"), TRUE));
DelayCommand(2.0, AssignCommand(oTarget, ActionOpenDoor(GetObjectByTag("guard_door_1"))));

// Have the other 3 doors open themselves
int nDoor;
for(nDoor = 2; nDoor < 5; nDoor++)
      {
      oTarget = GetObjectByTag("guard_door_" + IntToString(nDoor));
      DelayCommand(4.0, AssignCommand(oTarget, ActionOpenDoor(oTarget)));
      }
 
// Have other reinforcement guards move to their WPs
int nGuard;
for (nGuard = 1; nGuard < 13; nGuard++)
      {
      oTarget = GetObjectByTag("reinforcement_" + IntToString(nGuard));
      AssignCommand(oTarget, ClearAllActions());
      DelayCommand(5.1, AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp" + IntToString(nGuard)), TRUE)));
      }
 
// Have the original guard move to WP and turn his entire faction hostile towards PC
oTarget = GetObjectByTag("cult_guard1");
AssignCommand(oTarget, ClearAllActions());
DelayCommand(5.5, AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("reinforcement_wp13"), TRUE)));
DelayCommand(7.0, AdjustReputation(oPC, oTarget, -100)); 
}

Modifié par _Knightmare_, 04 janvier 2011 - 05:04 .


#28
Clyordes

Clyordes
  • Members
  • 300 messages
Many thanks, I only had a few minutes to test it last night, so I'm not sure of all the details, but I may have missed something obvious.

The guard opened the door fine & seemed to carry out his instructions ok, and the other doors opened ok too, but I'm sure only one reinforcement turned up.



The rest stayed in their rooms. Do I have to copy parts of the script to cover the other guards too? Be aware that when I get more time later in the week I'll be able to check that something daft hasn't happened, like all the reinforcements having the same tag!

#29
SkywingvL

SkywingvL
  • Members
  • 351 messages
If you want to perform multiple actions within a DelayCommand code snippet, you can simple call a function that returns void and takes nothing which you define in your script. For example:




void DoMyCommands()
{
 DoSomething();
 DoSomethingElse();
}

DelayCommand(timeout, DoMyCommands());



This is generally preferable to just adding small increments to the delay time unless you really need each DelayCommand fragment to really have time pass between the next one.

#30
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

Clyordes wrote...

Many thanks, I only had a few minutes to test it last night, so I'm not sure of all the details, but I may have missed something obvious.
The guard opened the door fine & seemed to carry out his instructions ok, and the other doors opened ok too, but I'm sure only one reinforcement turned up.

The rest stayed in their rooms. Do I have to copy parts of the script to cover the other guards too? Be aware that when I get more time later in the week I'll be able to check that something daft hasn't happened, like all the reinforcements having the same tag!


If only a single guard is moving, then yes, my guess is that either they all have the same tag (and the script is randomly grabbing just one of them) or the others have incorrect tags. I used your code as a base and tagged/numbered my test guards "reinforcement_1" through "reinforcement_12" - the other possibility is that the tags of the waypoints they are supposed to move to are incorrectly set. In my own testing all 13 guards definately came running and I had to fight them when they arrived. I can send you my little test module if you need it, its very small, just the one test area.

Modifié par _Knightmare_, 05 janvier 2011 - 11:59 .


#31
Clyordes

Clyordes
  • Members
  • 300 messages
No worries, I'm sure it's something obvious like all having the same tag or similar for the waypoints, if I can't make any progress later in the week I may take you up though!



Skywing? I'm honoured! But aren't you supposed to be doing something something super important rather than helping a lowly noob? ;-)

Also, when I finally get my head round scripting I may have an idea what you're telling me, but I'm afraid at the mo it doesn't mean much to me - sorry!

#32
Clyordes

Clyordes
  • Members
  • 300 messages
Hi again,

I've just created a small test area with all the scripted bits - initial guard, reinforcements, doors, waypoints - and it works fine (& I understand the timing better now too) - many thanks, Knightmare.



Only remaining problem is getting it to work in the dungeon I set up.

One thing I'm wondering - would the reinforcements need a clear line of sight to their waypoints? I'm presuming not, but I've checked all the reinforcements and waypoints & they're all showing the same tags as I used in the test area, so I'm a bit baffled as to why its not working - any obvious things that may be causing problems?



Cly

#33
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
NP. Yes, the function ActionMoveToObject() needs a clear/open pathway between the starting and ending points. If there is not one, the function does nothing (ie. the NPC will not move at all).

#34
Clyordes

Clyordes
  • Members
  • 300 messages
Ah - that'll be it then - the reinforcements are in groups of 4, each group in a 1 tile sized room with one door that needs to be opened. And the corridor to their waypoints is a little twisty turny too.



Any ideas?



How about multiple commands - each one to a waypoint they can see from the previous one? Any obvious reason why that wouldn't work?

#35
Clyordes

Clyordes
  • Members
  • 300 messages
Ok, this is odd...

I amended the script that knightmare put up here & it worked well in an outdoor test area with a bunch of deep gnomes fetched by an ogre with a couple of gateways to simulate the doors the reinforcements have to rush through. Most came through & made it to their first and second waypoints, despite not having a clear line of sight to them. The ones that didn't I'm presuming got stopped by being held up by their buddies - I can live with that.



So I tried the same script in my dungeon & suddenly although 3 of the initial guards attack fine but the chap who's supposed to run & get help is completely immobile & apparently oblivious - doesn't go for help at all. I copied him to the test area & he works flawlessly there, so I was thinking maybe a tag had got changed so didn't know where to go, but I can't see anything wrong. Anyone know any reasons why an on perception script might suddenly fail to fire?

#36
PJ156

PJ156
  • Members
  • 2 980 messages
Just a thought as this is what happened to me. Is the onperc script clashing with qanything in the on heartbeat script?

PJ

#37
Clyordes

Clyordes
  • Members
  • 300 messages
Hi PJ, thanks for the idea but I don't think there are any heartbeat scripts in the mod, although I think you're right, something must be conflicting in my general mod that's not in the test mod even though the latter is exactly the same as the former but with most of the areas stripped out