You can declare variables inside any block of code (as designated by {}), I believe. Also does not have to be at the start of the block. This is not new in EE.
In this case you probably don't need to since the if part is borken and the aNAME is only used once...
Ok. Changed it a bit so that it will only fire for assigned waypoints. Now it wont look through every waypoint in the area. Ha,ha.
//The Tinmans Simple "Spawns All" script.
//Can be used with a Triggers on enter event, or an objects heartbeat script.
void CreatVoid (object oObject) { }
void main()
{
// Only fires for the PC
object oPC = GetEnteringObject();
//If this line is commented out it can be used on an objects heartbeat script
if(!GetIsPC(oPC)) { return; }
// Only fire once per PC.
if ( GetLocalInt(OBJECT_SELF, "DO_ONCE__" + ObjectToString(oPC)) )
return;
SetLocalInt(OBJECT_SELF, "DO_ONCE__" + ObjectToString(oPC), TRUE);
//The Waypoint Spawner
object oSP = GetFirstObjectInArea();
//Checks for Waypoints in the Area
while(GetIsObjectValid(oSP))
{
//Change the name of the waypoint to the Tag of a Standard Creature.
//Change the name of the waypoint to the ResRef of a Custom Creature
//The object this script is attached to must have the same name as the Waypoint
string aNAME = GetName(oSP);
string tNAME = GetName(OBJECT_SELF); //OBJECT_SELF = the caller of this script
if(GetObjectType(oSP) == OBJECT_TYPE_WAYPOINT
&& GetName(OBJECT_SELF) == aNAME)
{
//Slight delay to fix multiple creature spawns
DelayCommand(0.1, CreatVoid( CreateObject(OBJECT_TYPE_CREATURE, aNAME, GetLocation(oSP), FALSE)));
}
//Loops through all of the Waypoints with the Spawner tag.
oSP = GetNextObjectInArea();
}
}
You know, the way I'd do this is that instead of using the name of the area for the comparison, I'd save a string variable on the area and I'd retrieve that in the script for the comparison. I'd also search by tag rather than searching by name and I'd take the blueprint ResRef from either the name of the waypoint or from a variable stored on the waypoint.
The script would go something like:
void CreatVoid (object oObject) { }
void main()
{
// Only fires for the PC
object oPC = GetEnteringObject();
//If this line is commented out it can be used on an objects heartbeat script
if(!GetIsPC(oPC)) { return; }
// Only fire once per PC.
if ( GetLocalInt(OBJECT_SELF, "DO_ONCE__" + ObjectToString(oPC)) )
return;
SetLocalInt(OBJECT_SELF, "DO_ONCE__" + ObjectToString(oPC), TRUE);
//The Waypoint Spawner
string tNAME=GetLocalString(OBJECT_SELF,"SPAWN_POINTS"); //OBJECT_SELF = the caller of this script
object oSP = GetFirstObjectInArea();
//Checks for Waypoints in the Area
while(GetIsObjectValid(oSP))
{
//Change the name of the waypoint to the Tag of a Standard Creature.
//Change the name of the waypoint to the ResRef of a Custom Creature
//The object this script is attached to must have the same name as the Waypoint (not any more)
string aNAME = GetName(oSP);
string aTAG=GetTag(oSP);
//string tNAME = GetName(OBJECT_SELF); //OBJECT_SELF = the caller of this script
if(GetObjectType(oSP) == OBJECT_TYPE_WAYPOINT
&& aTAG == tNAME)
{
//Slight delay to fix multiple creature spawns
DelayCommand(0.1, CreatVoid( CreateObject(OBJECT_TYPE_CREATURE, aNAME, GetLocation(oSP), FALSE)));
}
//Loops through all of the Waypoints with the Spawner tag.
oSP = GetNextObjectInArea();
}
}
}
With this version, the only change you should need to make is to add the string variable SPAWN_POINTS to the area, and make sure it contains the tag which you assign to all of your creature spawn waypoints (and don't give that same tag to any other waypoints). Sure, you'll also have to make sure you change the creature spawn waypoint tags, but a big advantage is that you no longer have to link your area name to the waypoint names. If you ever decide to use a different area name, you won't have to change anything else.
I did something slightly similar to this, only it was for placeables rather than for creatures. The idea was to be able to create destroyable loot containers for a multi-player module, then after the area is vacated by all players, reset the area by erasing the remaining placeables and re-create them all over again ready for the next player.
The way I did it was by having waypoints all named "CREATE_PLACEABLE" and each waypoint had variables on it to control exactly what was created at that place. Other variables allowed for variations such as only creating some placeables randomly, creating a group of placeables in a particular configuration, always creating a placeable but putting it in a different place each time, and a few other ideas.
I honestly didnt know how to script it that way. The only downside is that I cant name the tag of the waypoint so i know what creature is assigned to it. I would name my waypoint say NW_RAT001 with a tag of Rat. Small price to pay for the added flexibility though. Thank you very much.
I honestly didnt know how to script it that way. The only downside is that I cant name the tag of the waypoint so i know what creature is assigned to it. I would name my waypoint say NW_RAT001 with a tag of Rat. Small price to pay for the added flexibility though. Thank you very much.
The easiest way is probably to right-click on a standard waypoint and Edit New, then edit the tag and name in the properties and save it as a custom waypoint. That way, you can "stamp out" as many creature spawn waypoints as you need, and just edit the waypoint name to the ResRef of the creature which you want spawned at that waypoint.
I'm not sure why you say you can't "name the tag" of the waypoint. It's a simple matter of editing the properties. The only limitation is that the tag can't contain spaces, but you shouldn't need spaces in the tag anyway.
The "tag naming" only applies if more than one creature type is spawned into one area. I would tag each waypoint the creature type. It was mainly for ease of location in the toolset because waypoints show up by tag name.
And yes. You have helped me greatly. Thanks again.
Comments
In this case you probably don't need to since the if part is borken and the aNAME is only used once...
The script would go something like: With this version, the only change you should need to make is to add the string variable SPAWN_POINTS to the area, and make sure it contains the tag which you assign to all of your creature spawn waypoints (and don't give that same tag to any other waypoints). Sure, you'll also have to make sure you change the creature spawn waypoint tags, but a big advantage is that you no longer have to link your area name to the waypoint names. If you ever decide to use a different area name, you won't have to change anything else.
I did something slightly similar to this, only it was for placeables rather than for creatures. The idea was to be able to create destroyable loot containers for a multi-player module, then after the area is vacated by all players, reset the area by erasing the remaining placeables and re-create them all over again ready for the next player.
The way I did it was by having waypoints all named "CREATE_PLACEABLE" and each waypoint had variables on it to control exactly what was created at that place. Other variables allowed for variations such as only creating some placeables randomly, creating a group of placeables in a particular configuration, always creating a placeable but putting it in a different place each time, and a few other ideas.
The easiest way is probably to right-click on a standard waypoint and Edit New, then edit the tag and name in the properties and save it as a custom waypoint. That way, you can "stamp out" as many creature spawn waypoints as you need, and just edit the waypoint name to the ResRef of the creature which you want spawned at that waypoint.
I'm not sure why you say you can't "name the tag" of the waypoint. It's a simple matter of editing the properties. The only limitation is that the tag can't contain spaces, but you shouldn't need spaces in the tag anyway.
Anyway, I hope I've been of some help to you.
And yes. You have helped me greatly. Thanks again.