diff --git a/SampSharpGameMode1/Civilisation/PathExtractor.cs b/SampSharpGameMode1/Civilisation/PathExtractor.cs
index 97cd69a..eaa872c 100644
--- a/SampSharpGameMode1/Civilisation/PathExtractor.cs
+++ b/SampSharpGameMode1/Civilisation/PathExtractor.cs
@@ -193,7 +193,7 @@ public enum NodeType : byte
public static void Load()
{
- string heightmapFile = Directory.GetCurrentDirectory() + "\\scriptfiles\\SAfull.hmap";
+ string heightmapFile = Directory.GetCurrentDirectory() + "/scriptfiles/SAfull.hmap";
using (FileStream fs = File.Open(heightmapFile, FileMode.Open, FileAccess.Read))
{
long fsLen = fs.Length;
@@ -220,7 +220,7 @@ public static void Extract(string path, int index)
{
try
{
- string filename = path + "\\NODES" + index + ".DAT";
+ string filename = path + "/NODES" + index + ".DAT";
Random rdm = new Random();
using (FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read))
{
diff --git a/SampSharpGameMode1/Civilisation/RecordCreator.cs b/SampSharpGameMode1/Civilisation/RecordCreator.cs
index fc99722..8d6f55c 100644
--- a/SampSharpGameMode1/Civilisation/RecordCreator.cs
+++ b/SampSharpGameMode1/Civilisation/RecordCreator.cs
@@ -73,7 +73,7 @@ public void AddVehicleBlock(VehicleBlock vehicleBlock)
/// File name with .rec extension
public void Save(string filename)
{
- using (FileStream fs = File.Open(Directory.GetCurrentDirectory() + "\\npcmodes\\recordings\\" + filename, FileMode.Create, FileAccess.Write))
+ using (FileStream fs = File.Open(Directory.GetCurrentDirectory() + "/npcmodes/recordings/" + filename, FileMode.Create, FileAccess.Write))
{
byte[] buffer;
diff --git a/SampSharpGameMode1/Commands/CommonCommands.cs b/SampSharpGameMode1/Commands/CommonCommands.cs
index ba652b0..5d0f3b8 100644
--- a/SampSharpGameMode1/Commands/CommonCommands.cs
+++ b/SampSharpGameMode1/Commands/CommonCommands.cs
@@ -13,24 +13,31 @@ namespace SampSharpGameMode1.Commands
{
class CommonCommands
{
+ [Command("help")]
+ private static void HelpCommand(Player player)
+ {
+ player.SendClientMessage(ColorPalette.Primary.Main + "This is a SA-MP where you can create your own maps, races and derbies !");
+ player.SendClientMessage($"Type {ColorPalette.Secondary.Main}/event-infos{Color.White} to get more information about how to create a map, a race, or a derby.");
+ player.SendClientMessage($"Teleport yourself where you want with {ColorPalette.Secondary.Main}/tlps");
+ player.SendClientMessage($"This server is still in beta, type {ColorPalette.Secondary.Main}/beta{Color.White} to see what is coming soon !");
+ }
[Command("beta")]
private static void BetaCommand(Player player)
{
player.SendClientMessage(ColorPalette.Primary.Main + "These features are still in development and will be ready to test soon:");
- player.SendClientMessage(ColorPalette.Secondary.Main + " - Map creator (in progress)");
- player.SendClientMessage(ColorPalette.Secondary.Main + " - Derby creator and Derby events (need to implement Map creator first)");
- player.SendClientMessage(ColorPalette.Secondary.Main + " - AI / NPC to play with");
- player.SendClientMessage(ColorPalette.Secondary.Main + " - More event types");
+ player.SendClientMessage(" - AI / NPC to play with");
+ player.SendClientMessage(" - More event types");
}
[Command("event-infos")]
private static void EventInfosCommand(Player player)
{
player.SendClientMessage(ColorPalette.Primary.Main + "On this server you can create your own races and derbies, so please read the following instructions:");
- player.SendClientMessage(ColorPalette.Secondary.Main + " - Use /race to see race creator commands, and /derby for derby creator commands");
- player.SendClientMessage(ColorPalette.Secondary.Main + " - Make sure you use a keyboard with numpad (controllers are not supported yet)");
- player.SendClientMessage(ColorPalette.Secondary.Main + " - You can only edit your own event");
- player.SendClientMessage(ColorPalette.Secondary.Main + " - If you want to add a map to your event, create the map first with /map commands, then load it into your event");
- player.SendClientMessage(ColorPalette.Secondary.Main + " - Once your event is playable, everybody can load it and join it");
+ player.SendClientMessage($" - Use {ColorPalette.Secondary.Main}/race{Color.White} to see race creator commands, and {ColorPalette.Secondary.Main}/derby{Color.White} for derby creator commands");
+ player.SendClientMessage($" - Make sure you use a keyboard with numpad (controllers are not supported yet)");
+ player.SendClientMessage($" - You can only edit your own event");
+ player.SendClientMessage($" - If you want to add a map to your event, create the map first with {ColorPalette.Secondary.Main}/map{Color.White} commands, then load it into your event");
+ player.SendClientMessage($" - Don't forget to save your creations with {ColorPalette.Secondary.Main}/race save{Color.White}, {ColorPalette.Secondary.Main}/derby save{Color.White} or {ColorPalette.Secondary.Main}/map save{Color.White}");
+ player.SendClientMessage($" - Once your event is playable, everybody can load it and join it");
}
[Command("s")]
@@ -44,8 +51,11 @@ private static void RCommand(Player player)
{
if (player.LastSavedPosition.Position != Vector3.Zero)
{
- player.Teleport(player.LastSavedPosition.Position + Vector3.UnitZ);
- player.Angle = player.LastSavedPosition.Rotation;
+ if (!player.IsInEvent)
+ {
+ player.Teleport(player.LastSavedPosition.Position + Vector3.UnitZ);
+ player.Angle = player.LastSavedPosition.Rotation;
+ }
}
else
player.SendClientMessage(ColorPalette.Error.Main + "Set the position with /s first");
diff --git a/SampSharpGameMode1/Commands/DerbyCommands.cs b/SampSharpGameMode1/Commands/DerbyCommands.cs
index a2a7c6b..b926c26 100644
--- a/SampSharpGameMode1/Commands/DerbyCommands.cs
+++ b/SampSharpGameMode1/Commands/DerbyCommands.cs
@@ -12,6 +12,61 @@ namespace SampSharpGameMode1.Commands
{
class DerbyCommands
{
+
+ /* Display a list of all the player's races */
+ [Command("myderbies")]
+ private static void MyDerbiesCommand(Player player)
+ {
+ List races = Derby.GetPlayerDerbyList(player);
+ if (races.Count == 0)
+ player.SendClientMessage("You don't have any derbies");
+ else
+ {
+ ListDialog list = new ListDialog(player.Name + "'s derbies", "Options", "Close");
+ list.AddItems(races);
+ list.Response += (object sender, DialogResponseEventArgs e) =>
+ {
+ if (e.DialogButton == DialogButton.Left)
+ {
+ ListDialog actionList = new ListDialog("Action", "Select", "Cancel");
+ actionList.AddItem("Infos ...");
+ actionList.AddItem("Edit");
+ actionList.AddItem("Delete");
+ actionList.Response += (object sender, DialogResponseEventArgs ev) =>
+ {
+ if (ev.DialogButton == DialogButton.Left)
+ {
+ try
+ {
+ int raceid = Convert.ToInt32(races[e.ListItem].Substring(0, races[e.ListItem].IndexOf('_')));
+ switch (ev.ListItem)
+ {
+ case 0: // Infos
+ DerbyCommandsClass.GetInfo(player, raceid);
+ break;
+ case 1: // Edit
+ DerbyCommandsClass.LoadDerbyCreator(player, raceid);
+ break;
+ case 2: // Delete
+ player.SendClientMessage(Color.Red + "This function is not developped yet");
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ MySQLConnector.Instance().CloseReader();
+ Logger.WriteLineAndClose("DerbyCommands.cs - DerbyCommands.MyDerbiesCommand:E: Exception raised: " + ex.Message);
+ player.SendClientMessage(Color.Red + "An error occured");
+ }
+ }
+ };
+ actionList.Show(player);
+ }
+ };
+ list.Show(player);
+ }
+ }
+
[Command("derby")]
private static void DerbyCommandUsage(Player player)
{
@@ -36,7 +91,7 @@ private static void CreateDerby(Player player)
}
[Command("loadc")]
- private static void LoadDerbyCreator(Player player, int id)
+ public static void LoadDerbyCreator(Player player, int id)
{
if (player.pEvent != null)
return;
@@ -142,7 +197,7 @@ private static void EditPickup(Player player, int objectid)
[Command("find")]
private static void FindDerby(Player player, string name)
{
- Dictionary result = DerbyCreator.Find(name);
+ Dictionary result = Derby.Find(name);
if (result.Count == 0)
player.SendClientMessage("No derby found !");
else
@@ -155,9 +210,9 @@ private static void FindDerby(Player player, string name)
}
[Command("info")]
- private static void GetInfo(Player player, int id)
+ public static void GetInfo(Player player, int id)
{
- Dictionary result = DerbyCreator.GetInfo(id);
+ Dictionary result = Derby.GetInfo(id);
if (result.Count == 0)
player.SendClientMessage("No derby found !");
else
@@ -166,7 +221,7 @@ private static void GetInfo(Player player, int id)
string str = "";
foreach (KeyValuePair kvp in result)
{
- str = new Color(50, 50, 255) + kvp.Key + ": " + new Color(255, 255, 255) + kvp.Value;
+ str = Display.ColorPalette.Primary.Main + kvp.Key + ": " + new Color(255, 255, 255) + kvp.Value;
if (str.Length >= 64)
{
infoList.AddItem(str.Substring(0, 63));
diff --git a/SampSharpGameMode1/Commands/MappingCommands.cs b/SampSharpGameMode1/Commands/MappingCommands.cs
index 1badac4..590d610 100644
--- a/SampSharpGameMode1/Commands/MappingCommands.cs
+++ b/SampSharpGameMode1/Commands/MappingCommands.cs
@@ -12,12 +12,66 @@ namespace SampSharpGameMode1.Commands
{
class MappingCommands
{
+
+ /* Display a list of all the player's maps */
+ [Command("mymaps")]
+ private static void MyMapsCommands(Player player)
+ {
+ List maps = Map.GetPlayerMapList(player);
+ if (maps.Count == 0)
+ player.SendClientMessage("You don't have any maps");
+ else
+ {
+ ListDialog list = new ListDialog(player.Name + "'s maps", "Options", "Close");
+ list.AddItems(maps);
+ list.Response += (object sender, DialogResponseEventArgs e) =>
+ {
+ if (e.DialogButton == DialogButton.Left)
+ {
+ ListDialog actionList = new ListDialog("Action", "Select", "Cancel");
+ actionList.AddItem("Infos ...");
+ actionList.AddItem("Edit");
+ actionList.AddItem("Delete");
+ actionList.Response += (object sender, DialogResponseEventArgs ev) =>
+ {
+ if (ev.DialogButton == DialogButton.Left)
+ {
+ try
+ {
+ int mapid = Convert.ToInt32(maps[e.ListItem].Substring(0, maps[e.ListItem].IndexOf('_')));
+ switch (ev.ListItem)
+ {
+ case 0: // Infos
+ MappingCommandClass.GetInfo(player, mapid);
+ break;
+ case 1: // Edit
+ MappingCommandClass.LoadCommand(player, mapid);
+ break;
+ case 2: // Delete
+ player.SendClientMessage(Color.Red + "This function is not developped yet");
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ MySQLConnector.Instance().CloseReader();
+ Logger.WriteLineAndClose("MappingCommands.cs - MappingCommands.MyMapsCommands:E: Exception raised: " + ex.Message);
+ player.SendClientMessage(Color.Red + "An error occured");
+ }
+ }
+ };
+ actionList.Show(player);
+ }
+ };
+ list.Show(player);
+ }
+ }
[Command("mapping", Shortcut = "map")]
private static void MappingCommand(Player player)
{
player.SendClientMessage($"Usage: {ColorPalette.Secondary.Main}/mapping [action]");
player.SendClientMessage($"Global Actions: {ColorPalette.Secondary.Main}help, create, loadc, exit");
- player.SendClientMessage($"On map editing Actions: {ColorPalette.Secondary.Main}help, save, exit, list, addo, delo, replace, marker, dist, edit");
+ player.SendClientMessage($"On map editing Actions: {ColorPalette.Secondary.Main}help, save, exit, info, addo, delo, replace, marker, dist, edit");
}
[CommandGroup("mapping", "map")]
class MappingCommandClass
@@ -29,15 +83,15 @@ private static void HelpCommand(Player player)
$"{ColorPalette.Primary.Main}/mapping create {ColorPalette.Primary.Darken}Create a new map" + "\n" +
$"{ColorPalette.Primary.Main}/mapping loadc [id] {ColorPalette.Primary.Darken}Load a map" + "\n" +
$"{ColorPalette.Primary.Main}/mapping save {ColorPalette.Primary.Darken}Save the map" + "\n" +
- $"{ColorPalette.Primary.Main}/mapping exit {ColorPalette.Primary.Darken}Close the editor without saving the map" + "\n" +
- $"{ColorPalette.Primary.Main}/mapping list {ColorPalette.Primary.Darken}List all your races" + "\n" +
+ $"{ColorPalette.Primary.Main}/mapping exit {ColorPalette.Primary.Darken}Close the editor (save your map first !)" + "\n" +
+ $"{ColorPalette.Primary.Main}/mapping info [id] {ColorPalette.Primary.Darken}Display the info of a map" + "\n" +
$"{ColorPalette.Primary.Main}/mapping addo [modelid] {ColorPalette.Primary.Darken}Add an object with specified modelid" + "\n" +
$"{ColorPalette.Primary.Main}/mapping delo [objectid] {ColorPalette.Primary.Darken}Delete the object" + "\n" +
$"{ColorPalette.Primary.Main}/mapping replace [objectid] [modelid] {ColorPalette.Primary.Darken}Replace the object by the s modelid" + "\n" +
+ $"{ColorPalette.Primary.Main}/mapping dupl [objectid] {ColorPalette.Primary.Darken}Duplicate the object" + "\n" +
$"{ColorPalette.Primary.Main}/mapping marker [1-2] {ColorPalette.Primary.Darken}Edit the marker position to get distance" + "\n" +
$"{ColorPalette.Primary.Main}/mapping dist {ColorPalette.Primary.Darken}Displays the distance between the markers" + "\n" +
- $"{ColorPalette.Primary.Main}/mapping edit [objectid] {ColorPalette.Primary.Darken}Edit position/rotation of object" + "\n" +
- $"{ColorPalette.Primary.Main}/mapping exit {ColorPalette.Primary.Darken}Close the editor"
+ $"{ColorPalette.Primary.Main}/mapping edit [objectid] {ColorPalette.Primary.Darken}Edit position/rotation of object";
;
MessageDialog dialog = new MessageDialog("Command list", list, "Close");
dialog.Show(player);
@@ -51,7 +105,7 @@ private static void CreateCommand(Player player)
player.mapCreator.CreateMap();
}
[Command("loadc")]
- private static void LoadCommand(Player player, int id)
+ public static void LoadCommand(Player player, int id)
{
if (player.pEvent != null)
return;
@@ -189,6 +243,14 @@ private static void ReplaceCommand(Player player, int objectid, int modelid)
else
player.SendClientMessage(Color.Red, $"Map creator is not initialized, create or load a map first");
}
+ [Command("dupl")]
+ private static void DuplicateCommand(Player player, int objectid)
+ {
+ if (!(player.mapCreator is null))
+ player.mapCreator.DuplicateObject(objectid);
+ else
+ player.SendClientMessage(Color.Red, $"Map creator is not initialized, create or load a map first");
+ }
[Command("marker")]
private static void MarkerCommand(Player player, int marker)
{
@@ -213,6 +275,31 @@ private static void EditCommand(Player player, int objectid)
else
player.SendClientMessage(Color.Red, $"Map creator is not initialized, create or load a map first");
}
+
+ [Command("info")]
+ public static void GetInfo(Player player, int id)
+ {
+ Dictionary result = Map.GetInfo(id);
+ if (result.Count == 0)
+ player.SendClientMessage("No map found !");
+ else
+ {
+ var infoList = new ListDialog("Map info", "Ok", "");
+ string str = "";
+ foreach (KeyValuePair kvp in result)
+ {
+ str = Display.ColorPalette.Primary.Main + kvp.Key + ": " + new Color(255, 255, 255) + kvp.Value;
+ if (str.Length >= 64)
+ {
+ infoList.AddItem(str.Substring(0, 63));
+ infoList.AddItem(str.Substring(63));
+ }
+ else
+ infoList.AddItem(str);
+ }
+ infoList.Show(player);
+ }
+ }
}
}
}
diff --git a/SampSharpGameMode1/Commands/RaceCommands.cs b/SampSharpGameMode1/Commands/RaceCommands.cs
index 156478a..7f9ea3d 100644
--- a/SampSharpGameMode1/Commands/RaceCommands.cs
+++ b/SampSharpGameMode1/Commands/RaceCommands.cs
@@ -27,7 +27,7 @@ private static void RespawnCommand(Player player)
[Command("myraces")]
private static void MyRacesCommand(Player player)
{
- List races = RaceCreator.GetPlayerRaceList(player);
+ List races = Race.GetPlayerRaceList(player);
if (races.Count == 0)
player.SendClientMessage("You don't have any races");
else
@@ -64,6 +64,7 @@ private static void MyRacesCommand(Player player)
}
catch (Exception ex)
{
+ MySQLConnector.Instance().CloseReader();
Logger.WriteLineAndClose("RaceCommands.cs - RaceCommands.MyRacesCommand:E: Exception raised: " + ex.Message);
player.SendClientMessage(Color.Red + "An error occured");
}
@@ -229,7 +230,7 @@ private static void AddSG(Player player)
[Command("find")]
private static void FindRace(Player player, string name)
{
- Dictionary result = RaceCreator.Find(name);
+ Dictionary result = Race.Find(name);
if (result.Count == 0)
player.SendClientMessage("No race found !");
else
@@ -244,7 +245,7 @@ private static void FindRace(Player player, string name)
[Command("info")]
public static void GetInfo(Player player, int id)
{
- Dictionary result = RaceCreator.GetInfo(id);
+ Dictionary result = Race.GetInfo(id);
if (result.Count == 0)
player.SendClientMessage("No race found !");
else
@@ -253,7 +254,7 @@ public static void GetInfo(Player player, int id)
string str = "";
foreach (KeyValuePair kvp in result)
{
- str = new Color(50, 50, 255) + kvp.Key + ": " + new Color(255, 255, 255) + kvp.Value;
+ str = Display.ColorPalette.Primary.Main + kvp.Key + ": " + new Color(255, 255, 255) + kvp.Value;
if (str.Length >= 64)
{
infoList.AddItem(str.Substring(0, 63));
diff --git a/SampSharpGameMode1/Commands/TeleportCommands.cs b/SampSharpGameMode1/Commands/TeleportCommands.cs
new file mode 100644
index 0000000..eb096d3
--- /dev/null
+++ b/SampSharpGameMode1/Commands/TeleportCommands.cs
@@ -0,0 +1,145 @@
+using SampSharp.GameMode;
+using SampSharp.GameMode.Definitions;
+using SampSharp.GameMode.Display;
+using SampSharp.GameMode.SAMP;
+using SampSharp.GameMode.SAMP.Commands;
+using SampSharp.GameMode.World;
+using SampSharpGameMode1.Display;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace SampSharpGameMode1.Commands
+{
+ class MapHUD : HUD
+ {
+ protected MySQLConnector mySQLConnector = MySQLConnector.Instance();
+ private Dictionary teleportations = new Dictionary();
+ Player player;
+ public MapHUD(Player player) : base(player, "mapteleport.json")
+ {
+ this.player = player as Player;
+ if (mySQLConnector != null)
+ {
+ float scaleX = 6000 / layer.GetTextdrawSize("mapbox").X;
+ float scaleY = 6000 / layer.GetTextdrawSize("mapbox").Y;
+
+ Dictionary param = new Dictionary();
+ mySQLConnector.OpenReader("SELECT * FROM teleportations WHERE 1=1", param);
+ Dictionary row = mySQLConnector.GetNextRow();
+ int tlpID;
+ string tlpName;
+ Vector3 tlpPosition;
+ Vector2 tlpDisplayedPosition;
+ teleportations.Clear();
+ while (row.Count > 0)
+ {
+ tlpID = Convert.ToInt32(row["teleport_id"]);
+ tlpName = row["teleport_name"];
+ tlpPosition = new Vector3(
+ (float)Convert.ToDouble(row["teleport_pos_x"]),
+ (float)Convert.ToDouble(row["teleport_pos_y"]),
+ (float)Convert.ToDouble(row["teleport_pos_z"])
+ );
+ teleportations[tlpID] = new Vector3R(tlpPosition, (float)Convert.ToDouble(row["teleport_angle"]));
+ tlpDisplayedPosition = new Vector2(
+ (tlpPosition.X + 3000) / scaleX + layer.GetTextdrawPosition("mapbox").X,
+ ((tlpPosition.Y * -1) + 3000) / scaleY + layer.GetTextdrawPosition("mapbox").Y
+ );
+ layer.CreateBackground(player, "tlps_" + tlpID, tlpDisplayedPosition, new Vector2(5, 5), ColorPalette.Secondary.Main.GetColor());
+ layer.SetTextdrawText("tlps_" + tlpID, "LD_POOL:nib");
+ layer.UpdateTextdraw("tlps_" + tlpID);
+ layer.SetClickable("tlps_" + tlpID);
+
+ Color color = ColorPalette.Primary.Main.GetColor();
+ color = new Color(color.R, color.G, color.B, 0.8f);
+ layer.CreateTextdraw(player, "info_" + tlpID, TextdrawLayer.TextdrawType.Box);
+ layer.SetTextdrawText("info_" + tlpID, $"{tlpName}");
+ layer.SetTextdrawSize("info_" + tlpID, 5, 50);
+ layer.SetTextdrawColor("info_" + tlpID, ColorPalette.Secondary.Main.GetColor());
+ layer.SetTextdrawBoxColor("info_" + tlpID, new Color(100, 100, 100, 0.8f));
+ layer.SetTextdrawPosition("info_" + tlpID, layer.GetTextdrawPosition("tlps_" + tlpID) + new Vector2(0, 8));
+ layer.SetTextdrawLetterSize("info_" + tlpID, 0.15f, 0.6f);
+ layer.SetTextdrawFont("info_" + tlpID, 1);
+ layer.SetTextdrawAlignment("info_" + tlpID, 2);
+ layer.SetClickable("info_" + tlpID);
+
+ row = mySQLConnector.GetNextRow();
+ }
+ mySQLConnector.CloseReader();
+ layer.UnselectAllTextdraw();
+
+ layer.TextdrawClicked += OnTextdrawClicked;
+ }
+ else
+ {
+ Logger.WriteLineAndClose("TeleportCommands.cs - MapHUD._:E: MySQL not started");
+ }
+ }
+
+ private void OnTextdrawClicked(object sender, TextdrawLayer.TextdrawEventArgs e)
+ {
+ if(Int32.TryParse(e.TextdrawName.Substring(5), out int tlpID))
+ {
+ player.Teleport(teleportations[tlpID].Position);
+ player.Angle = teleportations[tlpID].Rotation;
+ player.CancelSelectTextDraw();
+ }
+ }
+
+ public void ForceHide()
+ {
+ //layer.Hide("mapbox");
+ }
+ }
+ class TeleportCommands
+ {
+ [Command("tlps")]
+ private static void TlpsCommand(BasePlayer player)
+ {
+ MapHUD mapHUD = new MapHUD(player as Player);
+ mapHUD.Show();
+ mapHUD.ForceHide();
+ player.SelectTextDraw(ColorPalette.Primary.Main.GetColor());
+ player.CancelClickTextDraw += (sender, e) =>
+ {
+ if(mapHUD != null)
+ {
+ mapHUD.Hide();
+ mapHUD = null;
+ }
+ };
+ }
+
+ [CommandGroup("tlps")]
+ class TlpsCommandGroup
+ {
+ [Command("add", PermissionChecker = typeof(AdminPermissionChecker))]
+ private static void AddCommand(BasePlayer player)
+ {
+ InputDialog dialog = new InputDialog("Creating Teleport point", "Type the name of the teleport point", false, "Save", "Cancel");
+ dialog.Response += (sender, e) =>
+ {
+ if(e.DialogButton == DialogButton.Left)
+ {
+ MySQLConnector mySQLConnector = MySQLConnector.Instance();
+ Dictionary param = new Dictionary();
+ param.Add("@name", e.InputText);
+ param.Add("@pos_x", e.Player.Position.X);
+ param.Add("@pos_y", e.Player.Position.Y);
+ param.Add("@pos_z", e.Player.Position.Z);
+ param.Add("@angle", e.Player.Angle);
+ param.Add("@zone", Zone.GetZoneName(e.Player.Position));
+ mySQLConnector.Execute("INSERT INTO teleportations (teleport_name, teleport_pos_x, teleport_pos_y, teleport_pos_z, teleport_angle, teleport_zone) VALUES" +
+ "(@name, @pos_x, @pos_y, @pos_z, @angle, @zone)", param);
+ if (mySQLConnector.RowsAffected > 0)
+ {
+ player.SendClientMessage($"{ColorPalette.Primary.Main}The teleport point {ColorPalette.Secondary.Main}\"{e.InputText}\"{ColorPalette.Primary.Main} has been created");
+ }
+ }
+ };
+ dialog.Show(player);
+ }
+ }
+ }
+}
diff --git a/SampSharpGameMode1/Display/ColorPalette.cs b/SampSharpGameMode1/Display/ColorPalette.cs
index 6aac65d..d043edf 100644
--- a/SampSharpGameMode1/Display/ColorPalette.cs
+++ b/SampSharpGameMode1/Display/ColorPalette.cs
@@ -15,6 +15,11 @@ public SAMPColor(SampSharp.GameMode.SAMP.Color clr)
{
this.color = Color.FromArgb(clr.A, clr.R, clr.G, clr.B);
}
+ public SampSharp.GameMode.SAMP.Color GetColor()
+ {
+ return new SampSharp.GameMode.SAMP.Color(color.R, color.G, color.B, color.A);
+
+ }
public override string ToString()
{
return "{" + color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2") + "}";
diff --git a/SampSharpGameMode1/Display/HUD.cs b/SampSharpGameMode1/Display/HUD.cs
index 7612110..0282eb9 100644
--- a/SampSharpGameMode1/Display/HUD.cs
+++ b/SampSharpGameMode1/Display/HUD.cs
@@ -21,7 +21,7 @@ public class HUD
public HUD(Player player, string jsonFilename)
{
layer = new TextdrawLayer();
- string filename = Directory.GetCurrentDirectory() + "\\scriptfiles\\" + jsonFilename;
+ string filename = Directory.GetCurrentDirectory() + "/scriptfiles/" + jsonFilename;
string jsonData = "";
if (File.Exists(filename))
{
diff --git a/SampSharpGameMode1/Display/TextdrawCreator.cs b/SampSharpGameMode1/Display/TextdrawCreator.cs
index a33fac5..b242e8a 100644
--- a/SampSharpGameMode1/Display/TextdrawCreator.cs
+++ b/SampSharpGameMode1/Display/TextdrawCreator.cs
@@ -25,7 +25,7 @@ public TextdrawHUD(Player player)
{
isSwitched = false;
layer = new TextdrawLayer();
- string filename = Directory.GetCurrentDirectory() + "\\scriptfiles\\tdcreator.json";
+ string filename = Directory.GetCurrentDirectory() + "/scriptfiles/tdcreator.json";
string jsonData = "";
if (File.Exists(filename))
{
@@ -433,7 +433,7 @@ private void ShowTextdrawDialog()
string[] posStr = input.Split(";");
if(double.TryParse(posStr[0], out double posX) && double.TryParse(posStr[1], out double posY))
{
- layers[layerIndex].SetTextdrawPos(editingTDName, new Vector2(posX, posY));
+ layers[layerIndex].SetTextdrawPosition(editingTDName, new Vector2(posX, posY));
UpdateRuler();
}
else player.SendClientMessage(Color.Red, "Format error");
@@ -473,7 +473,7 @@ public void Update()
}
public void Load(string name)
{
- string filename = Directory.GetCurrentDirectory() + "\\scriptfiles\\" + name + ".json";
+ string filename = Directory.GetCurrentDirectory() + "/scriptfiles/" + name + ".json";
string jsonData = "";
if (File.Exists(filename))
{
@@ -566,7 +566,7 @@ public void Save(string name)
output = JsonConvert.SerializeObject(listOfTextdraw, Formatting.Indented);
player.SendClientMessage(output);
- string filename = Directory.GetCurrentDirectory() + "\\scriptfiles\\" + name + ".json";
+ string filename = Directory.GetCurrentDirectory() + "/scriptfiles/" + name + ".json";
try
{
diff --git a/SampSharpGameMode1/Display/TextdrawLayer.cs b/SampSharpGameMode1/Display/TextdrawLayer.cs
index 6b7d174..eb13edb 100644
--- a/SampSharpGameMode1/Display/TextdrawLayer.cs
+++ b/SampSharpGameMode1/Display/TextdrawLayer.cs
@@ -9,6 +9,11 @@ namespace SampSharpGameMode1.Display
{
public class TextdrawLayer
{
+ public class TextdrawEventArgs : EventArgs
+ {
+ public string TextdrawName { get; set; }
+ }
+
private Color editingColor = new Color(180, 50, 50);
Dictionary textdrawList = new Dictionary();
@@ -20,6 +25,13 @@ public class TextdrawLayer
public enum TextdrawType { Background, Box, Text };
public enum EditingMode { Unselected, Position, WidthHeight };
+
+ public event EventHandler TextdrawClicked;
+ protected virtual void OnTextdrawClicked(TextdrawEventArgs e)
+ {
+ TextdrawClicked?.Invoke(this, e);
+ }
+
public Dictionary GetTextdrawList()
{
return textdrawList;
@@ -39,13 +51,14 @@ public Textdraw CreateBackground(BasePlayer owner, string name, Vector2 position
textdrawList[name].type = "background";
textdrawList[name].ForeColor = color;
+
textdrawType[name] = TextdrawType.Background;
textdrawEditMode[name] = EditingMode.Position;
textdrawOrder.Add(name);
textdrawList[name].Show();
return textdrawList[name];
}
- public Textdraw CreateTextdraw(BasePlayer owner, string name, TextdrawType type)
+ public Textdraw CreateTextdraw(BasePlayer owner, string name, TextdrawType type, string text = "")
{
textdrawList.Add(name, new Textdraw(owner, name));
textdrawList[name].Position = new Vector2(320.0f, 240.0f);
@@ -61,7 +74,7 @@ public Textdraw CreateTextdraw(BasePlayer owner, string name, TextdrawType type)
}
else if (type == TextdrawType.Text)
{
- textdrawList[name].text = name;
+ textdrawList[name].text = text;
textdrawList[name].type = "text";
textdrawType[name] = TextdrawType.Text;
}
@@ -105,16 +118,11 @@ public void Destroy()
td.Value.AutoDestroy = true;
this.HideAll();
}
-
- public Boolean SetTextdrawPosition(string name, Vector2 position)
+ public Vector2 GetTextdrawSize(string name)
{
- if (!textdrawList.ContainsKey(name))
+ if (!textdrawType.ContainsKey(name))
throw new TextdrawNameNotFoundException(name);
- float newPosX, newPosY;
- newPosX = (position.X >= 0) ? position.X : textdrawList[name].Position.X;
- newPosY = (position.Y >= 0) ? position.Y : textdrawList[name].Position.Y;
- textdrawList[name].Position = new Vector2(newPosX, newPosY);
- return true;
+ return new Vector2(textdrawList[name].Width, textdrawList[name].Height);
}
public Boolean SetTextdrawSize(string name, float width, float height)
{
@@ -154,11 +162,15 @@ public Vector2 GetTextdrawPosition(string name)
throw new TextdrawNameNotFoundException(name);
return textdrawList[name].Position;
}
- public void SetTextdrawPos(string name, Vector2 pos)
+ public Boolean SetTextdrawPosition(string name, Vector2 position)
{
if (!textdrawList.ContainsKey(name))
throw new TextdrawNameNotFoundException(name);
- textdrawList[name].Position = pos;
+ float newPosX, newPosY;
+ newPosX = (position.X >= 0) ? position.X : textdrawList[name].Position.X;
+ newPosY = (position.Y >= 0) ? position.Y : textdrawList[name].Position.Y;
+ textdrawList[name].Position = new Vector2(newPosX, newPosY);
+ return true;
}
public void SetTextdrawType(string name, TextdrawType type)
@@ -284,14 +296,14 @@ public void UpdateTextdraw(string name)
textdrawList[name].Show();
}
- public void SetOnClickCallback(string name, Action callback)
+ public void SetClickable(string name)
{
textdrawList[name].Selectable = true;
textdrawList[name].Click += (object sender, SampSharp.GameMode.Events.ClickPlayerTextDrawEventArgs e) =>
{
- callback();
+ OnTextdrawClicked(new TextdrawEventArgs { TextdrawName = name });
};
- }
+ }
public bool SelectTextdraw(string name)
{
diff --git a/SampSharpGameMode1/Events/Derbys/Derby.cs b/SampSharpGameMode1/Events/Derbys/Derby.cs
index f1870f3..9dcbaad 100644
--- a/SampSharpGameMode1/Events/Derbys/Derby.cs
+++ b/SampSharpGameMode1/Events/Derbys/Derby.cs
@@ -38,6 +38,7 @@ public class Derby : EventSource
public bool IsLoaded { get; private set; }
public bool IsCreatorMode { get; set; }
public string Creator { get; set; }
+ public float MinimumHeight { get; set; }
// Launcher only
@@ -71,6 +72,14 @@ protected virtual void OnFinished(DerbyFinishedEventArgs e)
#endregion
#region PlayerEvents
+ private void OnPlayerUpdate(object sender, PlayerUpdateEventArgs e)
+ {
+ if(((BasePlayer)sender).Position.Z < this.MinimumHeight)
+ {
+ OnPlayerFinished((Player)sender, "Fall from the map");
+ ((Player)sender).Update -= OnPlayerUpdate;
+ }
+ }
public void OnPlayerDisconnect(object sender, DisconnectEventArgs e)
{
OnPlayerFinished((Player)sender, "Disconnected");
@@ -125,6 +134,7 @@ public void Load(int id, int virtualworld = -1)
{
this.StartingVehicle = null;
}
+ this.MinimumHeight = (float)Convert.ToDouble(row["derby_minheight"]);
}
else
{
@@ -236,6 +246,7 @@ public void Prepare(List slots)
slot.Player.VirtualWorld = virtualWorld;
+ slot.Player.Update += OnPlayerUpdate;
slot.Player.ExitVehicle += OnPlayerExitVehicle;
slot.Player.KeyStateChanged += OnPlayerKeyStateChanged;
slot.Player.Disconnected += OnPlayerDisconnect;
@@ -434,6 +445,7 @@ public void Eject(Player player)
}
player.DisableCheckpoint();
player.DisableRaceCheckpoint();
+ player.Update -= OnPlayerUpdate;
player.ExitVehicle -= OnPlayerExitVehicle;
player.KeyStateChanged -= OnPlayerKeyStateChanged;
player.Disconnected -= OnPlayerDisconnect;
@@ -469,5 +481,79 @@ public bool IsPlayerSpectating(Player player)
{
return this.spectatingPlayers.Contains(player);
}
+
+ public static List GetPlayerDerbyList(Player player)
+ {
+ MySQLConnector mySQLConnector = MySQLConnector.Instance();
+ mySQLConnector = MySQLConnector.Instance();
+ Dictionary param = new Dictionary
+ {
+ { "@name", player.Name }
+ };
+ mySQLConnector.OpenReader("SELECT derby_id, derby_name FROM derbys WHERE derby_creator = @name", param);
+ List result = new List();
+ Dictionary row = mySQLConnector.GetNextRow();
+ while (row.Count > 0)
+ {
+ result.Add(row["derby_id"] + "_" + Display.ColorPalette.Primary.Main + row["derby_name"]);
+ row = mySQLConnector.GetNextRow();
+ }
+ mySQLConnector.CloseReader();
+
+ return result;
+ }
+
+ public static Dictionary Find(string str)
+ {
+ MySQLConnector mySQLConnector = MySQLConnector.Instance();
+ mySQLConnector = MySQLConnector.Instance();
+ Dictionary param = new Dictionary
+ {
+ { "@name", str }
+ };
+ mySQLConnector.OpenReader("SELECT derby_id, derby_name FROM derbys WHERE derby_name LIKE @name", param);
+ Dictionary results = mySQLConnector.GetNextRow();
+ mySQLConnector.CloseReader();
+ return results;
+ }
+ public static Dictionary GetInfo(int id)
+ {
+ // id, name, creator, number of spawn points, number of pickups, number of map objects
+ Dictionary results = new Dictionary();
+ Dictionary row;
+ bool exists = false;
+
+ MySQLConnector mySQLConnector = MySQLConnector.Instance();
+ Dictionary param = new Dictionary
+ {
+ { "@id", id }
+ };
+
+ mySQLConnector.OpenReader("SELECT derby_id, derby_name, derby_creator, map_name FROM derbys LEFT JOIN maps ON (derby_name = map_id) WHERE derby_id = @id", param);
+
+ row = mySQLConnector.GetNextRow();
+ if (row.Count > 0) exists = true;
+ foreach (KeyValuePair kvp in row)
+ results.Add(MySQLConnector.Field.GetFieldName(kvp.Key), kvp.Value);
+
+ mySQLConnector.CloseReader();
+
+ if (exists)
+ {
+ mySQLConnector.OpenReader("SELECT COUNT(*) as nbr " +
+ "FROM derby_spawn WHERE derby_id = @id", param);
+ row = mySQLConnector.GetNextRow();
+ results.Add("Spawn points", row["nbr"]);
+ mySQLConnector.CloseReader();
+
+ mySQLConnector.OpenReader("SELECT COUNT(*) as nbr " +
+ "FROM derby_pickups WHERE derby_id = @id", param);
+ row = mySQLConnector.GetNextRow();
+ results.Add("Pickups", row["nbr"]);
+ mySQLConnector.CloseReader();
+ }
+
+ return results;
+ }
}
}
diff --git a/SampSharpGameMode1/Events/Derbys/DerbyCreator.cs b/SampSharpGameMode1/Events/Derbys/DerbyCreator.cs
index 05a13d4..ab97fe1 100644
--- a/SampSharpGameMode1/Events/Derbys/DerbyCreator.cs
+++ b/SampSharpGameMode1/Events/Derbys/DerbyCreator.cs
@@ -293,9 +293,11 @@ public Boolean Save()
{
{ "@name", editingDerby.Name },
{ "@mapid", editingDerby.MapId == -1 ? null : editingDerby.MapId.ToString() },
+ { "@vehicleid", editingDerby.StartingVehicle },
+ { "@minheight", editingDerby.MinimumHeight },
{ "@id", editingDerby.Id }
};
- mySQLConnector.Execute("UPDATE derbys SET derby_name=@name, derby_map=@mapid WHERE derby_id=@id", param);
+ mySQLConnector.Execute("UPDATE derbys SET derby_name=@name, derby_map=@mapid, derby_startvehicle=@vehicleid, derby_minheight=@minheight WHERE derby_id=@id", param);
isNew = false;
return (mySQLConnector.RowsAffected > 0);
}
@@ -310,11 +312,12 @@ public Boolean Save()
{
{ "@derby_name", name },
{ "@derby_creator", player.Name },
- { "@derby_startvehicle", editingDerby.StartingVehicle }
+ { "@derby_startvehicle", editingDerby.StartingVehicle },
+ { "@derby_minheight", editingDerby.MinimumHeight },
};
editingDerby.Id = (int)mySQLConnector.Execute("INSERT INTO derbys " +
- "(derby_name, derby_creator, derby_startvehicle) VALUES" +
- "(@derby_name, @derby_creator, @derby_startvehicle)", param);
+ "(derby_name, derby_creator, derby_startvehicle, derby_minheight) VALUES" +
+ "(@derby_name, @derby_creator, @derby_startvehicle, @derby_minheight)", param);
if (mySQLConnector.RowsAffected > 0)
{
editingDerby.Name = name;
@@ -407,6 +410,7 @@ private void ShowDerbyDialog()
derbyDialog.AddItem("Edit derby name");
derbyDialog.AddItem("Start Spawn creator");
derbyDialog.AddItem("Load a map ...");
+ derbyDialog.AddItem("Set minimum height");
derbyDialog.Show(player);
derbyDialog.Response += DerbyDialog_Response;
@@ -493,8 +497,8 @@ private void DerbyDialog_Response(object sender, DialogResponseEventArgs e)
hud.SetEditingMode(editingMode);
}
break;
- }
- case 3:
+ }
+ case 3: // Load a map
{
InputDialog findMapDialog = new InputDialog("Find a map", "Type the name of the map you want to load, or empty for full list", false, "Search", "Cancel");
findMapDialog.Show(player);
@@ -512,13 +516,32 @@ private void DerbyDialog_Response(object sender, DialogResponseEventArgs e)
};
break;
}
+ case 4: // Set minimum height
+ {
+ MessageDialog minHeightDialog = new MessageDialog("Setting minimum height", "This setting is used to determinate when player fall from the map. Place yourself on the lowest part of your derby, when you are ready press \"SET\"", "SET", "Cancel");
+ minHeightDialog.Response += (sender, eventArgs) =>
+ {
+ if (eventArgs.DialogButton == DialogButton.Left)
+ {
+ editingDerby.MinimumHeight = player.Position.Z - 10.0f;
+ player.Notificate("Minimum height set");
+ }
+ else
+ {
+ player.Notificate("Cancelled");
+ ShowDerbyDialog();
+ }
+ };
+ minHeightDialog.Show(player);
+ break;
+ }
}
}
}
}
private void ShowLoadMapDialog(string text)
{
- Dictionary maps = Map.FindAll(text);
+ Dictionary maps = Map.FindAll(text, player);
if (maps.Count == 0)
{
player.Notificate("No results");
@@ -632,64 +655,5 @@ private void moverObject_Edited(object sender, EditPlayerObjectEventArgs e)
if(e.EditObjectResponse == EditObjectResponse.Final || e.EditObjectResponse == EditObjectResponse.Cancel)
lastPickedUpPickup = null;
}
-
- public static Dictionary Find(string str)
- {
- MySQLConnector mySQLConnector = MySQLConnector.Instance();
- mySQLConnector = MySQLConnector.Instance();
- Dictionary param = new Dictionary
- {
- { "@name", str }
- };
- mySQLConnector.OpenReader("SELECT derby_id, derby_name FROM derbys WHERE derby_name LIKE @name", param);
- Dictionary results = mySQLConnector.GetNextRow();
- mySQLConnector.CloseReader();
- return results;
- }
- public static Dictionary GetInfo(int id)
- {
- // id, name, creator, type, number of spawn points, number of pickups, number of map objects
- Dictionary results = new Dictionary();
- Dictionary row;
- bool exists = false;
-
- MySQLConnector mySQLConnector = MySQLConnector.Instance();
- Dictionary param = new Dictionary
- {
- { "@id", id }
- };
-
- mySQLConnector.OpenReader("SELECT derby_id, derby_name, derby_creator FROM derbys WHERE derby_id = @id", param);
-
- row = mySQLConnector.GetNextRow();
- if (row.Count > 0) exists = true;
- foreach (KeyValuePair kvp in row)
- results.Add(MySQLConnector.Field.GetFieldName(kvp.Key), kvp.Value);
-
- mySQLConnector.CloseReader();
-
- if(exists)
- {
- mySQLConnector.OpenReader("SELECT COUNT(*) as nbr " +
- "FROM derby_spawn WHERE derby_id = @id", param);
- row = mySQLConnector.GetNextRow();
- results.Add("Spawn points", row["nbr"]);
- mySQLConnector.CloseReader();
-
- mySQLConnector.OpenReader("SELECT COUNT(*) as nbr " +
- "FROM derby_pickups WHERE derby_id = @id", param);
- row = mySQLConnector.GetNextRow();
- results.Add("Pickups", row["nbr"]);
- mySQLConnector.CloseReader();
-
- mySQLConnector.OpenReader("SELECT COUNT(*) as nbr " +
- "FROM derby_mapobjects WHERE derby_id = @id", param);
- row = mySQLConnector.GetNextRow();
- results.Add("Map objects", row["nbr"]);
- mySQLConnector.CloseReader();
- }
-
- return results;
- }
}
}
diff --git a/SampSharpGameMode1/Events/Derbys/DerbyPickupRandomEvent.cs b/SampSharpGameMode1/Events/Derbys/DerbyPickupRandomEvent.cs
index a214c56..86f6a23 100644
--- a/SampSharpGameMode1/Events/Derbys/DerbyPickupRandomEvent.cs
+++ b/SampSharpGameMode1/Events/Derbys/DerbyPickupRandomEvent.cs
@@ -3,7 +3,7 @@
using SampSharp.GameMode.World;
using SampSharp.Streamer.World;
using System;
-using System.Collections.Generic;
+using System.Linq;
using System.Threading;
namespace SampSharpGameMode1.Events.Derbys
@@ -130,17 +130,26 @@ private void OnPlayerKeyStateChanged(Object sender, KeyStateChangedEventArgs eve
SampSharp.GameMode.SAMP.Timer.RunOnce(8000, () =>
{
explosionOffset = new Vector3(rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), 0.0);
- BasePlayer.CreateExplosionForAll(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f);
+ foreach (BasePlayer p in BasePlayer.GetAll().Where(p => p.VirtualWorld == this.Player.VirtualWorld))
+ {
+ p.CreateExplosion(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f);
+ }
});
SampSharp.GameMode.SAMP.Timer.RunOnce(8100, () =>
{
explosionOffset = new Vector3(rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), 0.0);
- BasePlayer.CreateExplosionForAll(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f);
+ foreach (BasePlayer p in BasePlayer.GetAll().Where(p => p.VirtualWorld == this.Player.VirtualWorld))
+ {
+ p.CreateExplosion(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f);
+ }
});
SampSharp.GameMode.SAMP.Timer.RunOnce(8200, () =>
{
explosionOffset = new Vector3(rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), rdm.Next(-MaxAirSupportRdmRange, MaxAirSupportRdmRange), 0.0);
- BasePlayer.CreateExplosionForAll(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f);
+ foreach (BasePlayer p in BasePlayer.GetAll().Where(p => p.VirtualWorld == this.Player.VirtualWorld))
+ {
+ p.CreateExplosion(markerPos + explosionOffset, SampSharp.GameMode.Definitions.ExplosionType.LargeVisibleDamageFire, 50.0f);
+ }
});
SampSharp.GameMode.SAMP.Timer.RunOnce(10000, () =>
{
diff --git a/SampSharpGameMode1/Events/Races/Race.cs b/SampSharpGameMode1/Events/Races/Race.cs
index 1c93659..46d8f40 100644
--- a/SampSharpGameMode1/Events/Races/Race.cs
+++ b/SampSharpGameMode1/Events/Races/Race.cs
@@ -653,6 +653,11 @@ private void UpdatePlayerCheckpoint(Player player)
if (cp == this.checkpoints[this.checkpoints.Count - 1]) // If it's the last checkpoint
{
player.SetRaceCheckpoint(cp.Type + 1, cp.Position, Vector3.Zero, cp.Size);
+ foreach (Player p in spectatingPlayers)
+ {
+ if (players[playersData[p].spectatePlayerIndex] == player)
+ p.SetRaceCheckpoint(cp.Type + 1, cp.Position, Vector3.Zero, cp.Size);
+ }
}
else
{
@@ -660,6 +665,11 @@ private void UpdatePlayerCheckpoint(Player player)
{
Checkpoint nextcp = this.checkpoints[cp.Idx + 1];
player.SetRaceCheckpoint(cp.Type, cp.Position, nextcp.Position, cp.Size);
+ foreach(Player p in spectatingPlayers)
+ {
+ if(players[playersData[p].spectatePlayerIndex] == player)
+ p.SetRaceCheckpoint(cp.Type, cp.Position, nextcp.Position, cp.Size);
+ }
}
catch (KeyNotFoundException e)
{
@@ -885,5 +895,96 @@ public bool IsPlayerSpectating(Player player)
{
return this.spectatingPlayers.Contains(player);
}
+
+
+ public static List GetPlayerRaceList(Player player)
+ {
+ MySQLConnector mySQLConnector = MySQLConnector.Instance();
+ mySQLConnector = MySQLConnector.Instance();
+ Dictionary param = new Dictionary
+ {
+ { "@name", player.Name }
+ };
+ mySQLConnector.OpenReader("SELECT race_id, race_name FROM races WHERE race_creator = @name", param);
+ List result = new List();
+ Dictionary row = mySQLConnector.GetNextRow();
+ while (row.Count > 0)
+ {
+ result.Add(row["race_id"] + "_" + Display.ColorPalette.Primary.Main + row["race_name"]);
+ row = mySQLConnector.GetNextRow();
+ }
+ mySQLConnector.CloseReader();
+
+ return result;
+ }
+
+ public static Dictionary Find(string str)
+ {
+ MySQLConnector mySQLConnector = MySQLConnector.Instance();
+ mySQLConnector = MySQLConnector.Instance();
+ Dictionary param = new Dictionary
+ {
+ { "@name", str }
+ };
+ mySQLConnector.OpenReader("SELECT race_id, race_name FROM races WHERE race_name LIKE @name", param);
+ Dictionary results = mySQLConnector.GetNextRow();
+ mySQLConnector.CloseReader();
+ return results;
+ }
+
+ public static Dictionary GetInfo(int id)
+ {
+ // id, name, creator, number of checkpoints, zone, number of spawnpoints
+ Dictionary results = new Dictionary();
+ Dictionary row;
+
+ MySQLConnector mySQLConnector = MySQLConnector.Instance();
+ Dictionary param = new Dictionary
+ {
+ { "@id", id }
+ };
+
+ mySQLConnector.OpenReader("SELECT race_id, race_name, race_creator, map_name FROM races LEFT JOIN maps ON (race_map = map_id) WHERE race_id = @id", param);
+
+ row = mySQLConnector.GetNextRow();
+ foreach (KeyValuePair kvp in row)
+ results.Add(MySQLConnector.Field.GetFieldName(kvp.Key), kvp.Value);
+
+ mySQLConnector.CloseReader();
+
+ mySQLConnector.OpenReader("SELECT checkpoint_id, checkpoint_number, checkpoint_pos_x, checkpoint_pos_y, checkpoint_pos_z " +
+ "FROM race_checkpoints WHERE race_id = @id", param);
+ int nbrOfCheckpoints = 0;
+ row = mySQLConnector.GetNextRow();
+ Vector3 firstCheckpointPos = new Vector3();
+ while (row.Count > 0)
+ {
+ nbrOfCheckpoints++;
+ if (row["checkpoint_number"] == "0")
+ {
+ firstCheckpointPos = new Vector3(
+ (float)Convert.ToDouble(row["checkpoint_pos_x"]),
+ (float)Convert.ToDouble(row["checkpoint_pos_y"]),
+ (float)Convert.ToDouble(row["checkpoint_pos_z"])
+ );
+ }
+ row = mySQLConnector.GetNextRow();
+ }
+ results.Add("Number of checkpoints", nbrOfCheckpoints.ToString());
+ mySQLConnector.CloseReader();
+
+ string zoneStr = Zone.GetZoneName(firstCheckpointPos);
+ results.Add("Zone", zoneStr);
+
+ mySQLConnector.OpenReader("SELECT COUNT(spawn_index) as nbr " +
+ "FROM race_spawn WHERE race_id = @id", param);
+ row = mySQLConnector.GetNextRow();
+ if (row.Count == 0)
+ results.Add("Number of spawn points", Color.Red + "No spawn point");
+ else
+ results.Add("Number of spawn points", row["nbr"]);
+ mySQLConnector.CloseReader();
+ return results;
+ }
}
}
diff --git a/SampSharpGameMode1/Events/Races/RaceCreator.cs b/SampSharpGameMode1/Events/Races/RaceCreator.cs
index e2edec1..7a19307 100644
--- a/SampSharpGameMode1/Events/Races/RaceCreator.cs
+++ b/SampSharpGameMode1/Events/Races/RaceCreator.cs
@@ -29,7 +29,6 @@ public HUD(Player player) : base(player, "racecreator.json")
layer.SetTextdrawText("totalcp", "Total CP: 0");
layer.SetTextdrawText("editingmode", "Mode: None");
layer.UnselectAllTextdraw();
- layer.SetOnClickCallback("editingmode", OnEditingModeClick);
}
public void Destroy()
{
@@ -56,10 +55,6 @@ public void SetEditingMode(EditingMode editingMode)
layer.SetTextdrawText("editingmode", editingMode.ToString());
this.SetSelectedIdx(selectedIdx, editingMode);
}
- private void OnEditingModeClick()
- {
- Player.SendClientMessageToAll("EditingMode textdraw clicked !");
- }
}
enum EditingMode { Checkpoints, SpawnPos }
@@ -316,9 +311,10 @@ public Boolean Save()
{
{ "@name", editingRace.Name },
{ "@mapid", editingRace.MapId == -1 ? null : editingRace.MapId.ToString() },
+ { "@vehicleid", editingRace.StartingVehicle },
{ "@id", editingRace.Id }
};
- mySQLConnector.Execute("UPDATE races SET race_name=@name, race_map=@mapid WHERE race_id=@id", param);
+ mySQLConnector.Execute("UPDATE races SET race_name=@name, race_map=@mapid, race_startvehicle=@vehicleid WHERE race_id=@id", param);
isNew = false;
return (mySQLConnector.RowsAffected > 0);
}
@@ -657,7 +653,7 @@ private void RaceDialog_Response(object sender, SampSharp.GameMode.Events.Dialog
private void ShowLoadMapDialog(string text)
{
- Dictionary maps = Map.FindAll(text);
+ Dictionary maps = Map.FindAll(text, player);
if (maps.Count == 0)
{
player.Notificate("No results");
@@ -1000,98 +996,5 @@ private void moverObject_Edited(object sender, SampSharp.GameMode.Events.EditPla
player.cameraController.Enabled = true;
}
}
-
- public static List GetPlayerRaceList(Player player)
- {
-
- MySQLConnector mySQLConnector = MySQLConnector.Instance();
- mySQLConnector = MySQLConnector.Instance();
- Dictionary param = new Dictionary
- {
- { "@name", player.Name }
- };
- mySQLConnector.OpenReader("SELECT race_id, race_name FROM races WHERE race_creator = @name", param);
- List result = new List();
- Dictionary row = mySQLConnector.GetNextRow();
- while(row.Count > 0)
- {
- result.Add(row["race_id"] + "_" + Display.ColorPalette.Primary.Main + row["race_name"]);
- row = mySQLConnector.GetNextRow();
- }
- mySQLConnector.CloseReader();
-
- return result;
- }
-
- public static Dictionary Find(string str)
- {
- MySQLConnector mySQLConnector = MySQLConnector.Instance();
- mySQLConnector = MySQLConnector.Instance();
- Dictionary param = new Dictionary
- {
- { "@name", str }
- };
- mySQLConnector.OpenReader("SELECT race_id, race_name FROM races WHERE race_name LIKE @name", param);
- Dictionary results = mySQLConnector.GetNextRow();
- mySQLConnector.CloseReader();
- return results;
- }
-
- public static Dictionary GetInfo(int id)
- {
- // id, name, creator, type, number of checkpoints, zone, number of spawnpoints
- Dictionary results = new Dictionary();
- Dictionary row;
-
- MySQLConnector mySQLConnector = MySQLConnector.Instance();
- Dictionary param = new Dictionary
- {
- { "@id", id }
- };
-
- mySQLConnector.OpenReader("SELECT race_id, race_name, race_creator FROM races WHERE race_id = @id", param);
-
- row = mySQLConnector.GetNextRow();
- foreach (KeyValuePair kvp in row)
- results.Add(MySQLConnector.Field.GetFieldName(kvp.Key), kvp.Value);
-
- mySQLConnector.CloseReader();
-
- mySQLConnector.OpenReader("SELECT checkpoint_id, checkpoint_number, checkpoint_pos_x, checkpoint_pos_y, checkpoint_pos_z " +
- "FROM race_checkpoints WHERE race_id = @id", param);
- int nbrOfCheckpoints = 0;
- row = mySQLConnector.GetNextRow();
- Vector3 firstCheckpointPos = new Vector3();
- while(row.Count > 0)
- {
- nbrOfCheckpoints++;
- if(row["checkpoint_number"] == "0")
- {
- firstCheckpointPos = new Vector3(
- (float)Convert.ToDouble(row["checkpoint_pos_x"]),
- (float)Convert.ToDouble(row["checkpoint_pos_y"]),
- (float)Convert.ToDouble(row["checkpoint_pos_z"])
- );
- }
- row = mySQLConnector.GetNextRow();
- }
- results.Add("Number of checkpoints", nbrOfCheckpoints.ToString());
- mySQLConnector.CloseReader();
-
- // On récupère la zone du premier checkpoint
- Zone zone = new Zone();
- string zoneStr = zone.GetZoneName(firstCheckpointPos);
- results.Add("Zone", zoneStr);
-
- mySQLConnector.OpenReader("SELECT COUNT(spawn_index) as nbr " +
- "FROM race_spawn WHERE race_id = @id", param);
- row = mySQLConnector.GetNextRow();
- if (row.Count == 0)
- results.Add("Number of spawn points", Color.Red + "No spawn point");
- else
- results.Add("Number of spawn points", row["nbr"]);
- mySQLConnector.CloseReader();
- return results;
- }
}
}
diff --git a/SampSharpGameMode1/GameMode.cs b/SampSharpGameMode1/GameMode.cs
index aa612af..b09735f 100644
--- a/SampSharpGameMode1/GameMode.cs
+++ b/SampSharpGameMode1/GameMode.cs
@@ -35,9 +35,19 @@ protected override void OnInitialized(EventArgs e)
#endif
Console.WriteLine("----------------------------------\n");
- //this.AddPlayerClass(1, 1, new Vector3(1431.6393, 1519.5398, 10.5988), 0.0f); // airlv
+ SetGameModeText("Free/Race/Derby");
+
+ this.AddPlayerClass(1, 0, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f);
this.AddPlayerClass(1, 1, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f);
- //this.AddPlayerClass(1, 1, new Vector3(-2699.6025,2381.6885,66.8945), 0.0f);
+ this.AddPlayerClass(1, 2, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f);
+ this.AddPlayerClass(1, 7, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f);
+ this.AddPlayerClass(1, 8, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f);
+ this.AddPlayerClass(1, 12, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f);
+ this.AddPlayerClass(1, 13, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f);
+ this.AddPlayerClass(1, 17, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f);
+ this.AddPlayerClass(1, 19, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f);
+ this.AddPlayerClass(1, 21, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f);
+ this.AddPlayerClass(1, 15, new Vector3(2486.5537, 1531.3606, 10.8191), 316.3417f);
Logger.Init();
@@ -67,7 +77,7 @@ protected override void OnInitialized(EventArgs e)
//Civilisation.PathExtractor.Extract("E:\\Jeux\\GTA San Andreas\\data\\Paths", 54);
for (int i = 0; i < 64; i++)
{
- Civilisation.PathExtractor.Extract(ConfigurationManager.AppSettings["gta_basefolder"] + "\\data\\Paths", i);
+ Civilisation.PathExtractor.Extract(ConfigurationManager.AppSettings["gta_basefolder"] + "/data/Paths", i);
}
sw.Stop();
Logger.WriteLineAndClose($"GameMode.cs - GameMode.OnInitialized:I: PathExtractor.Extract => {sw.ElapsedMilliseconds} ms");
diff --git a/SampSharpGameMode1/Logger.cs b/SampSharpGameMode1/Logger.cs
index e3f0a6c..1ce9996 100644
--- a/SampSharpGameMode1/Logger.cs
+++ b/SampSharpGameMode1/Logger.cs
@@ -8,8 +8,7 @@ namespace SampSharpGameMode1
{
class Logger
{
- private static string filename = Directory.GetCurrentDirectory() + "\\scriptfiles\\gamemode.log";
- //private static string filename = BaseMode.Instance.Client.ServerPath + "..\\..\\scriptfiles\\gamemode.log";
+ private static string filename = Directory.GetCurrentDirectory() + "/scriptfiles/gamemode.log";
FileStream fileStream = null;
@@ -48,16 +47,27 @@ public static void Init()
{
try
{
+ filename = Path.GetFullPath(filename);
FileStream fs = File.Open(filename, FileMode.Create, FileAccess.Write);
fs.Close();
- Logger.WriteLineAndClose("Logger.cs - Logger.Init:I: Logger initialized at " + DateTime.Now.ToString(), false);
- Console.WriteLine("Logger.cs - Logger.Init:I: Logger initialized");
+ if(File.Exists(filename))
+ {
+ Logger.WriteLineAndClose("Logger.cs - Logger.Init:I: Logger initialized at " + DateTime.Now.ToString(), false);
+ Console.WriteLine("Logger.cs - Logger.Init:I: Logger initialized in " + filename);
+ }
+ else
+ Console.WriteLine("Logger.cs - Logger.Init:E: Error during Logger init, file could not be created");
}
catch (IOException e)
{
Console.WriteLine("Logger.cs - Logger.Init:E: Cannot delete logger file: ");
Console.WriteLine(e.Message);
}
+ catch (UnauthorizedAccessException e)
+ {
+ Console.WriteLine("Logger.cs - Logger.Init:E: Cannot delete logger file: ");
+ Console.WriteLine(e.Message);
+ }
}
public static void WriteAndClose(string text, bool writeToConsole = true)
{
diff --git a/SampSharpGameMode1/Map.cs b/SampSharpGameMode1/Map.cs
index 8136b6b..d7f9d20 100644
--- a/SampSharpGameMode1/Map.cs
+++ b/SampSharpGameMode1/Map.cs
@@ -127,16 +127,17 @@ public static List