• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Mount Command not working properly

Druid Elf

Member
Joined
Oct 18, 2009
Messages
226
Reaction score
12
Location
Kiranthyl
Here's the thing, I have mounts working, but before adding quests/items/npcs or w/e to the server for the player to get the mounts, I'm creating a command for it.

And there comes the problem, I managed to get the mounts on my God character, but I can't give it to anyone >_<
Whenever I type "/mount", I get all the mounts, but when I say any name, nothing happens and the command appear in my default window in yellow.


I've written and rewritten this a few times, lol, this is my lastest try:
LUA:
-- Mount Command - by Druid Elf
-- /mount - gives GM/GOD/CM all mounts
-- /mount PLAYERNAME - gives player all mounts
-- /mount PLAYERNAME, ID - gives player mount with ID equal to ID
-- /mount PLAYERNAME, remove - removes player mounts
function onSay(cid, words, param, channel)
	if(param == "") then
		for i = 1,20 do
			doPlayerAddMountEx(cid, i)
		end
		doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_RED)
		doCreatureSay(cid, "Mounts, HURRAY!", TALKTYPE_ORANGE)
	end
	
	local player, id
	param = string.explode(param, ",")
	if not param[2] then
		if not getPlayerByNameWildcard(param[1]) or getPlayerByNameWildcard(param[1]) == "" then
			return doPlayerSendCancel(cid, "Invalid player name.")
		else
		player = getPlayerByNameWildcard(param[1])
			for i = 1,20 do
				doPlayerAddMountEx(player, i)
			end
		doSendMagicEffect(getPlayerPosition(player), CONST_ME_MAGIC_RED)
		doCreatureSay(player, "Mounts, HURRAY!", TALKTYPE_ORANGE)
		end
	end
	
	if (param[2] ~= 0) then
		player, id = getPlayerByNameWildcard(param[1]), param[2]
		id = type(ach) == "string"
		if (id <= 0) and (id >= 21) then
			doPlayerSendCancel(cid, "Invalid mount ID.")
		else
			doPlayerAddMountEx(player, id)
			doSendMagicEffect(getPlayerPosition(player), CONST_ME_MAGIC_RED)
			doCreatureSay(player, "You received a new mount!", TALKTYPE_ORANGE)
		end
	elseif (param[2] == "remove") then
		player = getPlayerByNameWildcard(param[1])
		for i = 1,20 do
			doPlayerRemoveMountEx(player, i)
		end
		doSendMagicEffect(getPlayerPosition(player), CONST_ME_MAGIC_RED)
		doCreatureSay(player, "No mounts!", TALKTYPE_ORANGE)
	end		
	
	return true
end

Btw, in this lastest try, when I say "/mount" I get all the mounts and then an "Invalid player name." :P and a console error about getting the player.
 
Here's the thing, I have mounts working, but before adding quests/items/npcs or w/e to the server for the player to get the mounts, I'm creating a command for it.

And there comes the problem, I managed to get the mounts on my God character, but I can't give it to anyone >_<
Whenever I type "/mount", I get all the mounts, but when I say any name, nothing happens and the command appear in my default window in yellow.


I've written and rewritten this a few times, lol, this is my lastest try:
LUA:
-- Mount Command - by Druid Elf
-- /mount - gives GM/GOD/CM all mounts
-- /mount PLAYERNAME - gives player all mounts
-- /mount PLAYERNAME, ID - gives player mount with ID equal to ID
-- /mount PLAYERNAME, remove - removes player mounts
function onSay(cid, words, param, channel)
	if(param == "") then
		for i = 1,20 do
			doPlayerAddMountEx(cid, i)
		end
		doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_RED)
		doCreatureSay(cid, "Mounts, HURRAY!", TALKTYPE_ORANGE)
	end
	
	local player, id
	param = string.explode(param, ",")
	if not param[2] then
		if not getPlayerByNameWildcard(param[1]) or getPlayerByNameWildcard(param[1]) == "" then
			return doPlayerSendCancel(cid, "Invalid player name.")
		else
		player = getPlayerByNameWildcard(param[1])
			for i = 1,20 do
				doPlayerAddMountEx(player, i)
			end
		doSendMagicEffect(getPlayerPosition(player), CONST_ME_MAGIC_RED)
		doCreatureSay(player, "Mounts, HURRAY!", TALKTYPE_ORANGE)
		end
	end
	
	if (param[2] ~= 0) then
		player, id = getPlayerByNameWildcard(param[1]), param[2]
		id = type(ach) == "string"
		if (id <= 0) and (id >= 21) then
			doPlayerSendCancel(cid, "Invalid mount ID.")
		else
			doPlayerAddMountEx(player, id)
			doSendMagicEffect(getPlayerPosition(player), CONST_ME_MAGIC_RED)
			doCreatureSay(player, "You received a new mount!", TALKTYPE_ORANGE)
		end
	elseif (param[2] == "remove") then
		player = getPlayerByNameWildcard(param[1])
		for i = 1,20 do
			doPlayerRemoveMountEx(player, i)
		end
		doSendMagicEffect(getPlayerPosition(player), CONST_ME_MAGIC_RED)
		doCreatureSay(player, "No mounts!", TALKTYPE_ORANGE)
	end		
	
	return true
end

Btw, in this lastest try, when I say "/mount" I get all the mounts and then an "Invalid player name." :P and a console error about getting the player.

Hey, im not a very good lua programmer.. xD but isnt param[0] the one b4 the first string explode? /mount playername=[0], ID=[1] ? tried that?
 
Back
Top