Benutzer-Werkzeuge

Webseiten-Werkzeuge


utilfunctions:setup_stargate_system

Das Stargate System

Funktion des Stargates:

Sobalt ein zweites Stargate durch das DHD angewählt wurde aktiviert sich das Gate mit einem wandernden DieHero-Effect. Das Gate kann maximal 3,8 Minuten offen gehalten werden und funktioniert nur vom Wahl- zum Zielgate. Wenn das Gate geschlossen wird verschwindet der Ereignishorizont .
Es können mehrere Verbindungen gleichzeitig geöffnet sein, aber zu jeder Verbindung gehören immer nur zwei Stargates! Genaueres unter www.stargate-project.de.

Wenn man den unteren Code so in sein Script kopiert hat, …
( Und sich „Briefing_ExtraWrapper“ und die verbesserte „SetPosition“ funktion auch in eurem Skript befinden! ) …
und sich geschlossene Tore mit den fortlaufenden Namen „Stargate1“, „Stargate2“, „Stargate3“, …
sowie DHDs ([Anwahlpulte] können alle Entities sein zb. „XD_TemplarAltar“) mit den fortlaufenden Namen „DHD1“, „DHD2“, „DHD3“, …
auf der Karte befinden, dann könnt ihr das Stargate-System ganz einfach mit folgendem Aufruf aktivieren:

	-- Stargate System aktivieren
	SetupStargateSystem( _stargates )

_stargates ist die Anzahl der Stargates, die das System enthalten soll. Entsprechend viele Tore mit fortlaufendem Namen mussen existieren!
( Mit diesem Code könnt ihr nur EIN Stargate System erstellen! )

Standartmäßig seid ihr die User (Benutzer) des Stargete-Systems → Player 1. Falls ihr weitere, oder andere Spieler als User definieren möchtet, …
müsst ihr beim Aktivieren alle user-player-Ids ( in einer Tabelle, als zweiten Parameter ) …
an die Setup-Funktion des Stargate-Systems übergeben:

	-- Stargate System mit erweiterten Benutzern aktivieren
	local users = { _player1, _player2, ... }
	SetupStargateSystem( _stargates, users )

Das wars! Wenn ihr EINE der beiden Setup-Code ausgeführt habt, könnt ihr nun die Stargates in einem Briefing anwählen, …
welches startet, wenn ihr mit einem eurer Leute in die unmittelberer Umgebung eines der DHDs kommt!

Wenn ihr mehrere geschlossene Tore auf der Karte verteilt, könnt ihr anfangs, nur einige aktivieren, …
und später durch einen Neustart des Stargate-Systems nachträglich weitere aktivieren, oder welche deaktivieren.
Die aktivierten Gates müssen aber immer fortlaufend nummeriert sein.

	-- Stargate System neustarten
	ReinstallStargateSystem( _stargates )
 
	-- oder
	local users = { _player1, _player2, ... }
	ReinstallStargateSystem( _stargates, users )

Hiermit könnt ihr das System deaktivieren ( komplett löschen ).

	-- Stargate System deaktivieren
	UninstallStargateSystem()

Dann könnt ihr das System noch auf Standby setzen, um die Anwahlmöglichkeit aller Stargates vorübergehend zu deaktivieren:

	-- Stargate System auf Standby setzen:
	StandbyStargateSystem()

Und natürlich auch wieder aus dem Standby-Modus starten:

	-- Stargate System aus dem Standby-Modus starten:
	StartStargateSystem()

Beispielkarte hier!

Übersicht über den System-Table:

Hier ist eine Übersicht über den StargateSystem-Table, wenn er mit allen Parametern gefüllt ist:
( wird erst in aktion aufgefüllt - manches nur kurzzeitig, … / die Werte [true,false,0,50,…] sind so in Ausgangsstellung )

	StargateSystem = {
		standby = false,
		users = {_player1, _player2, _player3, _playerN},
		activatedConnections = {
			[1] = {
				[1] = {
					id = dialingOutSgID,
					name = "Stargate"..dialingOutSgID,
					effect = {offsetPos = 0, changePos = 50},
				},
				[2] = {
					id = dialingInSgID,
					name = "Stargate"..dialingInSgID,
					effect = {offsetPos = 0, changePos = 50},
				},
				counter = 380,
			}
		},
		CheckDHDs = StartSimpleHiResJob("CheckDHDs"),
		HorizonEffects = StartSimpleHiResJob("ControlHorizonEffects"),
		HoleAktivitys = StartSimpleJob("ControlStargateHoleAktivitys"),
		[1] = {
			name = "Stargate1",
			pos = GetPosition( "Stargate1" ),
			place = GetPosition( "Stargate1Place" ),
			gateType = Logic.GetEntityType(GetEntityId( "Stargate1" )),
			orientation = Logic.GetEntityOrientation(GetEntityId( "Stargate1" )),
			dhd = {
				name = "DHD1", 
				pos = GetPosition("DHD1"),
				ready = true, 
				active = 0,
			},
			choicePage = {[1] = {}, [2] = {}, [3] = {}, [n] = {}},
		},
		[2] = {
			name = "Stargate2",
			pos = GetPosition( "Stargate2" ),
			place = GetPosition( "Stargate2Place" ),
			gateType = Logic.GetEntityType(GetEntityId( "Stargate2" )),
			orientation = Logic.GetEntityOrientation(GetEntityId( "Stargate2" )),
			dhd = {
				name = "DHD2", 
				pos = GetPosition("DHD2"),
				ready = true, 
				active = 0,
			},
			choicePage = {[1] = {}, [2] = {}, [3] = {}, [n] = {}},
		},
		[3] = {
			name = "Stargate3",
			pos = GetPosition( "Stargate3" ),
			place = GetPosition( "Stargate3Place" ),
			gateType = Logic.GetEntityType(GetEntityId( "Stargate3" )),
			orientation = Logic.GetEntityOrientation(GetEntityId( "Stargate3" )),
			dhd = {
				name = "DHD3", 
				pos = GetPosition("DHD3"),
				ready = true, 
				active = 0,
			},
			choicePage = {[1] = {}, [2] = {}, [3] = {}, [n] = {}},
		},
		[n] = {}
	}

Der Code:

--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Stargate Funktionen beginnen hier!
--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Comfort functions um ein Stargate-System zu etablieren		Version 1.00				by Tenji
------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
-- Setup Stargate System
------------------------------------------------------------------------------
function SetupStargateSystem( _gates, _systemUsers)
 
	assert(type(_gates) == "number" and _gates > 1, "SetupStargateSystem: _gates have to be a number, higher than 1!");
	if _systemUsers ~= nil then
		assert(type(_systemUsers) == "table" and type(_systemUsers[1]) == "number", "SetupStargateSystem: _systemUsers have to be a table with numbers of players from 1 to 8!");
	end
 
	-- Erstelle einen globalen Stargaate-System-Table	
	StargateSystem = {
		standby = true,
		activatedConnections = {},
	};
 
	if _users == nil then
		StargateSystem.users = {1};
	else
		StargateSystem.users = _systemUsers;
	end
 
	-- informationen über die Stargates speichern	
	for i = 1, _gates do
		local stargate = "Stargate"..i;
 
		-- überprüfe, ob die angegebenen Stargates auf der Map existieren
		assert( IsExisting( stargate ), "SetupStargateSystem: "..stargate.." have to be on the map with the same Scriptname!" );
		assert( IsExisting( "DHD"..i ), "SetupStargateSystem: DHD"..i.." have to be on the map with the same Scriptname!" );
 
		local iTable = {
			name = stargate,
			pos = GetPosition( stargate ),
			gateType = Logic.GetEntityType(GetEntityId( stargate )),
			orientation = Logic.GetEntityOrientation(GetEntityId( stargate )),
			dhd = {
				name = "DHD"..i,
				pos = GetPosition("DHD"..i), 
				ready = true, 
				active = 0,
			},
			choicePage = {},
		};
 
		-- füge das Stargate dem globalen Table hinzu 
		table.insert( StargateSystem, iTable);
 
	end
 
	-- öffne die Stargates es und füge jeweils eine Ankunftsposition hinzu
	for i = 1, _gates do
		local pos = StargateSystem[i].pos;
 
		local position;
		if StargateSystem[i].orientation == 0 then
			position = {X = pos.X +500, Y= pos.Y};
		elseif StargateSystem[i].orientation == 90 then
			position = {X = pos.X, Y= pos.Y +500};
		elseif StargateSystem[i].orientation == 180 then
			position = {X = pos.X -500, Y= pos.Y};
		elseif StargateSystem[i].orientation == 270 then
			position = {X = pos.X, Y= pos.Y -500};
		end	
 
		local place = CreateEntity( 4, Entities.XD_ScriptEntity, position, "Stargate"..i.."Place");
		StargateSystem[i].place = GetPosition( place );
 
		if StargateSystem[i].gateType == 390 then
			ReplaceEntity( StargateSystem[i].name, Entities.XD_WallStraightGate);
		elseif StargateSystem[i].gateType == 395 then
			ReplaceEntity( StargateSystem[i].name, Entities.XD_DarkWallStraightGate);
		elseif StargateSystem[i].gateType ~= 607 then -- wenn das Stargate kein Tor und keine ScriptEntity ist, dann "Error!"
			assert( false, "SetupStargateSystem: "..StargateSystem[i].name.." have to be a closed Door! Type 390 or 395, but not "..StargateSystem[i].gateType);
		end
	end
 
	-- ... und los!
	StartStargateSystem();
 
end 
---------------------------------------------------------------------------------------------
-- Restart Stargate System
------------------------------------------------------------------------------
function ReinstallStargateSystem( _gates, _systemUsers)
 
	assert(type(_gates) == "number" and _gates > 1, "ReinstallStargateSystem: _gates have to be a number, higher than 1!");
	if _systemUsers ~= nil then
		assert(type(_systemUsers) == "table" and type(_systemUsers[1]) == "number", "ReinstallStargateSystem: _systemUsers have to be a table with numbers of players from 1 to 8!");
	end
 
	-- System komplett löschen
	UninstallStargateSystem();
 
	-- System neu erstellen
	if _systemUsers == nil then
		SetupStargateSystem( _gates);
	else
		SetupStargateSystem( _gates, _systemUsers);
	end
 
end 
---------------------------------------------------------------------------------------------
-- Delate Stargate System
------------------------------------------------------------------------------
function UninstallStargateSystem()
 
	assert( StargateSystem ~= nil and table.getn(StargateSystem) > 1, "UninstallStargateSystem: StargateSystem have to be installed by ´SetupStargateSystem´ bevore!");
 
	-- System Herunterfahren
	StandbyStargateSystem();
 
	-- ermittle Systemgröße
	local systemSize = table.getn(StargateSystem);
 
	-- deaktiviere Stargate-Entitäten
	for i = 1, systemSize do
		local stargate = StargateSystem[i].name;
		local gateType = Logic.GetEntityType(GetEntityId(stargate));
 
		-- entferne die Stargate-Positionen-Entities
		DestroyEntity("Stargate"..i.."Place");
 
		-- schließe die Stargates auf der Karte
		if gateType == 389 then
			ReplaceEntity(stargate, Entities.XD_WallStraightGate_Closed);
		elseif gateType == 394 then
			ReplaceEntity(stargate, Entities.XD_DarkWallStraightGate_Closed);
		end	
	end
 
	-- lösche Systemdaten
	StargateSystem = nil;
 
end 
---------------------------------------------------------------------------------------------
-- Stargate Systeme auf Standby
------------------------------------------------------------------------------
function StandbyStargateSystem()
 
	assert( StargateSystem ~= nil and table.getn(StargateSystem) > 1, "StandbyStargateSystem: StargateSystem have to be installed by ´SetupStargateSystem´ bevore!");
 
	-- Alle Systeme zurücksetzen:
	-------------------------------------------
	-- die "Wurmloch-Funktion"
	if StargateSystem.HoleAktivitys ~= nil then
		EndJob( StargateSystem.HoleAktivitys );
		StargateSystem.HoleAktivitys = nil;
	end
	-------------------------------------------
	-- die "Ereignishorizont-Effekte"
	if StargateSystem.HorizonEffects ~= nil then
		EndJob( StargateSystem.HorizonEffects );
		StargateSystem.HorizonEffects = nil;
	end
	-------------------------------------------
	-- die Anwahlbereitschaft der DHDs
	if StargateSystem.CheckDHDs ~= nil then
		EndJob( StargateSystem.CheckDHDs );
		StargateSystem.CheckDHDs = nil;
	end
	-------------------------------------------
	-- die Daten
	for i = 1,table.getn(StargateSystem) do
		StargateSystem[i].dhd.ready = true;
		StargateSystem[i].dhd.active = 0;
	end
	StargateSystem.activatedConnections = {};
	-------------------------------------------
	-- Standby-Modus aktiv
	StargateSystem.standby = true;
 
end
---------------------------------------------------------------------------------------------
-- Starte das Stargate System
------------------------------------------------------------------------------
function StartStargateSystem()
 
	assert( StargateSystem ~= nil and table.getn(StargateSystem) > 1, "StartStargateSystem: StargateSystem have to be installed by ´SetupStargateSystem´ bevore!");
 
	if StargateSystem.standby then
 
		-- Standby-Modus inaktiv
		StargateSystem.standby = false;
 
		-- die Anwahlbereitschaft der DHDs überwachen
		StargateSystem.CheckDHDs = StartSimpleJob("CheckDHDs");
 
	end
 
end
---------------------------------------------------------------------------------------------
-- Prüfe, ob anwahlberechtigte Entities am DHD stehen
------------------------------------------------------------------------------
function AreEntitiesAtDHD( _dhd )
 
	local dhd;
	if type(_dhd) == "string" then 
		dhd = _dhd;
	elseif type(_dhd) == "number" then 
		dhd = "DHD".._dhd;
	else 
		assert( false, "SgSystem: _dhd have to be type string or number!");
	end
 
	if AreUseAllowedEntitiesNear( dhd, 300 ) then
		return true;
	else
		return false;
	end
 
end
---------------------------------------------------------------------------------------------
-- Prüfe, ob Entities mit Nutzungsberechtigung in der Nähe sind
------------------------------------------------------------------------------
function AreUseAllowedEntitiesNear( _entityOrPos, _range )
 
	local pos;
	if type(_entityOrPos) == "table" and type(_entityOrPos.X) == "number" and type(_entityOrPos.Y) == "number" then
		pos = _entityOrPos;
	elseif type(_entityOrPos) == "string" or type(_entityOrPos) == "number" then
		pos = GetPosition( _entityOrPos );
	else
		assert( false, "SgSystem: _entityOrPos have to be type table {X = number, Y = number} or type string (name of Entity) or type number (ID of Entity)!");
	end
	assert(type(_range) == "number", "SgSystem: _range have to be type number!");
 
	local data = {Logic.GetPlayerEntitiesInArea( 1, 0, pos.X, pos.Y, _range, 10)};
	local amount = table.remove(data, 1);
 
	for i = 1, amount do
		-- so umständlich, weil "Logic.IsPlayerEntityOfCategoryInArea" einfach nicht funktioieren will !
		if Logic.IsEntityInCategory(data[i], EntityCategories.Military) == 1 and Logic.IsEntityInCategory(data[i], EntityCategories.Soldier) == 0 then
			return true;
		end
	end
 
	-- wenn es bis hier durchläuft, ist niemand berechtigter da
	return false;
 
end
---------------------------------------------------------------------------------------------
-- DHD ( Dial Home Device ) - Funktionen
------------------------------------------------------------------------------
function CheckDHDs()
 
	for i = 1,table.getn( StargateSystem ) do
 
		local dhd = StargateSystem[i].dhd;
 
		-- prüfen, ob das DHD bereit ist, ...
		if ( dhd.ready == false ) and not AreEntitiesAtDHD(i) then -- war nicht bereit
			-- ist jetzt wieder bereit / wird nicht verwendet
			dhd.ready = true;
 
		elseif ( dhd.ready == true ) and AreEntitiesAtDHD(i) then -- war bereit
			-- ist jetzt nichtmehr bereit / wird verwendet
			dhd.ready = false;
 
			-- ... wenn ja, Entities in Richtung DHD blicken lassen, ...
			for u = 1,table.getn(StargateSystem.users) do
 
				local player = StargateSystem.users[u];
				local data = {Logic.GetPlayerEntitiesInArea( player, 0, dhd.pos.X, dhd.pos.Y, 300, 10)};
				local amount = table.remove(data, 1);
 
				for e = 1, amount do
					if Logic.IsBuilding(data[e]) == 0 then
						LookAt( data[e], dhd.name );
					end
				end
			end
 
			-- ... und entsprechendes Briefing starten!
			if dhd.active == 1 then
				CreateDialOutDHDBriefing(i);
 
			elseif dhd.active == 2 then
				CreateDialInDHDBriefing(i);
 
			else
				CreateDHDBriefing(i);
			end
 
		end
 
	end
 
end
---------------------------------------------------------------------------------------------
-- Dialing Out DHD Briefing
------------------------------------------------------------------------------
function CreateDialOutDHDBriefing( _dialingOutDHDid)
 
	-- Das lokale Briefing
	local briefing = {};
	-- AddPage Funktion
	local AP = function( _page ) table.insert( briefing, _page ); return _page; end
 
	-- das angewählte DHD heraus suchen
	local cons = StargateSystem.activatedConnections;
	local dialingInDHDid;
 
	for i = table.getn(cons),1,-1 do
		if cons[i][1].id == _dialingOutDHDid then
			dialingInDHDid = cons[i][2].id;
		end
	end
 
	-- Seite 1
	local choicePage = AP{ 
		mc = {	-- Multiple Choice
					title	= "",
					text = "Die von diesem DHD ausgehende Aktivierung abschalten, Sir?",
					firstText = "Ja, DHD".._dialingOutDHDid.." abschalten!",
					secondText = "Nein, Aktivierung Stargate ".._dialingOutDHDid.." - "..dialingInDHDid.." beibehalten!",
					firstSelected = 2,	--  -> Ende
					secondSelected = 2,	--  -> Ende
		},
		position = GetPosition("DHD".._dialingOutDHDid),
		dialogCamera = true,
	};
 
	-- Seite 2
	AP(); 	-- dient als Endseite
 
	-- Die finished Funktion:
	briefing.finished = function()
		-- wenn abgebrochen wurde, dann ...
		if GetSelectedBriefingMCButton( choicePage ) == 1 then
			DeactivateConnection(_dialingOutDHDid);
		end
	end
 
	-- ... und los!
	StartBriefing( briefing );
 
end
---------------------------------------------------------------------------------------------
-- Dialing In DHD Briefing
------------------------------------------------------------------------------
function CreateDialInDHDBriefing( _dialingInDHDid)
 
	-- Das lokale Briefing
	local briefing = {};
	-- AddPage Funktion
	local AP = function( _page ) table.insert( briefing, _page ); return _page; end
 
	-- das anwählende DHD heraus suchen
	local cons = StargateSystem.activatedConnections;
	local dialingOutStargate;
 
	for i = table.getn(cons),1,-1 do
		if cons[i][2].id == _dialingInDHDid then
			dialingOutStargate = cons[i][1].name;
		end
	end
 
	-- Seite 1
	AP{ 
		text = "Sir, eine eingehende Aktivierung von "..dialingOutStargate.."! \n \n Wir können nicht rauswählen!",
		position = GetPosition("DHD".._dialingInDHDid),
		dialogCamera = true,
	};
 
	-- ... und los!
	StartBriefing( briefing );
 
end
---------------------------------------------------------------------------------------------
-- DHD Briefing
------------------------------------------------------------------------------
function CreateDHDBriefing( _dialingOutSgID)
 
	-- Das lokale Briefing
	local briefing = {};
	-- AddPage Funktion
	local AP = function( _page ) table.insert( briefing, _page ); return _page; end
 
	-- lokale Speicherung
	local tableN = table.getn(StargateSystem);
	local dialingInSgID;
	local stopped = true;
 
	-- Endseite festlegen
	local lastPage = 4
	for i = 1,tableN do
		if i ~= _dialingOutSgID and StargateSystem[i].dhd.active == 0 then
			lastPage = lastPage +1;
		end
	end
	local endPage = lastPage -1;
	local nextpage = 2;
 
	-- Seite 1
	local firstChoicePage = AP{ 
		mc = {	-- Multiple Choice
					title	= "",
					text = "Sir, wir kennen "..tableN.." Toradressen!",
					firstText = "Eine anwählen!",
					secondText = "Abbrechen!",
					firstSelected = 2,	--  -> Erste Stargateanwahlseite
					secondSelected = endPage,	--  -> Ende
		},
		position = GetPosition("DHD".._dialingOutSgID),
		dialogCamera = true,
	};
 
	-- je nach Systemgröße und Bereitschaft Anwahlmöglichkeiten bieten
	for i = 1,tableN do
		if i ~= _dialingOutSgID and StargateSystem[i].dhd.active == 0 then
			nextpage = nextpage +1;
 
			-- page # 1 - tableN
			StargateSystem[_dialingOutSgID].choicePage[i] = AP{
				mc = {	-- Multiple Choice
					title	= "",
					text = "Welches Gate sollen wir anwählen?",
					firstText = "Stargate"..i,
					secondText = "Nächstes",
					firstSelected = lastPage,	--  -> Nächste Stargateanwahlseite
					secondSelected = nextpage,	--  -> Nächste Auswahlseite
				},
				dialogCamera = true,
			};
		end
	end
 
	-- restart ? page
	local secChoicePage = AP{ 
		mc = {	-- Multiple Choice
					title	= "",
					text = "Sir, mehr Toradressen kennen wir nicht!",
					firstText = "Eine anwählen!",
					secondText = "Abbrechen!",
					firstSelected = 2,	--  -> Erste Stargateanwahlseite
					secondSelected = endPage,	--  -> Ende
		},
		dialogCamera = true,
	};
 
	-- end page
	AP();	-- dient als Ende
 
	-- last page
	AP{ 
		text = "Ja Sir, aktiviere Stargate!",
		position = GetPosition("Stargate".._dialingOutSgID),
		action = function()
 
			-- angewähltes Stargate merken
			for i = tableN,1,-1 do
				if i ~= _dialingOutSgID and GetSelectedBriefingMCButton( StargateSystem[_dialingOutSgID].choicePage[i] ) == 1 then
					dialingInSgID = i;
					break
				end
			end
			assert(type(dialingInSgID) == "number", "SgSystem: dialingInSgID have to be a number!");
 
			-- Verbindung im globalen Table katalogisieren
			StargateSystem[_dialingOutSgID].dhd.active = 1;
			StargateSystem[dialingInSgID].dhd.active = 2;
 
			local iTable = {
				{	-- "StargateSystem.activatedConnections[1][1]" _ entspricht "dialOut"
					id = _dialingOutSgID,
					name = "Stargate".._dialingOutSgID,
					effect = {offsetPos = 0, changePos = 50},
				},
				{	-- "StargateSystem.activatedConnections[1][2]" _ entspricht "dialIn"
					id = dialingInSgID,
					name = "Stargate"..dialingInSgID,
					effect = {offsetPos = 0, changePos = 50},
				},
				counter = 380,
			};
			table.insert(StargateSystem.activatedConnections, iTable);
 
			-- den Ereignishorizont-Effekt starten
			StargateSystem.HorizonEffects = StargateSystem.HorizonEffects or StartSimpleHiResJob("ControlHorizonEffects");
			stopped = false;
			Message("Stargate Aktivierung erfolgt!");
 
		end
	}
 
	-- Die finished Funktion:
	briefing.finished = function()
		-- wenn abgebrochen wurde, dann aktiviere die Stargate-Funktion!
		if not stopped then
			StargateSystem.HoleAktivitys = StargateSystem.HoleAktivitys or StartSimpleJob("ControlStargateHoleAktivitys");
			StargateSystem.Counter = StargateSystem.Counter or StartSimpleJob("CountingStargateActivitys");
		end
	end
 
	-- ... und los!
	StartBriefing( briefing );
 
end
---------------------------------------------------------------------------------------------
-- Wurmloch Funktion
------------------------------------------------------------------------------
function ControlStargateHoleAktivitys()
 
	-- System-Verzeichnis-Verlauf abkürzen
	local cons = StargateSystem.activatedConnections;
 
	for c = table.getn(cons),1,-1 do
 
		-- locale Variablen festlegen
		local outDialStargate = StargateSystem[cons[c][1].id];
		local inDialStargate = StargateSystem[cons[c][2].id];
		local outHorizonPos = outDialStargate.pos;
		local inHorizonPos = inDialStargate.pos;
 
		-- Entities aller Systembenutzer im Anwahlberich ermitteln, ...
		for u = 1,table.getn(StargateSystem.users) do
 
			local player = StargateSystem.users[u];
			local data = {Logic.GetPlayerEntitiesInArea( player, 0, outHorizonPos.X, outHorizonPos.Y, 200, 10)};
			local amount = table.remove(data, 1);
 
			-- ... und durch das Stargate schicken
			for i = 1, amount do
				if Logic.IsEntityInCategory(data[i], EntityCategories.Military) == 1 and Logic.IsEntityInCategory(data[i], EntityCategories.Soldier) == 0 then
 
					local id = GetEntityId( data[i]);
					if GetEntityName( id) == nil then
						-- eventuell lokalen Namen vergeben, ...
						SetEntityName(id, "DataEntity"..i);
					end
 
					local name = GetEntityName( id);
					SetPosition( data[i], inHorizonPos);
					Move( name, inDialStargate.place);
					NpcIsObservedIDUpdate( id, name);
 
					-- ... und nach Gebrauch wieder löschen
					local newId = GetEntityId( name );
					if name == "DataEntity"..i then
						SetEntityName( newId, nil );
					end
 
					-- ermitteln, ob noch jemand rumsteht, ...
					if not AreUseAllowedEntitiesNear( outDialStargate.place, 500 ) and outDialStargate.dhd.ready == true then
						-- ... wenn nicht, Ankunfts-Briefing starten
						CreateWurmlochBriefing( newId , cons[c][1].id);
					end	
 
				end
 
			end
		end
 
	end
end 
---------------------------------------------------------------------------------------------
-- Briefing-npc.id update
------------------------------------------------------------------------------
-- Hier wird die npc.id in den Npc-briefings aktualisiert
function NpcIsObservedIDUpdate( _id, _name)
 
	-- prüfen, ob es der Entity ein Briefing übergeben wurde
	local newId = GetEntityId( _name);
	if NPC ~= nil then
		local npc = NPC[_id];
		if npc ~= nil then
			if npc.briefing ~= nil then
 
				-- wenn ja, alle Seiten durchgehen
				for j = 1, table.getn(npc.briefing) do
					if npc.briefing[j].npc ~= nil then
 
						-- und wenn npc.isObserved mit der alten Id verwendet wird, ...
						if npc.briefing[j].npc.id == _id or npc.briefing[j].npc.id == 0 then
							-- ... dann die Id aktualisieren!
							npc.briefing[j].npc.id = newId;
						end
 
					end
				end
 
			end
		end
	end
 
end 
---------------------------------------------------------------------------------------------
-- Voyager Briefing
------------------------------------------------------------------------------
function CreateWurmlochBriefing(_entity, _dialingOutSgID) 
 
	-- Das lokale Briefing
	local briefing = {};
	-- AddPage Funktion
	local AP = function( _page ) table.insert( briefing, _page ); return _page; end
 
	-- Seite 1
	local showVoyager = AP{ 
		text = "Das ist immer wieder Cool!",
		npc = { id = GetEntityId( _entity), isObserved = true},
		dialogCamera = true,
	};
 
	briefing.finished = function()
		ResolveBriefing( showVoyager );
		DeactivateConnection( _dialingOutSgID );
	end
 
	-- ... los! 
	StartBriefing( briefing );
 
end 
---------------------------------------------------------------------------------------------
-- Ereignishorizont Effekt
------------------------------------------------------------------------------
function ControlHorizonEffects()
 
	-- System-Verzeichnis-Verlauf abkürzen
	local cons = StargateSystem.activatedConnections;
 
	for c = table.getn(cons),1,-1 do
		for i = 1,2 do
 
			local conSg = cons[c][i];
			local effect = conSg.effect;
			local sg = StargateSystem[conSg.id];
 
			-- Ausrichtung des Effects festlegen
			if sg.orientation == 0 or sg.orientation == 180 then
				Logic.CreateEffect(GGL_Effects.FXDie, sg.pos.X, sg.pos.Y -150 +effect.offsetPos, 4);
			else
				Logic.CreateEffect(GGL_Effects.FXDie, sg.pos.X -150 +effect.offsetPos, sg.pos.Y, 4);
			end
 
			-- Effect kreieren
			effect.offsetPos = effect.offsetPos + effect.changePos;
			if effect.offsetPos > 300 then
				effect.offsetPos = 300;
				effect.changePos = effect.changePos * -1;
			end
			if effect.offsetPos < 0 then
				effect.offsetPos = 0;
				effect.changePos = effect.changePos * -1;
			end
 
		end
	end
end 
-------------------------------------------------------------------------------------------------
-- Automatischen Abschalten des Stargates nach 3,8 Minuten
------------------------------------------------------------------------------
-- ( in der TV-Serie "Stargate" sind es eigentlich 38 Minuten )
function CountingStargateActivitys()
 
	-- System-Verzeichnis-Verlauf abkürzen
	local cons = StargateSystem.activatedConnections;
 
	-- für jede Verbindung den counter herunterzählen
	for i = table.getn(cons),1,-1 do
		if ( cons[i].counter > 0 ) then
			if ( cons[i].counter == 380 ) then
				Message("3,8 Minuten bis zum automatischen Abschalten des Stargates!");
			end
			cons[i].counter = cons[i].counter -1;
		else
			-- wenn der counter abgelaufen ist, Verbindung trennen
			DeactivateConnection( cons[i][1].id );
			Message("Automatische Deaktivierung des Stargates erfolgt!");
		end
	end
 
	-- wenn keine Verbindungen mehr aktiv sind, den Job beenden
	if table.getn(cons) == 0 then
		StargateSystem.Counter = nil;
		return true;
	end
 
end
function DeactivateConnection( _dialingOutSgID )
 
	-- System-Verzeichnis-Verlauf abkürzen
	local cons = StargateSystem.activatedConnections;
 
	-- die aktuelle ID der zu trennenden Verbindung ermitteln
	for i = table.getn(cons),1,-1 do
		if cons[i][1].id == _dialingOutSgID then
 
			-- die DHDs beider Stargates der zu trennenden Verbindung sind jetzt nichtmehr aktiv
			StargateSystem[_dialingOutSgID].dhd.active = 0;
			StargateSystem[cons[i][2].id].dhd.active = 0;
 
			-- die Verbindung trennen
			table.remove(cons,i);
			break;
 
		end
	end
 
	-- falls keine Verbindungen mehr bestehen, ...
	if table.getn(cons) == 0 then
		-- ... und die Jobs noch laufen, dann beenden!
		if StargateSystem.HoleAktivitys ~= nil then
			EndJob( StargateSystem.HoleAktivitys );
			StargateSystem.HoleAktivitys = nil;
		end
		if StargateSystem.HorizonEffects ~= nil then
			EndJob( StargateSystem.HorizonEffects );
			StargateSystem.HorizonEffects = nil;
		end
	end
 
end
--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-- Stargate Funktionen enden hier!
--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Die Zusatzcode:

------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Comfort function zum aufrufen von Aktionen im Briefing
------------------------------------------------------------------------------------------------------------------------------------------------------------
function Briefing_ExtraWrapper( _v1, _v2 )
	for i = 1, 2 do --alt
		local theButton = "CinematicMC_Button" .. i;
		XGUIEng.DisableButton( theButton, 1 );
		XGUIEng.DisableButton( theButton, 0 );
	end
	if _v1.action then --neu
		assert( type(_v1.action) == "function" );
		if type(_v1.parameters) == "table" then 
			_v1.action(unpack2(_v1.parameters));
		else
			_v1.action(_v1.parameters);
		end
	end
	Briefing_ExtraOrig( _v1, _v2 );
end
Briefing_ExtraOrig = Briefing_Extra;
Briefing_Extra = Briefing_ExtraWrapper;
 
 
------------------------------------------------------------------------------------------------------------------------------------------------------------
-- "SetPosition" optimierung											by Old McDonald
------------------------------------------------------------------------------------------------------------------------------------------------------------
function SetPosition(_entity, _position)
    assert(type(_entity) == "string" or type(_entity) == "number");
	assert(type(_position) == "table" and type(_position.X) == "number" and type(_position.Y) == "number");
 
	if IsDead(_entity) then
		return;
	end
	_entity = GetEntityId(_entity);
 
	local hurt = Logic.GetEntityMaxHealth(_entity) - Logic.GetEntityHealth(_entity);
	local entityType = Logic.GetEntityType(_entity);
	local name = Logic.GetEntityName(_entity);
	local player = Logic.EntityGetPlayer(_entity);
	local wasSelected = IsEntitySelected(_entity);
	local orientation = Logic.GetEntityOrientation(_entity);
 
	if wasSelected then
		GUI.DeselectEntity(_entity);
	end
	local newEntityId;
 
	--leader is a special case...
	if Logic.IsLeader(_entity) == 1 then
		local army = AI.Entity_GetConnectedArmy(_entity);
		local numberOfSoldiers = Logic.LeaderGetNumberOfSoldiers(_entity);
		local soldiers = {Logic.GetSoldiersAttachedToLeader(_entity)};
		local soldierType = Logic.LeaderGetSoldiersType(_entity);
		local allHurts = {};
		assert(numberOfSoldiers == table.remove(soldiers, 1));
 
		for i = 1, numberOfSoldiers, 1 do
			--get hurt
			table.insert(allHurts, Logic.GetEntityMaxHealth(soldiers[i]) - Logic.GetEntityHealth(soldiers[i]));
			--destroy
			Logic.DestroyEntity(soldiers[i]);
		end
 
		--destroy leader
		Logic.DestroyEntity(_entity);
 
		--create leader
		newEntityId = Logic.CreateEntity(entityType, _position.X, _position.Y, orientation, player);
		for i = 1, numberOfSoldiers, 1 do
			--create soldier
			local soldierId = Logic.CreateEntity(soldierType, _position.X, _position.Y, orientation, player);
			--hurt soldier
			Logic.HurtEntity(soldierId, allHurts[i]);
		end
 
		--add soldier
		Tools.AttachSoldiersToLeader(newEntityId, numberOfSoldiers);
		if army ~= -1 then
			AI.Entity_ConnectLeader(newEntityId, army);
		end
 
	else
		--destroy entity
		Logic.DestroyEntity(_entity);
 
		--create entity
		newEntityId = Logic.CreateEntity(entityType, _position.X, _position.Y, orientation, player);
	end
 
	--entity name
	if name ~= nil then
		Logic.SetEntityName(newEntityId, name);
	end
 
	--selection
	if wasSelected then
		GUI.SelectEntity(newEntityId);
	end
	GroupSelection_EntityIDChanged(_entity, newEntityId);
 
	--hurt it
	Logic.HurtEntity(newEntityId, hurt);
 
end

Schlusswort

Vielen Dank an Old McDonald für die SetPosition-Optimierung! :-)Tenji [2005/11/12 19:22]


Bei Problemen bitte hier im Forum melden!


Zur Tutorial-Übersicht

utilfunctions/setup_stargate_system.txt · Zuletzt geändert: 2021/09/18 19:16 (Externe Bearbeitung)