253 lines
12 KiB
C#
253 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using GrandTheftMultiplayer.Server.API;
|
|
using GrandTheftMultiplayer.Server.Constant;
|
|
using GrandTheftMultiplayer.Server.Elements;
|
|
using GrandTheftMultiplayer.Server.Managers;
|
|
using GrandTheftMultiplayer.Shared;
|
|
using GrandTheftMultiplayer.Shared.Math;
|
|
using MySql.Data.MySqlClient;
|
|
|
|
namespace Roleplay.Fraktionen.Aktionen
|
|
{
|
|
class BadFraktionmanager : Script
|
|
{
|
|
public static string myConnectionString = "SERVER=185.223.28.49;" + "DATABASE=gtanetwork;" + "UID=fivem;" + "PASSWORD=" + Main.databasepass + ";";
|
|
public static MySqlConnection connection;
|
|
public static MySqlCommand command;
|
|
public static MySqlDataReader reader;
|
|
public const int FraktionsKassenCallback = 96846534;
|
|
public BadFraktionmanager()
|
|
{
|
|
loadFraktionsKassen();
|
|
API.onEntityEnterColShape += Fraktionskasse;
|
|
}
|
|
|
|
private void Fraktionskasse(ColShape colshape, NetHandle entity)
|
|
{
|
|
if (entity != null)
|
|
{
|
|
if (API.getEntityType(entity) == EntityType.Player)
|
|
{
|
|
Client player = API.getPlayerFromHandle(entity);
|
|
if (colshape.hasData("fraktionskasse:" + Fraktionsmanager.getFraktion(player)) == true && colshape.getData("fraktionskasse:" + Fraktionsmanager.getFraktion(player)))
|
|
{
|
|
object[] argumentList = new object[13];
|
|
argumentList[0] = FraktionsKassenCallback;
|
|
argumentList[1] = "Fraktionskasse";
|
|
argumentList[2] = "Optionen:";
|
|
argumentList[3] = true;
|
|
argumentList[4] = 3;
|
|
argumentList[5] = "~y~Geld";
|
|
argumentList[6] = "~c~Materialien";
|
|
argumentList[7] = "~r~Schliessen";
|
|
argumentList[8] = "~y~" + getFraktionsMoney(Fraktionsmanager.getFraktion(player)) + "$";
|
|
argumentList[9] = "~c~" + getFraktionsMats(Fraktionsmanager.getFraktion(player)) + "";
|
|
API.triggerClientEvent(player, "menu_handler_create_menu", argumentList);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void loadFraktionsFahrzeuge()
|
|
{
|
|
//MYSQL
|
|
|
|
connection = new MySqlConnection(myConnectionString);
|
|
command = connection.CreateCommand();
|
|
command.CommandText = "SELECT * FROM fraktions_fahrzeuge";
|
|
|
|
connection.Open();
|
|
reader = command.ExecuteReader();
|
|
DataTable results = new DataTable();
|
|
results.Load(reader);
|
|
|
|
foreach (DataRow dr in results.Rows)
|
|
{
|
|
string model = Convert.ToString(dr["model"]);
|
|
int fraktionsid = Convert.ToInt32(dr["fraktionsid"]);
|
|
int SPAWN_X = Convert.ToInt32(dr["SPAWN_X"]);
|
|
int SPAWN_Y = Convert.ToInt32(dr["SPAWN_Y"]);
|
|
int SPAWN_Z = Convert.ToInt32(dr["SPAWN_Z"]);
|
|
int ROTATION = Convert.ToInt32(dr["ROT"]);
|
|
int R = Convert.ToInt32(dr["R"]);
|
|
int G = Convert.ToInt32(dr["G"]);
|
|
int B = Convert.ToInt32(dr["B"]);
|
|
Vehicle veh = API.createVehicle(API.vehicleNameToModel(model), new Vector3(SPAWN_X, SPAWN_Y, SPAWN_Z), new Vector3(0, 0, ROTATION), 0, 0, 0);
|
|
API.setVehicleCustomPrimaryColor(veh, R, G, B);
|
|
API.setVehicleEngineStatus(veh, false);
|
|
API.setEntityData(veh, "Fraktionsfahrzeug", fraktionsid);
|
|
API.setEntitySyncedData(veh, "besitzer", Fraktionsmanager.getFraktionsName(fraktionsid));
|
|
API.setVehicleCustomSecondaryColor(veh, R, G, B);
|
|
API.setVehicleNumberPlate(veh, Fraktionsmanager.getFraktionsName(fraktionsid));
|
|
API.setEntitySyncedData(veh, "locked", true);
|
|
API.sendNativeToPlayersInDimension(0, Hash.SET_VEHICLE_DOORS_LOCKED, veh, 2);
|
|
}
|
|
API.consoleOutput("Loaded " + results.Rows.Count + " Fraktions Fahrzeuge!");
|
|
connection.Close();
|
|
}
|
|
|
|
public static void loadFraktionsFahrzeugebyid(int id)
|
|
{
|
|
//MYSQL
|
|
|
|
connection = new MySqlConnection(myConnectionString);
|
|
command = connection.CreateCommand();
|
|
command.CommandText = "SELECT * FROM fraktions_fahrzeuge WHERE ID = " + id;
|
|
|
|
connection.Open();
|
|
reader = command.ExecuteReader();
|
|
DataTable results = new DataTable();
|
|
results.Load(reader);
|
|
List<NetHandle> vehs = API.shared.getAllVehicles();
|
|
foreach(NetHandle vehaa in vehs)
|
|
{
|
|
if (vehaa != null)
|
|
{
|
|
Vehicle veha = API.shared.getEntityFromHandle<Vehicle>(vehaa);
|
|
if (veha.hasData("Fraktionsfahrzeug") == true && veha.getData("Fraktionsfahrzeug") == id)
|
|
{
|
|
veha.delete();
|
|
}
|
|
}
|
|
}
|
|
foreach (DataRow dr in results.Rows)
|
|
{
|
|
string model = Convert.ToString(dr["model"]);
|
|
int fraktionsid = Convert.ToInt32(dr["fraktionsid"]);
|
|
int SPAWN_X = Convert.ToInt32(dr["SPAWN_X"]);
|
|
int SPAWN_Y = Convert.ToInt32(dr["SPAWN_Y"]);
|
|
int SPAWN_Z = Convert.ToInt32(dr["SPAWN_Z"]);
|
|
int ROTATION = Convert.ToInt32(dr["ROT"]);
|
|
int R = Convert.ToInt32(dr["R"]);
|
|
int G = Convert.ToInt32(dr["G"]);
|
|
int B = Convert.ToInt32(dr["B"]);
|
|
Vehicle veh = API.shared.createVehicle(API.shared.vehicleNameToModel(model), new Vector3(SPAWN_X, SPAWN_Y, SPAWN_Z), new Vector3(0, 0, ROTATION), 0, 0, 0);
|
|
API.shared.setVehicleCustomPrimaryColor(veh, R, G, B);
|
|
API.shared.setVehicleEngineStatus(veh, false);
|
|
API.shared.setEntityData(veh, "Fraktionsfahrzeug", fraktionsid);
|
|
API.shared.setEntitySyncedData(veh, "besitzer", Fraktionsmanager.getFraktionsName(fraktionsid));
|
|
API.shared.setVehicleCustomSecondaryColor(veh, R, G, B);
|
|
API.shared.setVehicleNumberPlate(veh, Fraktionsmanager.getFraktionsName(fraktionsid));
|
|
API.shared.setEntitySyncedData(veh, "locked", true);
|
|
API.shared.sendNativeToPlayersInDimension(0, Hash.SET_VEHICLE_DOORS_LOCKED, veh, 2);
|
|
}
|
|
API.shared.consoleOutput("Loaded " + results.Rows.Count + " Fraktions Fahrzeuge!");
|
|
connection.Close();
|
|
}
|
|
|
|
public void loadFraktionsKassen()
|
|
{
|
|
|
|
connection = new MySqlConnection(myConnectionString);
|
|
command = connection.CreateCommand();
|
|
command.CommandText = "SELECT * FROM fraktions_kassen";
|
|
|
|
connection.Open();
|
|
reader = command.ExecuteReader();
|
|
DataTable results = new DataTable();
|
|
results.Load(reader);
|
|
|
|
foreach (DataRow dr in results.Rows)
|
|
{
|
|
int fraktionsid = Convert.ToInt32(dr["FraktionsID"]);
|
|
int geld = Convert.ToInt32(dr["Geld"]);
|
|
int materialien = Convert.ToInt32(dr["Materialien"]);
|
|
int Marker_X = Convert.ToInt32(dr["Marker_X"]);
|
|
int Marker_Y = Convert.ToInt32(dr["Marker_Y"]);
|
|
int Marker_Z = Convert.ToInt32(dr["Marker_Z"]);
|
|
RAPI.Marker.createMarker(0, new Vector3(Marker_X, Marker_Y, Marker_Z), 1, 255, 0, 0, "fraktionskasse:" + fraktionsid, 0, 185, "Fraktionskasse", 0);
|
|
}
|
|
API.consoleOutput("Loaded " + results.Rows.Count + " Fraktions Kassen!");
|
|
connection.Close();
|
|
}
|
|
|
|
public static int getFraktionsMoney(int fraktionsid)
|
|
{
|
|
connection = new MySqlConnection(myConnectionString);
|
|
command = connection.CreateCommand();
|
|
command.CommandText = "SELECT * FROM fraktions_kassen WHERE FraktionsID = " + fraktionsid;
|
|
int Geld = 0;
|
|
connection.Open();
|
|
reader = command.ExecuteReader();
|
|
while (reader.Read())
|
|
{
|
|
Geld = reader.GetInt32("Geld");
|
|
}
|
|
return Geld;
|
|
}
|
|
|
|
public static int getFraktionsMats(int fraktionsid)
|
|
{
|
|
connection = new MySqlConnection(myConnectionString);
|
|
command = connection.CreateCommand();
|
|
command.CommandText = "SELECT * FROM fraktions_kassen WHERE FraktionsID = " + fraktionsid;
|
|
int Mats = 0;
|
|
connection.Open();
|
|
reader = command.ExecuteReader();
|
|
while (reader.Read())
|
|
{
|
|
Mats = reader.GetInt32("Materialien");
|
|
}
|
|
return Mats;
|
|
}
|
|
|
|
public static void setFraktionsKassenValue( int fraktionsid, string row, int value)
|
|
{
|
|
connection = new MySqlConnection(myConnectionString);
|
|
command = connection.CreateCommand();
|
|
command.CommandText = "UPDATE fraktions_kassen SET " + row + " = " + value + " WHERE FraktionsID = " + fraktionsid;
|
|
connection.Open();
|
|
command.ExecuteNonQuery();
|
|
connection.Close();
|
|
}
|
|
|
|
[Command("ausrauben")]
|
|
public void rob(Client player, int SpielerID)
|
|
{
|
|
if (Fraktionsmanager.isEvil(player) == true)
|
|
{
|
|
Client robber = Commands.cmdLoginRegister.getPlayerFromID(SpielerID);
|
|
if(Jobs.Jobmanager.getPlayingHOURS(robber) >= 10){
|
|
List<Client> nearPlayerss = API.getPlayersInRadiusOfPlayer(5f, player);
|
|
if(Fraktionen.Fraktionsmanager.getFraktion(robber) == 0){
|
|
if (nearPlayerss.Contains(robber) == true)
|
|
{
|
|
if (robber != null)
|
|
{
|
|
API.sendNotificationToPlayer(player, "Du raubst: " + SpielerID + " aus! 10 Sekunden verbleiben!");
|
|
API.sendNotificationToPlayer(robber, "Du wirst ausgeraubt! Entferne dich vom Räuber oder er entnimmt dir etwas Bargeld! 10 Sekunden verbleiben!");
|
|
API.delay(1000 * 10, true, () =>
|
|
{
|
|
List<Client> nearPlayers = API.getPlayersInRadiusOfPlayer(2f, robber);
|
|
if (nearPlayers.Contains(player) == true)
|
|
{
|
|
int money = Environment.MONEY.Money.getBarMoney(robber);
|
|
double robbedmoney = money * 0.15;
|
|
Environment.MONEY.Money.giveBarMoney(player, Convert.ToInt32(+robbedmoney), API, "Du hast " + robbedmoney + " geklaut!");
|
|
Environment.MONEY.Money.giveBarMoney(robber, Convert.ToInt32(-robbedmoney), API, "Jemand hat dir " + robbedmoney + " geklaut!");
|
|
Levelsystem.addPlayerLevelFortschritt(player,1,API);
|
|
}
|
|
else
|
|
{
|
|
API.sendNotificationToPlayer(player, "Der Spieler ist entkommen!");
|
|
API.sendNotificationToPlayer(robber, "Du bist entkommen!");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|