Jump to content

Home

Trigger Function


TimBob12

Recommended Posts

So I decided that it would be handy to be able to script triggers so I decided to write another function. Currently I have code that compiles but doesn't seem to do anything.

 

Here is what I have:

 

Example.nss

 

#include "trigger"

void main()
{
   float x = -31.06730;
   float y = 111.57073;
   float z = 12.75084;
   float orient = 0.0;

   vector test = Vector(x,y,z);

   location test2 = Location(test, orient);
   string script = "debug_script";

   new_trigger(test2, 10.0, script);
}

 

Trigger.nss:

 

#include "k_inc_generic"
#include "k_inc_utility"

void new_trigger(location loc, float radius, string Action)
{
   object trigger = GetFirstObjectInShape(SHAPE_SPHERE, radius, loc, FALSE, OBJECT_TYPE_CREATURE);
   object oPC = GetFirstPC();

   while (GetIsObjectValid(trigger))
   {
      if (trigger == oPC)
      {
         ExecuteScript(Action, OBJECT_SELF);  
      }
      else
      {
         trigger = GetNextObjectInShape(SHAPE_SPHERE, radius, loc, FALSE, OBJECT_TYPE_CREATURE);
      }
   }
}


//Ignore this for now
void destroy_trigger()
{
}

 

Debug_script.nss

 

void main()
{
  object oPC = GetFirstPC();
  SendMessageToPC(oPC, "The trigger worked!!!!");
}

 

In theory this should work and it all compiles fine but no message comes through.

 

Any ideas people?

Link to comment
Share on other sites

Glad you decided to give this a try...good luck..I know nothing about scripting...did you put all the .ncs scripts in override or your .mod file....how are you injecting this script into the module..on enter? or on an npc? Maybe your saved game you are using is the problem?

Link to comment
Share on other sites

Now, I know next to nothing about scripting, so I may well be talking out of my backside here, but I'm not familiar with the 'string script' part in the first piece of code you posted. Would it make a difference if you used the ExecuteScript() command instead?

 

Also, in your script, you refer to the debug script as "debug_script" whereas later you call it "Debug_script" with a capital D on debug.. I think the name of the ncs has to EXACTLY match what you refer to it as In the script?

 

Of course, I may just be talking crap. :)

 

(sorry if this is poorly written, it was done on my phone)

Link to comment
Share on other sites

Now, I know next to nothing about scripting, so I may well be talking out of my backside here, but I'm not familiar with the 'string script' part in the first piece of code you posted. Would it make a difference if you used the ExecuteScript() command instead?

 

Also, in your script, you refer to the debug script as "debug_script" whereas later you call it "Debug_script" with a capital D on debug.. I think the name of the ncs has to EXACTLY match what you refer to it as In the script?

 

Of course, I may just be talking crap. :)

 

(sorry if this is poorly written, it was done on my phone)

 

The string script just defines a text variable which passes the name of your script to the ExecuteScript() command in the trigger so that people can pass any script they want to run in its parameters.

 

The second refferal to Debug_script.nss was me just being too gramitacally correct :p

 

 

 

I am running the script through an NPCs dialogue. and all the .ncs files are in my .mod

Link to comment
Share on other sites

It may be because you've got the script identified by two different identifiers. In example.nss, it's identified as script, but in trigger.nss it's identified as Action.

 

As in:

string [b]script[/b] = "debug_script";

 

But:

 

void new_trigger(location loc, float radius, [b]string Action[/b])

...

   ExecuteScript([b]Action[/b], OBJECT_SELF);  

 

If I've read this right, anyway.

Link to comment
Share on other sites

I'm sorry, I'm not seeing any connexion between the two in the scripts you've provided. So far as I can see, string script = "debug_script"; says that the item "debug_script" is to be treated as an object of the type string, called script. It's the same as putting:

 

object oPC = GetObjectByTag("object_tag");

 

You're not actually telling the script to do anything with it, you've just defined it in the context of that script.

 

In your trigger include file, string Action is looking for a string called Action. You're providing a string called script. The identifier string in both cases is just the type of thing being looked for.

Link to comment
Share on other sites

I am putting the contents of string through the function as Actiton. The trigger then takes the content of action, in this case it is the same as the content of string which is "debug_script". The trigger function takes the content of action and executes a script that has the same name as what is stored in the action variable.

Link to comment
Share on other sites

I never said string was a function I am declaring string to pass it to a function with its contents. I will try it your way but this method is what I used before.

 

This example from cplusplus.com shows how two variables can be substituted into a custom function in place of raw bits of data

 

int main ()
{
 [b][u]int x=5, y=3, z;
 z = subtraction (7,2);[/b][/u]
 cout << "The first result is " << z << '\n';
 cout << "The second result is " << subtraction (7,2) << '\n';
 cout << "The third result is " << [u][b]subtraction (x,y)[/b][/u] << '\n';
 [b][u]z= 4 + subtraction (x,y);[/b][/u]
 cout << "The fourth result is " << z << '\n';
 return 0;
}

 

I don't quite understand what you are saying. Probably my fault though as I can be a bit stupid and ignorant to the blazing obvious. :p

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...