-
Notifications
You must be signed in to change notification settings - Fork 41
/
cmd_summon.lua
190 lines (174 loc) · 5.75 KB
/
cmd_summon.lua
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
local Minecarts =
{
["minecart"] = E_ITEM_MINECART,
["chest_minecart"] = E_ITEM_CHEST_MINECART,
["furnace_minecart"] = E_ITEM_FURNACE_MINECART,
["hopper_minecart"] = E_ITEM_MINECART_WITH_HOPPER,
["tnt_minecart"] = E_ITEM_MINECART_WITH_TNT,
-- 1.10 and below
["MinecartChest"] = E_ITEM_CHEST_MINECART,
["MinecartFurnace"] = E_ITEM_FURNACE_MINECART,
["MinecartHopper"] = E_ITEM_MINECART_WITH_HOPPER,
["MinecartRideable"] = E_ITEM_MINECART,
["MinecartTNT"] = E_ITEM_MINECART_WITH_TNT
}
local Mobs =
{
["bat"] = mtBat,
["blaze"] = mtBlaze,
["cave_spider"] = mtCaveSpider,
["chicken"] = mtChicken,
["cow"] = mtCow,
["creeper"] = mtCreeper,
["ender_dragon"] = mtEnderDragon,
["enderman"] = mtEnderman,
["ghast"] = mtGhast,
["giant"] = mtGiant,
["guardian"] = mtGuardian,
["horse"] = mtHorse,
["iron_golem"] = mtIronGolem,
["magma_cube"] = mtMagmaCube,
["mooshroom"] = mtMooshroom,
["ocelot"] = mtOcelot,
["pig"] = mtPig,
["rabbit"] = mtRabbit,
["sheep"] = mtSheep,
["silverfish"] = mtSilverfish,
["skeleton"] = mtSkeleton,
["slime"] = mtSlime,
["snowman"] = mtSnowGolem,
["spider"] = mtSpider,
["squid"] = mtSquid,
["villager"] = mtVillager,
["witch"] = mtWitch,
["wither"] = mtWither,
["wither_skeleton"] = mtWitherSkeleton,
["wolf"] = mtWolf,
["zombie"] = mtZombie,
["zombie_pigman"] = mtZombiePigman,
["zombie_villager"] = mtZombieVillager,
-- 1.10 and below
["Bat"] = mtBat,
["Blaze"] = mtBlaze,
["CaveSpider"] = mtCaveSpider,
["Chicken"] = mtChicken,
["Cow"] = mtCow,
["Creeper"] = mtCreeper,
["EnderDragon"] = mtEnderDragon,
["Enderman"] = mtEnderman,
["Ghast"] = mtGhast,
["Giant"] = mtGiant,
["Guardian"] = mtGuardian,
["Horse"] = mtHorse,
["LavaSlime"] = mtMagmaCube,
["MushroomCow"] = mtMooshroom,
["Ozelot"] = mtOcelot,
["Pig"] = mtPig,
["Rabbit"] = mtRabbit,
["Sheep"] = mtSheep,
["Silverfish"] = mtSilverfish,
["Skeleton"] = mtSkeleton,
["Slime"] = mtSlime,
["SnowMan"] = mtSnowGolem,
["Spider"] = mtSpider,
["Squid"] = mtSquid,
["Villager"] = mtVillager,
["VillagerGolem"] = mtIronGolem,
["Witch"] = mtWitch,
["Wither"] = mtWither,
["WitherSkeleton"] = mtWitherSkeleton,
["Wolf"] = mtWolf,
["Zombie"] = mtZombie,
["PigZombie"] = mtZombiePigman,
["ZombieVillager"] = mtZombieVillager
}
local Projectiles =
{
["arrow"] = cProjectileEntity.pkArrow,
["egg"] = cProjectileEntity.pkEgg,
["ender_pearl"] = cProjectileEntity.pkEnderPearl,
["fireworks_rocket"] = cProjectileEntity.pkFirework,
["fireball"] = cProjectileEntity.pkGhastFireball,
["potion"] = cProjectileEntity.pkSplashPotion,
["small_fireball"] = cProjectileEntity.pkFireCharge,
["snowball"] = cProjectileEntity.pkSnowball,
["wither_skull"] = cProjectileEntity.pkWitherSkull,
["xp_bottle"] = cProjectileEntity.pkExpBottle,
-- 1.10 and below
["Arrow"] = cProjectileEntity.pkArrow,
["Fireball"] = cProjectileEntity.pkGhastFireball,
["FireworksRocketEntity"] = cProjectileEntity.pkFirework,
["SmallFireball"] = cProjectileEntity.pkFireCharge,
["Snowball"] = cProjectileEntity.pkSnowball,
["ThrownEgg"] = cProjectileEntity.pkEgg,
["ThrownEnderpearl"] = cProjectileEntity.pkEnderPearl,
["ThrownExpBottle"] = cProjectileEntity.pkExpBottle,
["ThrownPotion"] = cProjectileEntity.pkSplashPotion,
["WitherSkull"] = cProjectileEntity.pkWitherSkull
}
local function SpawnEntity(EntityName, World, X, Y, Z, Player)
if EntityName == "boat" or EntityName == "Boat" then
local Material = cBoat.bmOak
World:SpawnBoat(Vector3d(X, Y, Z), Material)
elseif EntityName == "falling_block" or EntityName == "FallingSand" then
local BlockType = E_BLOCK_SAND
local BlockMeta = 0
World:SpawnFallingBlock(Vector3i(X, Y, Z), BlockType, BlockMeta)
elseif EntityName == "lightning_bolt" or EntityName == "LightningBolt" then
World:CastThunderbolt(Vector3i(X, Y, Z))
elseif Minecarts[EntityName] then
World:SpawnMinecart(Vector3d(X, Y, Z), Minecarts[EntityName])
elseif Mobs[EntityName] then
World:SpawnMob(X, Y, Z, Mobs[EntityName])
elseif Projectiles[EntityName] then
World:CreateProjectile(Vector3d(X, Y, Z), Projectiles[EntityName], Player, Player:GetEquippedItem(), Player:GetLookVector() * 20)
elseif EntityName == "tnt" or EntityName == "PrimedTnt" then
World:SpawnPrimedTNT(Vector3d(X, Y, Z))
elseif EntityName == "xp_orb" or EntityName == "XPOrb" then
local Reward = 1
World:SpawnExperienceOrb(Vector3d(X, Y, Z), Reward)
elseif EntityName == "ender_crystal" or EntityName == "EnderCrystal" then
World:SpawnEnderCrystal(Vector3d(X, Y, Z), false)
else
return false
end
return true
end
function HandleSummonCommand(Split, Player)
local Response
if not Split[2] or (not Player and not Split[5]) then
Response = SendMessage(Player, "Usage: " .. Split[1] .. " <entityname> [x] [y] [z]")
else
local X
local Y
local Z
local World = cRoot:Get():GetDefaultWorld()
if Player then
X = Player:GetPosX()
Y = Player:GetPosY()
Z = Player:GetPosZ()
World = Player:GetWorld()
end
if Split[5] then
X = RelativeCommandCoord(Split[3], X)
Y = RelativeCommandCoord(Split[4], Y)
Z = RelativeCommandCoord(Split[5], Z)
if not X then
return true, SendMessageFailure(Player, "'" .. Split[3] .. "' is not a valid number")
elseif not Y then
return true, SendMessageFailure(Player, "'" .. Split[4] .. "' is not a valid number")
elseif not Z then
return true, SendMessageFailure(Player, "'" .. Split[5] .. "' is not a valid number")
end
end
if SpawnEntity(Split[2], World, X, Y, Z, Player) then
Response = SendMessageSuccess(Player, "Successfully summoned entity at [X:" .. math.floor(X) .. " Y:" .. math.floor(Y) .. " Z:" .. math.floor(Z) .. "]")
else
Response = SendMessageFailure(Player, "Unknown entity '" .. Split[2] .. "'")
end
end
return true, Response
end
function HandleConsoleSummon(Split)
return HandleSummonCommand(Split)
end