![]() |
|
#1
|
|||
|
|||
|
Is there a way to use the same variable in the host-mission and submission without using a .txt-file(for save variables)?
For example: In host mission script I have count of planes Code:
int countPlanes = 5; Code:
int countPlanes -= 1; Now I now about this variant - http://www.sukhoi.ru/forum/showthrea...=1#post1766444 There are other alternatives a more simple than this? Maybe new class on dll help on it? |
|
#2
|
|||
|
|||
|
Yes a Singleton Pattern in a DLL.
http://en.wikipedia.org/wiki/Singleton_pattern Example Singleton (threadsafe) Code:
public sealed class Singleton
{
public int planeCount { get; set; }
private static readonly Lazy<Singleton> lazy = new Lazy<Singleton>(() => new Singleton());
public static Singleton GetInstance { get { return lazy.Value; } }
private Singleton()
{
// Initialisations
}
}
Code:
//$reference parts/core/MyDll.dll
using System;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using MyNameSpace;
public class Mission : AMission
{
Singleton s=Singleton.GetInstance; // get access to the singleton or create it if not exist.
public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
{
base.OnPlaceEnter(player, actor, placeIndex);
s.planeCount += 1; // example
}
}
Last edited by FG28_Kodiak; 05-24-2012 at 09:48 AM. |
|
#3
|
|||
|
|||
|
Thank you, I hope it's help me.
|
|
#4
|
|||
|
|||
|
Great, it's work.
|
|
#5
|
|||
|
|||
|
My dll-file:
Code:
using System;
namespace smpcore
{
public static class SMPcore
{
public static int addNum(int x, int y)
{
return x + y;
}
}
public sealed class Singleton
{
public int planeCount { get; set; }
// Global side score
public int redScore { get; set; }
public int blueScore { get; set; }
// Number dead units global statistic
public int numberDeadRedPlanes { get; set; } // aircraft unit
public int numberDeadBluePlanes { get; set; } // aircraft unit
public int numberDeadRedAAA { get; set; }
public int numberDeadBlueAAA { get; set; }
public int numberDeadRedTanks { get; set; } // Tank unit
public int numberDeadBlueTanks { get; set; } // Tank unit
public int numberDeadRedArtillery { get; set; } // Artillery unit
public int numberDeadBlueArtillery { get; set; } // Artillery unit
public int numberDeadRedCars { get; set; } // Cars unit
public int numberDeadBlueCars { get; set; } // Cars unit
public int numberDeadRedShips { get; set; } // Ships unit
public int numberDeadBlueShips { get; set; } // Ships unit
private static readonly Lazy<Singleton> lazy = new Lazy<Singleton>(() => new Singleton());
public static Singleton GetInstance { get { return lazy.Value; } }
private Singleton()
{
// Initialisations
planeCount = 1;
// Global side score
redScore = 0;
blueScore = 0;
// Number dead units global statistic
numberDeadRedPlanes = 0; // aircraft unit
numberDeadBluePlanes = 0; // aircraft unit
numberDeadRedAAA = 0;
numberDeadBlueAAA = 0;
numberDeadRedTanks = 0; // Tank unit
numberDeadBlueTanks = 0; // Tank unit
numberDeadRedArtillery = 0; // Artillery unit
numberDeadBlueArtillery = 0; // Artillery unit
numberDeadRedCars = 0; // Cars unit
numberDeadBlueCars = 0; // Cars unit
numberDeadRedShips = 0; // Ships unit
numberDeadBlueShips = 0; // Ships unit
}
}
}
Code:
//$reference "parts\core\smp.dll"
//$reference "parts\core\smpMessage.dll"
using System;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using smpcore;
using smpmessage;
// HOST-MISSION Script
public class Mission : AMission
{
// =========================HOST-MISSION PARAMETERS===========================
// Setup file and folder path
string setupMisMPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\1C SoftClub\\il-2 sturmovik cliffs of dover\\missions\\SMP\\Friday on my mind\\system\\mission_setup.ini";
int unitPlanePrice = 10;
int unitAAAPrice = 3;
int unitTankPrice = 10;
int unitArtilleryPrice = 2;
int unitCarPrice = 2;
int unitShipPrice = 10;
// TESTTESTTESTTESTTESTTEST
Singleton stat = Singleton.GetInstance; // get access to the singleton or create it if not exist.
public override void OnBattleStarted()
{
base.OnBattleStarted();
MissionNumberListener = -1;
smpSendMSG.MessageToAll("BATTLE STARTED!", "Chat");
// LOAD SUBMISSIONS
GamePlay.gpPostMissionLoad("missions\\SMP\\Friday on my mind\\submissions\\Test1\\Test1.mis");
GamePlay.gpPostMissionLoad("missions\\SMP\\Friday on my mind\\submissions\\Test2\\Test2.mis");
}
// =========================OnActorDead=============================
public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
{
base.OnActorDead(missionNumber, shortName, actor, damages);
if (actor != null)
{
// AiGroundActor STATISTIC
if (actor is AiGroundActor)
{
AiGroundActor groundActor = actor as AiGroundActor;
if (groundActor != null)
{
// AAArtillery points
if (groundActor.Type() == AiGroundActorType.AAGun)
{
if (actor.Army() == 1)
{
stat.numberDeadRedAAA ++;
stat.blueScore += unitAAAPrice;
}
else if (actor.Army() == 2)
{
stat.numberDeadBlueAAA++;
stat.redScore += unitAAAPrice;
}
smpSendMSG.MessageToAll("Уничтожена зенитка [ Red/Blue ]:..." + stat.numberDeadRedAAA.ToString() + " / " + stat.numberDeadBlueAAA.ToString(), "Chat");
}
} // null
}
} // null
}
}
other stat. have error Second stat. element in smpSendMSG.MessageToAll - no error. I have error on VS, but script work fine in game. Last edited by podvoxx; 05-26-2012 at 12:27 PM. |
|
#6
|
|||
|
|||
|
No problem by me, do you use a static class with name stat?
if you rename "stat" (singleton) the problem also exist? |
|
#7
|
|||
|
|||
|
I don'n know why, but now I no have this problem. All work very good
|
![]() |
|
|