-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRidableHorses.cs
More file actions
172 lines (149 loc) · 5.5 KB
/
RidableHorses.cs
File metadata and controls
172 lines (149 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using Oxide.Core.Libraries.Covalence;
using System.Collections.Generic;
using UnityEngine;
using Oxide.Core;
using Oxide.Plugins;
namespace Oxide.Plugins
{
[Info("RidableHorses", "Jake_Rich", 0.1)]
[Description("Able to tame and ride horses around")]
public class RidableHorses : RustPlugin
{
public static RidableHorses thisPlugin;
#region Settings
public static int displayMode = 0; //0 = Only from player's belt
//1 = From player's belt and inventory
#endregion
void Loaded()
{
thisPlugin = this;
}
void Unload()
{
foreach(KeyValuePair<BasePlayer,BaseEntity> data in horseData)
{
data.Key.SetParent(null, "");
}
foreach (BaseNetworkable item in fakeEntities)
{
item.Kill();
}
foreach(BasePlayer item in fakePlayers)
{
item.Kill();
}
}
#region Writing
public void Output(params object[] text)
{
string str = "";
for (int i = 0; i < text.Length; i++)
{
str += text[i].ToString() + " ";
}
Puts(str);
}
public static void Write(params object[] text)
{
thisPlugin.Output(text);
}
public static void Write(object text)
{
thisPlugin.Output(text);
}
#endregion
public static Dictionary<BasePlayer, BaseEntity> horseData = new Dictionary<BasePlayer, BaseEntity>();
public static List<BaseNetworkable> fakeEntities = new List<BaseNetworkable>();
public static List<BasePlayer> fakePlayers = new List<BasePlayer>();
public static Dictionary<BaseEntity, BasePlayer> weaponNetworking = new Dictionary<BaseEntity, BasePlayer>();
void SpawnEntity(Vector3 pos, BasePlayer player)
{
string prefab = "assets/prefabs/ammo/arrow/arrow.prefab";
BaseEntity entity = GameManager.server.CreateEntity(prefab);
if (entity != null)
{
entity.Spawn();
entity.SetParent(player, "RustPlayer");
//entity.SetParent(bear, "RustPlayer");
entity.transform.position = new Vector3(0, 0, 0);
entity.transform.rotation = Quaternion.Euler(0, 0, 0);
entity.SendNetworkUpdateImmediate();
fakeEntities.Add(entity);
Write("Object spawned");
}
}
[ChatCommand("horse")]
BaseEntity SpawnHorse(BasePlayer player)
{
string prefab = "assets/bundled/prefabs/autospawn/animals/horse.prefab";
BaseEntity entity = GameManager.server.CreateEntity(prefab,player.transform.position);
if (entity != null)
{
entity.Spawn();
//entity.SetParent(player, "RustPlayer");
//entity.transform.position = new Vector3(0, 0, 0);
//entity.transform.rotation = Quaternion.Euler(0, 0, 0);
entity.SendNetworkUpdate();
fakeEntities.Add(entity);
Write("Horse spawned");
}
return entity;
}
[ChatCommand("ride")]
void RideHorse(BasePlayer player)
{
horseData.Add(player, SpawnHorse(player));
MountHorse(player,horseData[player]);
}
#region Hooks
int tickCount = 0;
void OnTick()
{
if (tickCount >= 1)
{
tickCount = 0;
foreach (KeyValuePair<BasePlayer, BaseEntity> data in horseData)
{
//data.Key.transform.position = Vector3.zero;
//data.Key.transform.localRotation = data.Value.transform.rotation;
data.Key.transform.localRotation = Quaternion.identity;
data.Key.SendNetworkUpdateImmediate();
//data.Value.SendNetworkUpdateImmediate();
}
}
tickCount++;
}
/*
object OnFurnaceSwitch()
{
Puts("Furance activated!");
return null;
}*/
void OnHammerHit(BasePlayer player, HitInfo info)
{
foreach (Item item in player.inventory.containerBelt.itemList)
{
Puts(item.info.shortname.ToString());
}
}
#endregion
void MountHorse(BasePlayer player1,BaseEntity entity)
{
BasePlayer player = SpawnPlayer(player1);
//player = player1;
player.SetParent(entity, "");
player.transform.position = new Vector3(-0.8f, 0f, -0.5f);
player.SendNetworkUpdateImmediate();
}
BasePlayer SpawnPlayer(BasePlayer player)
{
string prefab = "assets/prefabs/player/player.prefab";
BasePlayer newPlayer = (BasePlayer)GameManager.server.CreateEntity(prefab, player.transform.position + new Vector3(0, 0, 1));
newPlayer.Spawn();
//newPlayer.InitializeHealth(1000, 1000);
newPlayer.Heal(100);
fakePlayers.Add(newPlayer);
return newPlayer;
}
}
}