Jump to content

Home

Scripting riddle


clu

Recommended Posts

Here's (hopefully) an easy one.

 

I have three NPCs, and I want to trigger a script after they are *all* dead (individual deathscripts seem to be out since I don't know which will die last).

 

Any ideas?

 

-clu

Link to comment
Share on other sites

Put a target_counter inside your map. In it's entity window, give it key:count value:3. Next, enter key:usescript value:nameofscript.

Give your target_counter a targetname. For each NPC, in their entity windows, enter key:closetarget value:targetnameoftarget_counter.

Link to comment
Share on other sites

Now that it came into my mind, I can also give you an idea how to make it via scripting, if you insist. Of course it's total waste of time compared to the way War Master explained. (Of course I have used myself the counter method, but anyway. One can always build nice theories).

 

First, perhaps in the player spawnscript, your declare a float variable. Then, in each deathscript of these three unfortunate victims, you add one to the variable (+1). But in addition to that, you also check the current status of the variable. If it has reached some certain value (like 2 in this case, if you start with a zero), you use a scriptrunner to launch the appropriate script, that should be lauched after all the dudes are down.

 

For each NPC, in their entity windows, enter key:closetarget value:targetnameoftarget_counter.

I used NPC_target key, but I guess it makes little difference.

Link to comment
Share on other sites

The counter worked sweet (thanks again War Master), but lassev your post is useful and somehow reminded me of another question related to global variables (which I'm going to post in another thread!)

 

Thanks again.

 

-clu

Link to comment
Share on other sites

Ahh screw it, I'll post it here. I'm definitely new to scripting, so apologies if this is very basic. OK, two questions:

 

1) Are you saying if I define a variable in a script (like my spawnscript), it will persist throughout the whole level? And I can change it's value in other scripts?

 

2) Can I then have dynamic triggers? (have them launch different sections of a Usescript depending on the value of the variable)?

 

-clu

Link to comment
Share on other sites

The target_counter is the best way to go because scripting it can lead to a problem. One objective in my sp map is to destroy 12 imperial mainframes. I originally scripted the counting. After each mainframe is destroyed it would target the target_scriptrunner. I discovered a problem though, if the player destroys more than one at the same time the target_scriptrunner is only run once. On the other hand with a target_counter, you can use a detonator and destroy as many as you want at the same time and it'll keep count.

 

For variables, you have to declare and set them like this.

 

//Generated by BehavEd

 

declare ( /*@DECLARE_TYPE*/ FLOAT, "variablename" );

set ( "variablename", "0" );

 

To increment them:

 

set ( "variablename", "+1" );

Link to comment
Share on other sites

War Master, I'm using your counter and it works like a charm.

 

Just wanted to know about persistent variables and I think you guys answered that too.

 

Thanks for all the help.

 

-clu

Link to comment
Share on other sites

Hey sorry to keep beating this thread to death, but I have a question related to variable persistence and what you mentioned earlier.

 

In my player spawnscript, I define a variable called "03gamestate" to a value of "0"

-------------------------------------------------

declare ( FLOAT, "03gamestate" );

set ( "03gamestate", "0" );

-------------------------------------------------

 

Then, in a later script, I have an "if" statement that runs different scripts depending on the value of "03gamestate"

-------------------------------------------------

if ( get( FLOAT, "03gamestate") = "0" )

{

run ( "colo/L03/fight_brothers" );

}

 

else ( )

{

 

if ( get( FLOAT, "03gamestate") = "1" )

{

run ( "colo/L03/fight_soldiers" );

}

 

else ( )

{

rem ( "do nothing" );

}

}

-------------------------------------------------

 

My problem is that it is not recognizing the value as "0" (not running the scripts). Is this a syntax issue (I notice the use of "$$" to define numbers in other scripts. Do I need those?

 

-clu

Link to comment
Share on other sites

My problem is that it is not recognizing the value as "0" (not running the scripts). Is this a syntax issue (I notice the use of "$$" to define numbers in other scripts. Do I need those?

 

From looking at the SP scripts I think you do need to use the $. Try this out.

 

if ( $get( FLOAT, "03gamestate") = 0$ )

{

run ( "colo/L03/fight_brothers" );

}

 

else ( )

{

 

if ( $get( FLOAT, "03gamestate") = 1$ )

{

run ( "colo/L03/fight_soldiers" );

}

 

else ( )

{

rem ( "do nothing" );

}

}

Link to comment
Share on other sites

  • 3 years later...

Archived

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

×
×
  • Create New...