OP
addict
Joined: Jul 2014
|
Alright, I think this mod is at the point where it is feature complete. Version 4 of the mod- http://www.mediafire.com/download/g7554qx0v4jd9e3/RespawningEnemiesV4.zipFeatures: -Enemies will respawn* where they last died (this is on by default) -Player characters receive four skills upon arriving at Cyseal Beach that toggle various functions in this mod. 1. Disable Respawning Enemies - This makes it so that when enemies are killed, they no longer respawn. 2. Enable Respawning Enemies - This makes it so that enemies who are killed will respawn. 3. Mass Respawn - This makes it so that all NPCs who are currently dead (and haven't respawned) will respawn, even if they were killed when Respawn was disabled. 4. Reset Spawn Positions - The next time that dead enemies respawn will be at where they originally died at *Respawn means that a copy of the enemy will appear where the NPC last died. The original NPC's corpse will remain in the location that they originally died at. --- Full code- Default Character changes:
INIT
INT:%canRespawn=0
CHARACTER:%parent=__Me
FLOAT3:%spawnPos=null
INT:%hasChild=0
EVENTS
EVENT RespawnCharacter
VARS
CHARACTERTEMPLATE:_root
FLOAT3:_myPos
CHARACTER:_child
ON
OnInit()
ACTIONS
IF "c1&c2&c3&c4&c5"
IsEqual(%canRespawn, 1)
CharacterIsDead(__Me)
CharacterGetTemplate(__Me, _root)
GetPosition(__Me, _myPos)
IsEqual(%hasChild, 0)
THEN
IF "c1"
IsEqual(%spawnPos, null)
THEN
Set(%spawnPos, _myPos)
ENDIF
SpawnCharacter(_child, _root, %spawnPos, 0)
SetVar(_child, "parent", __Me)
Set(%hasChild, 1)
Set(%canRespawn, 0)
ENDIF
EVENT ProgenyDeath
VARS
FLOAT3:_myPos
ON
OnDie(__Me,_,_,_)
ACTIONS
IF "!c1&c2"
IsEqual(__Me, %parent)
GetPosition(__Me, _myPos)
THEN
SetVar(%parent, "hasChild", INT:0)
SetVar(%parent, "spawnPos", _myPos)
CharacterEvent(%parent, "CheckForRespawn")
ENDIF
EVENT ResetSpawnPosition
VARS
FLOAT3:_myPos
ON
OnCharacterEvent(__Me, "ResetSpawnPosition")
ACTIONS
IF "c1"
GetPosition(__Me, _myPos)
THEN
Set(%spawnPos, _myPos)
ENDIF
Story script-
INITSECTION
DB_RespawnEnabled(1);
KBSECTION
IF
CharacterCreationFinished(CHARACTER_NULL)
AND
CurrentLevel(_Lvl)
AND
DB_CharacterCreationLevels(_Lvl)
THEN
CharacterAddSkill(CHARACTER_Player1, "Shout_RespawnEnable");
CharacterAddSkill(CHARACTER_Player1, "Shout_RespawnDisable");
CharacterAddSkill(CHARACTER_Player2, "Shout_RespawnEnable");
CharacterAddSkill(CHARACTER_Player2, "Shout_RespawnDisable");
CharacterAddSkill(CHARACTER_Player1, "Shout_MassRespawnEnable");
CharacterAddSkill(CHARACTER_Player2, "Shout_MassRespawnEnable");
CharacterAddSkill(CHARACTER_Player1, "Shout_ResetSpawnPosition");
CharacterAddSkill(CHARACTER_Player2, "Shout_ResetSpawnPosition");
IF
CharacterUsedSkill(_Char, "Shout_RespawnEnable", _)
AND
DB_RespawnEnabled(0)
THEN
NOT DB_RespawnEnabled(0);
DB_RespawnEnabled(1);
IF
CharacterUsedSkill(_Char, "Shout_RespawnDisable", _)
AND
DB_RespawnEnabled(1)
THEN
NOT DB_RespawnEnabled(1);
DB_RespawnEnabled(0);
IF
CharacterDied(_Char)
THEN
CharacterSetEvent(_Char, "CheckForRespawn");
IF
CharacterEvent(_Char, "CheckForRespawn")
AND
NOT _Char.isPlayer()
AND
DB_RespawnEnabled(1)
THEN
CharacterSetVarInteger(_Char, "canRespawn", 1);
IF
CharacterDied(_Char)
AND
NOT _Char.isPlayer()
AND
NOT DB_DeadCharacters(_Char)
THEN
DB_DeadCharacters(_Char);
IF
CharacterEvent(_Char, "CheckForRespawn")
AND
NOT DB_DeadCharacters(_Char)
THEN
DB_DeadCharacters(_Char);
IF
CharacterUsedSkill(_Char, "Shout_MassRespawnEnable", _)
THEN
MassRespawn();
PROC
MassRespawn()
AND
DB_DeadCharacters(_Char)
THEN
CharacterSetVarInteger(_Char, "canRespawn", 1);
NOT DB_DeadCharacters(_Char);
MassRespawn();
IF
CharacterDied(_Char)
AND
NOT DB_SpawnPositions(_Char)
THEN
DB_SpawnPositions(_Char);
IF
CharacterEvent(_Char, "CheckForRespawn")
AND
NOT DB_SpawnPositions(_Char)
THEN
DB_SpawnPositions(_Char);
IF
CharacterUsedSkill(_Char, "Shout_ResetSpawnPosition", _)
THEN
MassResetSpawnPosition();
PROC
MassResetSpawnPosition()
AND
DB_SpawnPositions(_Char)
THEN
CharacterSetEvent(_Char, "ResetSpawnPosition");
NOT DB_SpawnPositions(_Char);
MassResetSpawnPosition();
Lessons learned from working on this mod- 1. Main campaign charScripts (and presumably itemScripts) can be overwritten by mods. There might be some side effects, but it can be done.
2. Story scripts and charScripts/itemScripts can work together to great effect.
3. Resurrected characters don't give exp but are easier to work with, while Spawned characters give exp and are much harder to work with. Something about living spawned characters (perhaps GUID) appears to change whenever the game is loaded (or perhaps they die) such that they are no longer equal to what they were prior to game load/death.
I think I now have enough experience in charScripts/itemScripts to add a section to my tutorial thread.
Last edited by Rhidian; 03/09/14 10:30 PM.
|