mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
working on player requests
This commit is contained in:
parent
c19f7b9066
commit
6803d56cbc
3 changed files with 103 additions and 23 deletions
|
@ -12,7 +12,6 @@ public class UIVehicleSpawner : MonoBehaviour
|
|||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(spawnKey))
|
||||
|
@ -24,19 +23,31 @@ public class UIVehicleSpawner : MonoBehaviour
|
|||
|
||||
public void SpawnVehicle()
|
||||
{
|
||||
var cont = PlayerController.Instance;
|
||||
var ped = Ped.Instance;
|
||||
|
||||
if (null == cont)
|
||||
if (null == ped)
|
||||
return;
|
||||
|
||||
|
||||
Vector3 pos = cont.transform.position + cont.transform.forward * spawnOffset.z + cont.transform.up * spawnOffset.y
|
||||
+ cont.transform.right * spawnOffset.x;
|
||||
Quaternion rotation = Quaternion.LookRotation(-cont.transform.right, Vector3.up);
|
||||
|
||||
// SanAndreasUnity.Behaviours.Vehicles.VehicleSpawner.Create ();
|
||||
var v = SanAndreasUnity.Behaviours.Vehicles.Vehicle.Create(-1, null, pos, rotation);
|
||||
Debug.Log("Spawned vehicle with id " + v.Definition.Id);
|
||||
SpawnVehicle(ped);
|
||||
|
||||
}
|
||||
|
||||
public void SpawnVehicle(Ped ped)
|
||||
{
|
||||
|
||||
Vector3 pos = ped.transform.position + ped.transform.forward * spawnOffset.z + ped.transform.up * spawnOffset.y
|
||||
+ ped.transform.right * spawnOffset.x;
|
||||
Quaternion rotation = Quaternion.LookRotation(-ped.transform.right, Vector3.up);
|
||||
|
||||
SpawnVehicle(pos, rotation);
|
||||
|
||||
}
|
||||
|
||||
public void SpawnVehicle(Vector3 pos, Quaternion rotation)
|
||||
{
|
||||
// SanAndreasUnity.Behaviours.Vehicles.VehicleSpawner.Create ();
|
||||
var v = SanAndreasUnity.Behaviours.Vehicles.Vehicle.Create(-1, null, pos, rotation);
|
||||
Debug.Log("Spawned vehicle with id " + v.Definition.Id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +1,87 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using SanAndreasUnity.Utilities;
|
||||
using SanAndreasUnity.Behaviours;
|
||||
|
||||
public class PlayerRequests : MonoBehaviour
|
||||
namespace SanAndreasUnity.Net
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
|
||||
public class PlayerRequests : NetworkBehaviour
|
||||
{
|
||||
|
||||
Player m_player;
|
||||
public static PlayerRequests Local { get; private set; }
|
||||
|
||||
float m_timeWhenSpawnedVehicle = 0f;
|
||||
float m_timeWhenChangedPedModel = 0f;
|
||||
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
m_player = this.GetComponentOrThrow<Player>();
|
||||
}
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
base.OnStartLocalPlayer();
|
||||
Local = this;
|
||||
}
|
||||
|
||||
|
||||
public bool CanPlayerSpawnVehicle()
|
||||
{
|
||||
if (null == m_player.OwnedPed)
|
||||
return false;
|
||||
|
||||
if (Vehicle.NumVehicles > Ped.NumPeds * 2)
|
||||
return false;
|
||||
|
||||
if (Time.time - m_timeWhenSpawnedVehicle < 3f)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanChangePedModel()
|
||||
{
|
||||
if (null == m_player.OwnedPed)
|
||||
return false;
|
||||
if (Time.time - m_timeWhenChangedPedModel < 3f)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RequestVehicleSpawn()
|
||||
{
|
||||
this.CmdRequestVehicleSpawn();
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdRequestVehicleSpawn()
|
||||
{
|
||||
if (!this.CanPlayerSpawnVehicle())
|
||||
return;
|
||||
|
||||
m_timeWhenSpawnedVehicle = Time.time;
|
||||
F.RunExceptionSafe( () => FindObjectOfType<UIVehicleSpawner> ().SpawnVehicle(m_player.OwnedPed) );
|
||||
}
|
||||
|
||||
public void RequestPedModelChange()
|
||||
{
|
||||
this.CmdRequestPedModelChange();
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdRequestPedModelChange()
|
||||
{
|
||||
if (!this.CanChangePedModel())
|
||||
return;
|
||||
|
||||
m_timeWhenChangedPedModel = Time.time;
|
||||
F.RunExceptionSafe( () => m_player.OwnedPed.PlayerModel.Load(Ped.RandomPedId) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
- headless server: start scene specified at cmd line ; use port from cmd line ;
|
||||
|
||||
- add ability for client to request: spawn vehicle ; change ped model ; commit suicide ; destroy my vehicle ; spawn stalker ped ;
|
||||
- add ability for client to request: spawn vehicle ; change ped model ; commit suicide ; destroy my vehicle ; spawn stalker ped ; teleport ;
|
||||
|
||||
- port the whole UI to multiplayer
|
||||
|
||||
|
|
Loading…
Reference in a new issue