Skip to content

Commit

Permalink
Upd
Browse files Browse the repository at this point in the history
  • Loading branch information
werasik2aa authored Mar 10, 2022
1 parent fa1ca67 commit fc867b2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 29 deletions.
5 changes: 3 additions & 2 deletions MenuControll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ public static void Update(int i)
public static void CarStatScreen(string PlayerName, bool allowsit, bool allowdrive, float fuel)
{
string[] ch = new string[3];
if(allowdrive)
if (allowsit)
ch[0] = "Allowed";
else
ch[0] = "Deny";

if (allowsit)
if (allowdrive)
ch[1] = "Allowed";
else
ch[1] = "Deny";

if (fuel >= 0) ch[2] = Mathf.Round(fuel).ToString();
if (NameTag) NameTag.text = "Vehicle by: " + PlayerName + Environment.NewLine + "Can you SIT?: " + ch[0] + Environment.NewLine + "CAN You DRIVE?: " + ch[1] + Environment.NewLine + "FUEL: "+ch[2];
}
Expand Down
10 changes: 10 additions & 0 deletions NETHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public static void NetSendMyCar(string CarName, Vector3 pos, Quaternion rot)
packet.Write(rot);
Send(packet);
}
public static void NETSIT(int CarID, int SitID)
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
Packet packet = packet = new Packet((int)ClientPackets.CUSTOM);

packet.Write(1111);
packet.Write(CarID);
packet.Write(SitID);
Send(packet);
}
public static void NetDeleteCar()
{
if (SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.NONE) return;
Expand Down
17 changes: 14 additions & 3 deletions PACKETS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from)) VehicleController.PlayerCarMove(ID, name, Position, Rotation);
if (CheckEnv(from) && data.GetObj(ID)) VehicleController.PlayerCarMove(ID, name, Position, Rotation);
}

if (packetid == 1000) // SPAWN CAR
Expand Down Expand Up @@ -71,7 +71,7 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from)) VehicleController.engineSound(curspeed, ID);
if (CheckEnv(from) && data.GetObj(ID)) VehicleController.engineSound(curspeed, ID);
}
if (packetid == 1110) // SEND Sound OFF
{
Expand All @@ -82,7 +82,18 @@ static void Postfix(SkyCoop.API __instance, Packet _pak, int from)
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from)) VehicleController.engineSoundOff(ID);
if (CheckEnv(from) && data.GetObj(ID)) VehicleController.engineSoundOff(ID);
}
if (packetid == 1111) // SEND Sound OFF
{
int ID = _pak.ReadInt();
int SitID = _pak.ReadInt();
if (from == -1 && SkyCoop.API.m_ClientState == SkyCoop.API.SkyCoopClientState.CLIENT)
{
from = _pak.ReadInt();
}
if (API.m_ClientState == API.SkyCoopClientState.HOST) API.SendDataToEveryone(_pak, from, true);
if (CheckEnv(from) && data.GetObj(ID)) VehicleController.CHANGESIT(data.GetObj(ID), SitID, from);
}
}
private static bool CheckEnv(int from)
Expand Down
50 changes: 33 additions & 17 deletions VehicleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class VehicleController
public static Transform cameracenter = null;
public static Transform cameracar = null;
public static bool fps;
//private static AudioSource audio;
private static int siter;

//CAR PARAMS
public static float maxspeed = 40;
Expand All @@ -42,6 +42,7 @@ public static void MoveDrive(GameObject car)
if (!car) return;
if (!main.vehicles.ContainsKey(int.Parse(car.name))) return;
Transform sit = car.transform.Find("SIT1");
NETHost.NETSIT(int.Parse(car.name), siter);
CameraFollow(car);//FOLLOW CAMERA
curspeed = rb.velocity.magnitude;
curX += Input.GetAxis("Mouse X") * 4f;
Expand Down Expand Up @@ -98,8 +99,6 @@ public static void MoveDrive(GameObject car)
}
public static void PlayerCarMove(int CarID, string CarName, Vector3 Position, Quaternion Rotation)
{
if (!main.vehicles.ContainsKey(CarID)) return;

GetObj(CarID).transform.rotation = Rotation;
GetObj(CarID).transform.position = Vector3.Lerp(GetObj(CarID).transform.position, Position, 15);
}
Expand Down Expand Up @@ -161,7 +160,6 @@ public static void SitCar(GameObject car)
MelonLogger.Msg("[Interact] Trying to interact with car ID:> " + car.name);
audio = car.GetComponent<AudioSource>();
rb = car.GetComponent<Rigidbody>();
bool ise;
if (main.isSit)
{
if (main.allowdrive)
Expand All @@ -182,17 +180,17 @@ public static void SitCar(GameObject car)
MenuControll.Open(1);
if(audio) audio.Stop();
NetSoundOff(int.Parse(car.name));
CHANGESIT(car, 0);
siter = 0;
}
else
{
if (main.allowdrive)
{
data.UpdateDriver(int.Parse(car.name), true);
CHANGESIT(car, 1);
NetSendDriver(int.Parse(car.name), true);
}else {
CHANGESIT(car, 2);
siter = 1;
} else {
siter = 2;
}
foreach (Collider col in GameManager.GetVpFPSPlayer().GetComponents<Collider>())
{
Expand All @@ -209,6 +207,8 @@ public static void SitCar(GameObject car)
cameracar.transform.position = car.transform.Find("CAMERACENTER").position;
main.targetcar = car;
}

CHANGESIT(car, siter, main.MyId);
MelonLogger.Msg("[Sit Manager]: " + main.allowdrive + "|" +isDrive(int.Parse(car.name)));
}
public static void engineSound(float curspeed, int ID)
Expand All @@ -222,9 +222,10 @@ public static void engineSound(float curspeed, int ID)
var dist = Vector3.Distance(GetObj(ID).transform.position, main.MyPosition.position); ;

if (dist > 10) audio.volume = dist / 20f;
if (dist > 20) audio.volume = dist / 50f;
if (dist < 20) audio.volume = dist / 50f;
if (dist <= 1) audio.volume = dist;
audio.pitch = (0.30f + curspeed * 0.025f);
if (dist > 20) audio.volume = 0;
audio.pitch = (0.30f + curspeed * 0.025f);
if (curspeed > 30)
{
audio.pitch = (0.25f + curspeed * 0.015f);
Expand All @@ -244,22 +245,37 @@ public static void engineSound(float curspeed, int ID)
}
}
}
private static void CHANGESIT(GameObject car, int i)
public static void CHANGESIT(GameObject car, int i, int from)
{
if(i == 0)
{
if (i == 0 && main.MyId == from) {
GameManager.GetVpFPSPlayer().transform.parent = null;
GameManager.GetPlayerTransform().transform.parent = null;
GameManager.GetPlayerManagerComponent().TeleportPlayer(main.MyPosition.position - car.transform.right * 2.5f + car.transform.up, Quaternion.identity);
GameManager.GetPlayerManagerComponent().StickPlayerToGround();
return;
}
if (main.allowdrive)
if (main.MyId == from && i != 0)
{
Transform sit = car.transform.Find("SIT"+i);
if (!car.transform.Find("SIT" + siter)) {
CHANGESIT(car, 0, main.MyId);
return;
};
Transform sit = car.transform.Find("SIT" + siter);
GameManager.GetVpFPSPlayer().transform.position = sit.position;
GameManager.GetPlayerTransform().transform.position = sit.position;
GameManager.GetVpFPSPlayer().transform.parent = car.transform;
GameManager.GetPlayerTransform().transform.parent = car.transform;
return;
}
if (i == 0)
{
SkyCoop.MyMod.players[from].transform.parent = null;
}
if (i != 0)
{
Transform sit = car.transform.Find("SIT" + i);
SkyCoop.MyMod.players[from].transform.parent = car.transform;
SkyCoop.MyMod.players[from].transform.position = sit.position;
}
}
public static void engineSoundOff(int ID)
Expand All @@ -268,7 +284,7 @@ public static void engineSoundOff(int ID)
audio = GetObj(ID).GetComponent<AudioSource>();
if(audio) audio.Stop();
}
private static void CameraFollow(GameObject car)
private static void CameraFollow(GameObject car)
{
if (!fps)
{
Expand All @@ -286,7 +302,7 @@ private static void CameraFollow(GameObject car)
{
cameracar.transform.parent = car.transform;
cameracar.transform.localRotation = Quaternion.Euler(-curY, curX, 0);
cameracar.transform.position = car.transform.Find("SIT1").position + car.transform.up * 1.7f;
if (car.transform.Find("SIT" + siter)) cameracar.transform.position = car.transform.Find("SIT"+siter).position + car.transform.up * 1.7f;
}
}
}
Expand Down
19 changes: 12 additions & 7 deletions main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public override void OnSceneWasLoaded(int level, string name)
levelname = name;
Paused = false;

MelonLogger.Msg("[Garbage Collector] Clearing Vehicle list on level:> " + levelname);
vehicles.Clear();
vehicledata.Clear();
drivers.Clear();

allowdrive = false;
isSit = false; // SET FALSE BECAUSE LEVEL CHANGED AND CAR ERASED
targetcar = null;
Expand All @@ -79,12 +84,12 @@ public override void OnSceneWasLoaded(int level, string name)
}
public override void OnUpdate()
{
if (levelname == "Empty" || levelname == "MainMenu" || levelname == "Boot" || levelname == "") return;
if (levelname == "Empty" || levelname == "MainMenu" || levelname == "Boot" || levelname == "" || GameManager.m_IsPaused) return;
VehicleController.turn = Input.GetAxis("Horizontal");
VehicleController.move = Input.GetAxis("Vertical");
MyId = API.m_MyClientID;
MyNick = SkyCoop.MyMod.MyChatName;
if(GameManager.GetVpFPSCamera().m_Camera) ray = GameManager.GetVpFPSCamera().m_Camera.ScreenPointToRay(Input.mousePosition);
if(vehicles.Count > 0) ray = GameManager.GetVpFPSCamera().m_Camera.ScreenPointToRay(Input.mousePosition);
MyPosition = GameManager.GetPlayerTransform().transform;
if (Input.GetKeyDown(KeyCode.Escape)) if (Paused) Paused = false; else Paused = true;
// fuck
Expand Down Expand Up @@ -148,11 +153,11 @@ private IEnumerator sendMycarPos(float waitTime)
}
public override void OnLateUpdate()
{
if (levelname == "Empty" || levelname == "MainMenu" || levelname == "Boot" || levelname == "") return;
if (levelname == "Empty" || levelname == "MainMenu" || levelname == "Boot" || levelname == "" || GameManager.m_IsPaused) return;

if (vehicles.ContainsKey(MyId) && !isDrive(MyId))
sendMycarPos(2);
if(isSit) SkyCoop.MyMod.MyAnimState = "Sit";
if(isSit && vehicles.Count > 0) SkyCoop.MyMod.MyAnimState = "Sit";
MenuControll.Update(0); // COUNT CARS
MenuControll.Update(1); // COOUNT SPEED
MenuControll.Update(2); // COUNT FUEL
Expand All @@ -166,9 +171,10 @@ public override void OnLateUpdate()
string othname = "Unknown";
try { number = int.Parse(ho.name); } catch (Exception e) { return; }
if (!vehicledata.ContainsKey(number)) return;
if (GetObj(number).transform.Find("CAMERACENTER")) return;

othname = SkyCoop.MyMod.playersData[number].m_Name;
if (number == MyId) othname = MyNick;
if (!vehicledata.ContainsKey(number)) return;

MenuControll.Open(2);
MenuControll.CarStatScreen(othname, bool.Parse(CarData(number)[0]), !isDrive(number), Mathf.Round(VehicleController.curfuel));
Expand All @@ -183,7 +189,7 @@ public override void OnLateUpdate()
}
public override void OnFixedUpdate()
{
if (levelname == "Empty" || levelname == "MainMenu" || levelname == "Boot" || levelname == "") return;
if (levelname == "Empty" || levelname == "MainMenu" || levelname == "Boot" || levelname == "" || GameManager.m_IsPaused) return;
if (vehicles.Count != 0) foreach (var i in vehicles) if (i.Value) VehicleController.wheel(i.Value);
if (isSit) VehicleController.MoveDrive(targetcar);
}
Expand Down Expand Up @@ -224,7 +230,6 @@ public static void SpawnCar(int PlayerId, int SceneId, string name, Vector3 Posi
key1.layer = LayerMask.NameToLayer("Player");

GameObject[] par = key1.GetComponentsInChildren<GameObject>();

foreach (GameObject b in par)
{
b.layer = LayerMask.NameToLayer("NPC");
Expand Down

0 comments on commit fc867b2

Please sign in to comment.