GetIsDay Question
Zephirius
Member Posts: 419
Trying to spawn a critter when entering an area, only if it is day time. I'm not seeing my spawn. When entering the game the clock is automatically set to 13:00 hours - daytime. Still no spawn.
Looked on the lexicon but didn't see anything informative...
Thanks for any help.
Looked on the lexicon but didn't see anything informative...
Thanks for any help.
void main()
{
object oPC = GetEnteringObject();
if (GetIsPC(oPC)) return;
location lLoc = GetLocation(GetWaypointByTag("ZUG_ZUG_LOC"));
if (GetIsDay())
{
CreateObject(OBJECT_TYPE_CREATURE, "bullywug004", lLoc);
}
}
Post edited by Zephirius on
0
Comments
NESS is one I have used for quite sometime:
https://neverwintervault.org/project/nwn1/script/neshkes-extendable-spawning-system-ness-v813
You are returning when it is the PC that is detected. Removing the 'return;' and instead adding a '{}' pair gives -
void main() { object oPC = GetEnteringObject(); if(GetIsPC(oPC)) { location lLoc = GetLocation(GetWaypointByTag("ZUG_ZUG_LOC")); if(GetIsDay()) { CreateObject(OBJECT_TYPE_CREATURE, "bullywug004", lLoc); } } }which, assuming everything else is correct, should work.
TR
The simplest fix is to set a flag (local int) on the area when the creature spawns. If that's set, don't spawn another one.
A more robust fix (which only needs coding once per module) is
Triggers can also check the "loading saved game" flag, leaving it to the area to clear it (triggers fire first).
Occasionally, there may be OnEnter actions that are required for both loads and normal entry - for example, scripted tweaks to sound / lighting. Do those before checking the flag, obviously.
This is for SP - multiplayer might need a more sophisticated solution.
Yep, I missed the !
The actors:
Character 1. Strong Zug-Zug - impossible for a 1st level character to topple
Character 2. Weak & Poisoned Zug-Zug
Intententions for my really bad scripting...
Only Spawn Strong Zug-Zug at night. If Strong Zug-Zug is poisoned only spawn weak Zug-Zug during day time. That's it.
As it stands, the behavior of my code results in Strong Zug-Zug spawning during the day except when poisoned. What doesn't happen is weak Zug-Zug spawning in after Strong Zug-Zug is poisoned...
void main() { object oTarget; object oSpawn; // Get the creature who triggered this event. object oPC = GetEnteringObject(); // Only fire for (real) PCs. if ( !GetIsPC(oPC) || GetIsDMPossessed(oPC) ) return; // Only fire once per PC. if ( GetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF)) ) return; SetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE); // If it is dawn or day or dusk. if ( GetIsDawn() || GetIsDay() || GetIsDusk() ) { // Spawn Strong Zug-Zug. oTarget = GetWaypointByTag("ZUG_ZUG_LOC"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bullywug004", GetLocation(oTarget)); } else if (GetIsDay() && GetLocalInt(oPC, "weak_zugzug") == 1) // Refers to Zug-Zug's poisoning. { // Spawn weak & poisoned Zug-Zug if it's day oTarget = GetWaypointByTag("ZUG_ZUG_LOC"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bullywug002", GetLocation(oTarget)); } }Good Morning to all...
Try this in order to match your description -
void main() { object oTarget; object oSpawn; // Get the creature who triggered this event. object oPC = GetEnteringObject(); // Only fire for (real) PCs. if ( !GetIsPC(oPC) || GetIsDMPossessed(oPC) ) return; // Only fire once per PC. if ( GetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF)) ) return; SetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE); // If it is night if(!(GetIsDawn() || GetIsDay() || GetIsDusk())) { // Spawn Strong Zug-Zug. oTarget = GetWaypointByTag("ZUG_ZUG_LOC"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bullywug004", GetLocation(oTarget)); } else if(GetIsDay() && GetLocalInt(oPC, "weak_zugzug")) // Refers to Zug-Zug's poisoning. { // Spawn weak & poisoned Zug-Zug if it's day oTarget = GetWaypointByTag("ZUG_ZUG_LOC"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bullywug002", GetLocation(oTarget)); } }One little thing. In C based languages like NwScript 1 == TRUE when used in an if() statement so there is no need to check for a local int being equal to one in that circumstance.
TR
Anyhow, thanks for the awsome help TarotRedhand and Proleric for the pointers...
I'm gonna try to iron this script out. I think by now, ya'll know that is a dicey proposistion!
Code I'm using right now...
void main() { object oTarget; object oSpawn; // Get the creature who triggered this event. object oPC = GetEnteringObject(); // Only fire for (real) PCs. if ( !GetIsPC(oPC) || GetIsDMPossessed(oPC) ) return; // Only fire once per PC. if ( GetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF)) ) return; SetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE); // If it is dawn or day or dusk. if ( GetIsDawn() || GetIsDay() || GetIsDusk() ) { // Spawn STRONG Zug-Zug the Hunter. oTarget = GetWaypointByTag("ZUG_ZUG_LOC"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bullywug004", GetLocation(oTarget)); } // Else, if it is day. else if ( GetIsDay() && GetLocalInt(oPC, "weak_zugzug")) { // Spawn WEAK Zug-Zug the Hunter/Poisoned oTarget = GetWaypointByTag("ZUG_ZUG_LOC"); oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bullywug002", GetLocation(oTarget)); } }Okee dokee. I throw in the proverbial towel! I'm tapping the mat! I'm crying uncle. I'm just crying...
P.S. I used Lilac Soul's script generator for most of the script...
SetLocalInt(oPC, "weak_zugzug", 1);
Then to call it - else if ( GetIsDay() && GetLocalInt(oPC, "weak_zugzug"))
Don't know if that's correct?
void main() { object oTarget; object oSpawn; // Get the creature who triggered this event. object oPC = GetEnteringObject(); // Only fire for (real) PCs. if ( !GetIsPC(oPC) || GetIsDMPossessed(oPC) ) return; // Only fire once per PC. if ( GetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF)) ) return; SetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE); oTarget = GetWaypointByTag("ZUG_ZUG_LOC"); // If it is day. if(GetIsDay() && GetLocalInt(oPC, "weak_zugzug")) oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bullywug002", GetLocation(oTarget)); // Spawn WEAK Zug-Zug the Hunter/Poisoned else if(!(GetIsNight())) // Otherwise, if it is dawn or day or dusk eg not Night. oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bullywug004", GetLocation(oTarget)); // Spawn STRONG Zug-Zug the Hunter. }And let me know if the re-ordering of your code works.
TR
Yeah, I tried the code, but got the same result. No spawn of the weak version. Also, I'm waiting until 9 am before I even attempt to enter the cave - just to be sure it was day time. Wasn't exactly sure when day began. Although I would imagine arround 6 or 7.
I've also triple checked the ResRefs and tags...
Look in the module properties under the Advanced tab. It is defined in there.
Experimenting in toolset (I have an idea). I may be sometime...
TR
BTW, is it your intention that the PC only gets one chance to kill Zug Zug? That they can only enter the cave, with a chance of killing Zug Zug, once even if they do so at night? If not I can create a work around that let's the PC enter more than once.
TR
Yeah. I was trying for multiple chances.
From the actions taken tab -
void main() { object oPC = GetPCSpeaker(); if (!GetIsPC(oPC)) return; SetLocalInt(oPC, "weak_zugzug", 1); object oZug = GetObjectByTag("ZUG_FX"); location lLoc1 = GetLocation(GetWaypointByTag("BUBBLES_01")); location lLoc2 = GetLocation(GetWaypointByTag("BUBBLES_02")); location lLoc3 = GetLocation(GetWaypointByTag("GREEN_GLOW_LOC")); if (GetFirstItemInInventory(oPC) == GetObjectByTag("WUG_POISON")) { DestroyObject(GetObjectByTag("WUG_POISON"), 0.0); GetNextItemInInventory(oPC); CreateObject(OBJECT_TYPE_PLACEABLE, "z_bubbles_01", lLoc1); CreateObject(OBJECT_TYPE_PLACEABLE, "z_bubbles_02", lLoc2); CreateObject(OBJECT_TYPE_PLACEABLE, "tm_pl_invbarr001", lLoc3); DelayCommand(2.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect (VFX_FNF_WAIL_O_BANSHEES), oZug)); ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect (VFX_FNF_GAS_EXPLOSION_ACID), oZug); DelayCommand(7.5, ActionSpeakString("His water has been amply corrupted!")); } }Now onto the problem with the above code. You are assuming that the very first item in the PCs inventory is going to be the poison. This is not necessarily the case. Try the following version of your code with a little bit of editing.
void main() { object oPC = GetPCSpeaker(); object oPoison = GetObjectByTag("WUG_POISON"); object oZug = GetObjectByTag("ZUG_FX"); object oItem; location lLoc1 = GetLocation(GetWaypointByTag("BUBBLES_01")); location lLoc2 = GetLocation(GetWaypointByTag("BUBBLES_02")); location lLoc3 = GetLocation(GetWaypointByTag("GREEN_GLOW_LOC")); if(GetIsPC(oPC)) { oItem = GetFirstItemInInventory(oPC); while(GetIsObjectValid(oItem)) { if(oItem == oPoison) { DestroyObject(GetObjectByTag("WUG_POISON"), 0.0); GetNextItemInInventory(oPC); CreateObject(OBJECT_TYPE_PLACEABLE, "z_bubbles_01", lLoc1); CreateObject(OBJECT_TYPE_PLACEABLE, "z_bubbles_02", lLoc2); CreateObject(OBJECT_TYPE_PLACEABLE, "tm_pl_invbarr001", lLoc3); DelayCommand(2.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_WAIL_O_BANSHEES), oZug)); ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_GAS_EXPLOSION_ACID), oZug); DelayCommand(7.5, ActionSpeakString("His water has been amply corrupted!")); break; } else oItem = GetNextItemInInventory(oPC); } SetLocalInt(oPC, "weak_zugzug", 1); } }TR
Tried to no avail. I'll tear apart every script in the mod. Thankfully I'm just starting this one and the number of scripts is small. Even smaller yet would be the number of scripts germaine to the intended outcome.
Thanks again TarotRedhand.
I'll check back soon...
I had a qestion about the revised script above. When you use "while" are you creating a "loop", and that's why there is a "break" at the end? If not does it fry your game in an endless loop...
The reason I ask is, when I've tried to use "while" before I always crash my game with code. I'm assuming it was because I didn't and don't know, how and when to "tie the knot" of the loop...?
I don't know if that makes a bit of sense...?
I explain all about loops (and other things) in the tutorial I wrote - "TR's Basics - Decisions". It's a 36 page pdf booklet that is extensively illustrated (eg loads of piccies). Give it a try. If you do get it, I highly recomend you use a dedicated pdf reading program as I went to the trouble of including bookmarks to make finding what you want easier.
TR
I looked at all of my scripts (all said and done about 20) and couldn't find anything that would cause any mayhem with the spawn that I could discern...
Gonna pass a little time and start making my 2x2 mod in lesson #1 of your tutorial...
void main() { object oPC = GetPCSpeaker(); if (!GetIsPC(oPC)) return; //if the speaker is NOT(!) a player then end here object oZug = GetObjectByTag("ZUG_FX"); location lLoc1 = GetLocation(GetWaypointByTag("BUBBLES_01")); location lLoc2 = GetLocation(GetWaypointByTag("BUBBLES_02")); location lLoc3 = GetLocation(GetWaypointByTag("GREEN_GLOW_LOC")); object oPoison = GetItemPossessedBy(oPC, "WUG_POISON"); if (GetIsObjectValid(oPoison)) { DestroyObject(oPoison, 0.0); CreateObject(OBJECT_TYPE_PLACEABLE, "z_bubbles_01", lLoc1); CreateObject(OBJECT_TYPE_PLACEABLE, "z_bubbles_02", lLoc2); CreateObject(OBJECT_TYPE_PLACEABLE, "tm_pl_invbarr001", lLoc3); DelayCommand(2.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_WAIL_O_BANSHEES), oZug)); ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_GAS_EXPLOSION_ACID), oZug); DelayCommand(7.5, ActionSpeakString("His water has been amply corrupted!")); SetLocalInt(oPC, "weak_zugzug", 1); } }Hope this helps.
TR
Would the fact that this script is being triggered as an area OnEnter script and not just a generic trigger have anything to do with weak ZUg-Zug not spawning? I wouldn't think so...?