Skip to content

Commit

Permalink
improvement: addMounts command to assign mounts to players
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Oct 30, 2024
1 parent 4a40672 commit 08c1ead
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 57 deletions.
38 changes: 0 additions & 38 deletions data/scripts/talkactions/god/add_mount.lua

This file was deleted.

58 changes: 39 additions & 19 deletions data/scripts/talkactions/god/add_mounts.lua
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
-- /addmounts playername
local addMounts = TalkAction("/addmount")

function addMounts.onSay(player, words, param)
-- Create log
logCommand(player, words, param)

local mounts = TalkAction("/addmounts")
function mounts.onSay(player, words, param)
local target
if param == "" then
target = player:getTarget()
if not target then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Unlocks all mounts for certain player. Usage: /mounts <player name>")
return true
end
else
target = Player(param)
player:sendCancelMessage("Command param required.")
return true
end

local split = param:split(",")
if #split < 2 then
player:sendCancelMessage("Usage: /addmount <playername>, <mount id or 'all'>")
return true
end

local playerName = split[1]
local target = Player(playerName)

if not target then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Player " .. param .. " is not currently online.")
player:sendCancelMessage("Player not found.")
return true
end

for i = 1, 221 do
target:addMount(i)
local mountParam = string.trim(split[2])
if mountParam == "all" then
for mountId = 1, 231 do
target:addMount(mountId)
end

target:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has added all mounts to you.", player:getName()))
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have successfully added all mounts to player %s.", target:getName()))
else
local mountId = tonumber(mountParam)
if not mountId then
player:sendCancelMessage("Invalid mount ID.")
return true
end

target:addMount(mountId)
target:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has added a new mount for you.", player:getName()))
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have successfully added mount %d to player %s.", mountId, target:getName()))
end

player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All mounts unlocked for: " .. target:getName())
target:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All of your mounts have been unlocked!")
logger.debug("[addMounts.onSay] - Player: {} has added mount: {} to the player: {}", player:getName(), mountParam, target:getName())
return true
end

mounts:separator(" ")
mounts:groupType("god")
mounts:register()
addMounts:separator(" ")
addMounts:groupType("god")
addMounts:register()

0 comments on commit 08c1ead

Please sign in to comment.