Skip to content

Commit

Permalink
Refactor the hotspot scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
zit-hb authored and EmpSurak committed Oct 13, 2024
1 parent 24eff4a commit f3f2af2
Show file tree
Hide file tree
Showing 98 changed files with 5,413 additions and 6,189 deletions.
41 changes: 23 additions & 18 deletions Data/Scripts/hotspots/activate_characters.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Name: activate_characters.as
// Developer: Wolfire Games LLC
// Script Type: Hotspot
// Description:
// License: Read below
//-----------------------------------------------------------------------------
//
Expand All @@ -23,31 +22,37 @@
//-----------------------------------------------------------------------------

void SetParameters() {
params.AddString("characters", "");
params.AddString("characters", "");
}

void HandleEvent(string event, MovementObject @mo){
if(event == "enter"){
void HandleEvent(string event, MovementObject@ mo) {
if (event == "enter") {
OnEnter(mo);
}
}

void OnEnter(MovementObject@ mo) {
if (!mo.controlled || !params.HasParam("characters")) {
return;
}

ActivateCharacters();

if (params.HasParam("music_layer_override")) {
int override = params.GetInt("music_layer_override");
level.SendMessage("music_layer_override " + override);
}
}

void OnEnter(MovementObject @mo) {
if(mo.controlled && params.HasParam("characters")){
TokenIterator token_iter;
token_iter.Init();
string str = params.GetString("characters");
while(token_iter.FindNextToken(str)){
int id = atoi(token_iter.GetToken(str));
if(ObjectExists(id) && ReadObjectFromID(id).GetType() == _movement_object){
ReadCharacterID(id).Execute("this_mo.static_char = false;");
}
}
void ActivateCharacters() {
TokenIterator token_iter;
token_iter.Init();
string str = params.GetString("characters");

if(params.HasParam("music_layer_override")){
int override = params.GetInt("music_layer_override");
level.SendMessage("music_layer_override "+override);
while (token_iter.FindNextToken(str)) {
int id = atoi(token_iter.GetToken(str));
if (ObjectExists(id) && ReadObjectFromID(id).GetType() == _movement_object) {
ReadCharacterID(id).Execute("this_mo.static_char = false;");
}
}
}
94 changes: 48 additions & 46 deletions Data/Scripts/hotspots/adv_dialogue.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Name: adv_dialogue.as
// Developer: Wolfire Games LLC
// Script Type: Hotspot
// Description:
// License: Read below
//-----------------------------------------------------------------------------
//
Expand Down Expand Up @@ -30,63 +29,66 @@ void Reset() {

void Init() {
Reset();
//vec3 end = char.rigged_object().GetAvgIKChainPos("torso");
}

void SetParameters() {
params.AddIntCheckbox("Play Once", true);
params.AddIntCheckbox("Play Only If Dead", false);
params.AddIntCheckbox("Play for NPCs", false);

params.AddIntCheckbox("Play Once", true);
params.AddIntCheckbox("Play Only If Dead", false);
params.AddIntCheckbox("Play for NPCs", false);
params.AddString("Lethal Dialogue", "Default text");
params.AddString("Medium Dialogue", "Default text");
params.AddString("Non Lethal Dialogue", "Default text");
}

void HandleEvent(string event, MovementObject @mo){
if(event == "enter"){
void HandleEvent(string event, MovementObject@ mo) {
if (event == "enter") {
OnEnter(mo);
} else if(event == "exit"){
OnExit(mo);
}
}

void OnEnter(MovementObject @mo) {
if((mo.GetIntVar("knocked_out") > 0 || params.GetInt("Play Only If Dead") == 0) //condition for "Play Only If Dead"
&& (!played || params.GetInt("Play Once") == 0) //condition for "Play once"
&& (mo.controlled || params.GetInt("Play for NPCs") == 1)){ //condition for "Play for NPCs"

int num_chars = GetNumCharacters();
bool everyone_alive = true;
bool everyone_dead = true;
for(int i=0; i<num_chars; ++i){ //check all character if they are alive
MovementObject @char = ReadCharacter(i);
if(!char.controlled && !mo.OnSameTeam(char)){
if(char.GetIntVar("knocked_out") == _dead){
everyone_alive = false;
Log(warning, "dude is dead");
} else {
everyone_dead = false;
Log(warning, "dude is alive");
}
} else {
Log(warning, "this is the player char");
}
}

if(everyone_alive){ //branches for different lethal states
Log(warning, "everyone's alive");
level.SendMessage("start_dialogue \""+params.GetString("Non Lethal Dialogue")+"\"");
} else if(everyone_dead){
Log(warning, "everyone's dead");
level.SendMessage("start_dialogue \""+params.GetString("Lethal Dialogue")+"\"");
} else {
Log(warning, "some survived");
level.SendMessage("start_dialogue \""+params.GetString("Medium Dialogue")+"\"");
}
played = true;
void OnEnter(MovementObject@ mo) {
if (!ShouldPlayDialogue(mo)) {
return;
}

PlayDialogue(mo);
played = true;
}

bool ShouldPlayDialogue(MovementObject@ mo) {
if (params.GetInt("Play Only If Dead") != 0 && mo.GetIntVar("knocked_out") <= 0) {
return false;
}
if (played && params.GetInt("Play Once") != 0) {
return false;
}
if (!mo.controlled && params.GetInt("Play for NPCs") == 0) {
return false;
}
return true;
}

void OnExit(MovementObject @mo) {
}
void PlayDialogue(MovementObject@ mo) {
int num_chars = GetNumCharacters();
bool everyone_alive = true;
bool everyone_dead = true;

for (int i = 0; i < num_chars; ++i) {
MovementObject@ char = ReadCharacter(i);
if (!char.controlled && !mo.OnSameTeam(char)) {
if (char.GetIntVar("knocked_out") == _dead) {
everyone_alive = false;
} else {
everyone_dead = false;
}
}
}

if (everyone_alive) {
level.SendMessage("start_dialogue \"" + params.GetString("Non Lethal Dialogue") + "\"");
} else if (everyone_dead) {
level.SendMessage("start_dialogue \"" + params.GetString("Lethal Dialogue") + "\"");
} else {
level.SendMessage("start_dialogue \"" + params.GetString("Medium Dialogue") + "\"");
}
}
99 changes: 51 additions & 48 deletions Data/Scripts/hotspots/adv_dialogue_kocheck.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Name: adv_dialogue_kocheck.as
// Developer: Wolfire Games LLC
// Script Type: Hotspot
// Description:
// License: Read below
//-----------------------------------------------------------------------------
//
Expand Down Expand Up @@ -30,66 +29,70 @@ void Reset() {

void Init() {
Reset();
//vec3 end = char.rigged_object().GetAvgIKChainPos("torso");
}

void SetParameters() {
params.AddIntCheckbox("Play Once", true);
params.AddIntCheckbox("Play Only If Dead", false);
params.AddIntCheckbox("Play for NPCs", false);
params.AddIntCheckbox("Play If No Combat", true);

params.AddIntCheckbox("Play Once", true);
params.AddIntCheckbox("Play Only If Dead", false);
params.AddIntCheckbox("Play for NPCs", false);
params.AddIntCheckbox("Play If No Combat", true);
params.AddString("All Enemies Neutralized", "Default text");
params.AddString("Some Enemies Neutralized", "Default text");
params.AddString("No Enemies Neutralized", "Default text");
}

void HandleEvent(string event, MovementObject @mo){
if(event == "enter"){
void HandleEvent(string event, MovementObject@ mo) {
if (event == "enter") {
OnEnter(mo);
} else if(event == "exit"){
OnExit(mo);
}
}

void OnEnter(MovementObject @mo) {
if((mo.GetIntVar("knocked_out") > 0 || params.GetInt("Play Only If Dead") == 0) //condition for "Play Only If Dead"
&& (!played || params.GetInt("Play Once") == 0) //condition for "Play once"
&& (mo.controlled || params.GetInt("Play for NPCs") == 1) //condition for "Play for NPCs"
&& (mo.QueryIntFunction("int CombatSong()") == 0) || params.GetInt("Play If No Combat") == 0){ //condition for No Combat
void OnEnter(MovementObject@ mo) {
if (!ShouldPlayDialogue(mo)) {
return;
}

PlayDialogue(mo);
played = true;
}


int num_chars = GetNumCharacters();
bool everyone_alive = true;
bool everyone_dead = true;
for(int i=0; i<num_chars; ++i){ //check all character if they are alive
MovementObject @char = ReadCharacter(i);
if(!char.controlled && !mo.OnSameTeam(char)){
if(char.GetIntVar("knocked_out") > 0){
everyone_alive = false;
Log(warning, "dude is ko");
} else {
everyone_dead = false;
Log(warning, "dude is conscious");
}
} else {
Log(warning, "this is the player char");
}
}

if(everyone_alive){ //branches for different security states
Log(warning, "everyone's alive");
level.SendMessage("start_dialogue \""+params.GetString("No Enemies Neutralized")+"\"");
} else if(everyone_dead){
Log(warning, "everyone's dead");
level.SendMessage("start_dialogue \""+params.GetString("All Enemies Neutralized")+"\"");
} else {
Log(warning, "some survived");
level.SendMessage("start_dialogue \""+params.GetString("Some Enemies Neutralized")+"\"");
}
played = true;
bool ShouldPlayDialogue(MovementObject@ mo) {
if (params.GetInt("Play Only If Dead") != 0 && mo.GetIntVar("knocked_out") <= 0) {
return false;
}
if (played && params.GetInt("Play Once") != 0) {
return false;
}
if (!mo.controlled && params.GetInt("Play for NPCs") == 0) {
return false;
}
if (params.GetInt("Play If No Combat") != 0 && mo.QueryIntFunction("int CombatSong()") != 0) {
return false;
}
return true;
}

void OnExit(MovementObject @mo) {
}
void PlayDialogue(MovementObject@ mo) {
int num_chars = GetNumCharacters();
bool all_conscious = true;
bool all_neutralized = true;

for (int i = 0; i < num_chars; ++i) {
MovementObject@ char = ReadCharacter(i);
if (!char.controlled && !mo.OnSameTeam(char)) {
if (char.GetIntVar("knocked_out") > 0) {
all_conscious = false;
} else {
all_neutralized = false;
}
}
}

if (all_conscious) {
level.SendMessage("start_dialogue \"" + params.GetString("No Enemies Neutralized") + "\"");
} else if (all_neutralized) {
level.SendMessage("start_dialogue \"" + params.GetString("All Enemies Neutralized") + "\"");
} else {
level.SendMessage("start_dialogue \"" + params.GetString("Some Enemies Neutralized") + "\"");
}
}
Loading

0 comments on commit f3f2af2

Please sign in to comment.