File size: 10,543 Bytes
758cb70 | 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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | -- Events
-- BlockPlace
Parameters
player: Player | nil
Player placing the block (if placed by a player).
position: Vector3
Position in the world the block is being placed at.
blockType: ItemType
The type of the block being placed
cancelled: bool [modifiable]
If set to true, the block place will be denied.
-- Here is a script using this event:
-- Fortify all blocks placed by players to Stone Brick
Events.BlockPlace(function(event)
-- Only fortify player blocks
if (not event.player) then
return
end
-- Only replace wool blocks
if not string.includes(event.blockType, "wool") then
return
end
BlockService.placeBlock(ItemType.STONE_BRICK, event.position)
SoundService.playSound(Sound.FORTIFY_BLOCK, event.position)
event.cancelled = true
end)
-- BlockBreak
Parameters
player: Player | nil
Player who broke the block.
position: Vector3
Position in the world the block was broken at.
blockType: ItemType
The type of the block being placed
-- Here is an example of a script using this event:
Events.BlockBreak(function(event)
if (not event.player) then
return
end
-- Only consider ceramic block breaks
if (event.blockType == ItemType.BLASTPROOF_CERAMIC) then
InventoryService.giveItem(event.player, ItemType.FIREBALL, 1, true)
end
end)
-- BedAlarmTriggered
Parameters
intruder: Player
The intruder player that triggered the bed alarm.
team: Team
The team whose bed alarm went off.
-- Here is an example of a script that uses this event:
-- Send out a broadcast to the game server when a bed alarm is triggered
Events.BedAlarmTriggered(function(event)
local alert = event.intruder.displayName .. " invaded " .. event.team.name .. "'s base!"
MessageService.broadcast(alert)
end)
-- ConsumeItem
Parameters
player: Player
The player that consumed the item.
itemType: ItemType
The item that was consumed by the player.
cancelled: bool [modifiable]
If set to true the item consume will be cancelled.
-- Here is a script that uses this event:
-- Make a player jump twice as high every time they eat a pie item
Events.ConsumeItem(function(event)
if (event.item == ItemType.PIE) then
event.player:registerJumpHeightMultiplier("pie_jumps", 2)
end
end)
-- Enchant
Parameters
player: Player
The player who researched the enchant.
enchant: EnchantType
Type of enchant researched by the player.
cancelled: bool [modifiable]
If set to true, the enchant research will be cancelled.
-- Here is a script that uses this event:
Events.Enchant(function(event)
-- Play the Learn Fire sound if a player receives a Fire 3 Enchant
if (event.enchant == EnchantType.FIRE_3) then
SoundService.playSound(Sound.WHIM_LEARN_FIRE)
end
end)
-- EntityDamage
Parameters
entity: Entity
The entity getting damaged.
fromEntity: Entity | nil
The attacker (if one exists).
damage: number [modifiable]
Amount of damage that will be dealt.
knockback: Knockback [modifiable]
Amount of knockback that will be applied.
cancelled: bool [modifiable]
If set to true the damage will be cancelled.
-- Here is a script using this event:
Events.EntityDamage(function(event)
local matchDurationSec = MatchService.getMatchDurationSec()
-- Double all damage in the game after 15 minutes
if (matchDurationSec > 15 * 60) then
event.damage = event.damage * 2
end
-- Disable damage in first 45s of the game
if (matchDurationSec < 45) then
event.cancelled = true;
end
end)
-- EntityDeath
Parameters
entity: Entity
The killed entity.
killer: Entity | nil
The killer (or nil if not killed by anyone).
assists: Entity[]
List of entities who damaged the victim within the last 15s.
finalKill: bool
True if the killed entity is going to be eliminated after this kill.
-- Here is a script that uses this event:
-- Give players 10 emeralds when they eliminate another player
Events.EntityDeath(function(event)
-- Only give payout if this is a player entity
if (event.entity:getPlayer() == nil) then
return
end
-- Only give payout if this is an elimination
if not event.finalKill then
return
end
-- Pay all assisting players 10 emeralds
for i, entity in ipairs(event.assists) do
if not entity:getPlayer() then
continue
end
InventoryService.giveItem(entity:getPlayer(), ItemType.EMERALD, 10, true)
end
end)
-- EntitySpawn
Parameters
entity: Entity
The spawning entity
-- Here is a script that uses this event:
-- Make all entities have only 1 health
Events.EntitySpawn(function(event)
event.entity:setMaxHealth(1)
end)
-- Forged
Parameters
player: Player
The player who forged the upgrade.
upgrade: ForgeUpgrade
Type of upgrade researched by the player.
level: number
The level of upgrade forged by the player.
-- Here is a script that uses this event:
Events.Forged(function(event)
if (event.upgrade == ForgeUpgrade.SCYTHE) then
-- Give the player the Life Steal effect if they forge a Scythe upgrade
StatusEffectService.giveEffect(event.player:getEntity(), StatusEffect.LIFE_STEAL_3)
-- Give the player a Sky Scythe item if they don't already have one
local currentAmount = InventoryService.getAmount(event.player, ItemType.SKY_SCYTHE)
if (currentAmount == 0) then
InventoryService.giveItem(event.player, ItemType.SKY_SCYTHE, 1, false)
end
end
end)
-- InventoryItemAdded
Parameters
player: Player
The player who received a new item.
item: ItemType
The type of item received by the player.
amount: number
The amount of the item received by the player.
-- Here is a script using this event:
Events.InventoryItemAdded(function(event)
-- Sends a notification to a player that receives the Laser Sword item
if (event.item == ItemType.LASER_SWORD) then
MessageService.sendInfo(event.player, "You have unlocked the power of the force!")
end
end)
-- ItemPurchase
Parameters
player: Player
The player who received a new item.
itemType: ItemType
The type of item received by the player.
amount: number
The amount of the item received by the player.
costItem: ItemType
The type of item used to purchase the specified item.
price: number
The amount of the cost item used to purchase the specified item.
-- Here is a script using this event:
-- Refund 50% of all Iron purchases in the shop
Events.ItemPurchase(function(event)
-- Only refund the player if the resource used to purchase the item is Iron
if (event.costItem == ItemType.IRON) then
-- Round 50% of the price to the closest smaller integer
local refund = math.floor(event.price * 0.5);
InventoryService.giveItem(event.player, ItemType.IRON, refund, true)
end
end)
-- MatchStart
-- Here is an example of a script that uses this event:
-- Play halloween music at the start of the game
Events.MatchStart(function(event)
SoundService.playSound(Sound.HALLOWEEN_2022_BOSS_MUSIC)
end)
-- PlayerChatted
Parameters
player: Player
The player that sent the message
message: string
The message sent by the player
-- Here is a script that uses this event:
-- Add "/rain {item}" command that rains a resource on all players
Events.PlayerChatted(function(event)
-- Split out command from args
local commandArgs = string.split(event.message, " ")
local command = string.lower(commandArgs[1])
-- Check that command is "/rain"
if string.lower(command) ~= "/rain" then
return
end
-- Verify message at least has 2 arguments (command & item type)
if #commandArgs < 2 then
MessageService.sendInfo(event.player, 'Format: /rain <Item Type>')
return
end
local itemType = string.lower(commandArgs[2])
-- Check that item exists
if not ItemType[itemType] then
MessageService.sendInfo(event.player, 'No item exists named ' .. itemType)
return
end
local numDrops = 25
task.spawn(function()
for i=1,numDrops,1 do
for i,player in ipairs(PlayerService.getPlayers()) do
local entity = player:getEntity()
if not entity then
continue
end
local pos = entity:getPosition()
pos = pos + Vector3.new(math.random(-5, 5), 8, math.random(-5, 5))
ItemService.dropItem(itemType, pos)
end
task.wait(0.2)
end
end)
end)
-- PlayerAdded
Parameters
player: Player
The player that joined the game server.
-- Here is a script that uses this event:
Events.PlayerAdded(function (event)
ChatService.sendMessage(event.player.name .. " joined the game!")
end)
Events.PlayerRemoving(function (event)
ChatService.sendMessage(event.player.name .. " left the game.")
end)
-- PlayerRemoving
Parameters
player: Player
The player that is about to leave the game server.
-- Here is a script that uses this event:
Events.PlayerAdded(function (event)
ChatService.sendMessage(event.player.displayName .. " joined the game!")
end)
Events.PlayerRemoving(function (event)
ChatService.sendMessage(event.player.displayName .. " left the game.")
end)
-- PlayerDropItem
Parameters
player: Player
The player that is dropping the item.
itemType: ItemType
The type of item being dropped by the player.
amount: number
The amount of the item being dropped by the player.
cancelled: bool [modifiable]
If set to true, the item drop event will be cancelled.
-- Here is a script that uses this event:
Events.PlayerDropItem(function(event)
if (event.itemType == ItemType.TENNIS_BALL) then
event.cancelled = true
MessageService.sendInfo(event.player, "Be more careful! Those can explode!")
end
end)
-- PlayerPickupItem
Parameters
player: Player
The player that is picking up the item.
itemType: ItemType
The type of item that is being picked up by the player.
amount: number
The amount of the item that is being picked up by the player.
cancelled: bool [modifiable]
If set to true, the item pickup event will be cancelled.
-- Here is a script that uses this event:
Events.PlayerPickupItem(function(event)
if (event.player:getEntity() == nil) then
return
end
if (event.itemType == ItemType.GLITCH_TRUMPET) then
EntityService.spawnKitEntity(KitType.MELODY, event.player:getEntity():getPosition())
AnnouncementService.sendAnnouncement("Let's jam!")
end
end)
|