• 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!

Solved Script error

Phemus

Member
Joined
Jun 16, 2012
Messages
150
Solutions
2
Reaction score
13
Hello! I have a script error.

LUA:
local outfits = {205,15,25,15,110,125,106,107,18}

local FOODS =
{
  [6394] = {1, "Transformation!"}
  }

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local food = FOODS[item.itemid]
	if(not food) then
		return false
	end

	if((getPlayerFood(cid) + food[1]) >= 400) then
		doPlayerSendCancel(cid, "You are full.")
		return true
	end

	doPlayerFeed(cid, food[1] * 4)
	doCreatureSay(cid, food[2], TALKTYPE_ORANGE_1)
	doSetCreatureOutfit(cid, {lookType = outfits[math.random(#outfits)]})
	doSendMagicEffect(getCreaturePos(cid), 17)
	doRemoveItem(item.uid, 1)
	return true
end

What it is supposed to do is that when somebody eats it, the player changes outfit randomly. In the console, it tells me this:

Code:
[Error - Action Interface] 
[16/08/2013 20:58:33] data/actions/scripts/by phemus/cream cake.lua:onUse
[16/08/2013 20:58:33] Description: 
[16/08/2013 20:58:33] attempt to index a number value
[16/08/2013 20:58:33] stack traceback:
[16/08/2013 20:58:33] 	[C]: in function 'doSetCreatureOutfit'
[16/08/2013 20:58:33] 	data/actions/scripts/by phemus/cream cake.lua:21: in function <data/actions/scripts/by phemus/cream cake.lua:8>

Can somebody help me?
Thanks :)
 
Last edited:
try
LUA:
local outfits = {205,15,25,15,110,125,106,107,18}
 
local FOODS =
{
  [6394] = {1, "Transformation!"}
  }
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local food = FOODS[item.itemid]
	if(not food) then
		return false
	end
 
	if((getPlayerFood(cid) + food[1]) >= 400) then
		doPlayerSendCancel(cid, "You are full.")
		return true
	end
 
	doPlayerFeed(cid, food[1] * 4)
	doCreatureSay(cid, food[2], TALKTYPE_ORANGE_1)
	doCreatureChangeOutfit(cid, {lookType = outfits[math.random(#outfits)]})
	doSendMagicEffect(getCreaturePos(cid), 17)
	doRemoveItem(item.uid, 1)
	return true
end
 
Thank you, it works! Is it possible that when you use it and you get an outfit... you don't get the same outfit the next time someone uses it?
 
LUA:
local outfits = {
	math.random(205, 15),
	math.random(25, 15),
	math.random(15, 110),
	math.random(125, 106),
	math.random(107, 18)
} 

local FOODS =
{
  [6394] = {1, "Transformation!"}
  }
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local food = FOODS[item.itemid]
	if(not food) then
		return false
	end
 
	if((getPlayerFood(cid) + food[1]) >= 400) then
		doPlayerSendCancel(cid, "You are full.")
		return true
	end
 
	doPlayerFeed(cid, food[1] * 4)
	doCreatureSay(cid, food[2], TALKTYPE_ORANGE_1)	
	doCreatureChangeOutfit(cid, {lookType = outfits[math.random(1, #outfits)], lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0, lookTypeEx = 0, lookAddons = 3})
	doSendMagicEffect(getCreaturePosition(cid), 53)
	doSendAnimatedText(getPlayerPosition(cid),"Changed!", math.random(1,255))
	doRemoveItem(item.uid, 1)
	return true
end
 
Code:
[16/08/2013 21:55:10] [Error - Action Interface] 
[16/08/2013 21:55:10] data/actions/scripts/by phemus/cream cake.lua
[16/08/2013 21:55:10] Description: 
[16/08/2013 21:55:10] data/actions/scripts/by phemus/cream cake.lua:2: bad argument #2 to 'random' (interval is empty)
[16/08/2013 21:55:10] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/by phemus/cream cake.lua)
 
hmm.. my error is why you have 205 on start local outfits = and in line get 1, #outfits <- start in 1..
You only need changed specific addons you have or wanna changed for many looktypes?
LUA:
	doCreatureChangeOutfit(cid, {lookType = outfits[math.random(205, #outfits)], lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0, lookTypeEx = 0, lookAddons = 3})
 
Last edited:
Code:
local outfits = {205,15,25,15,110,125,106,107,18}
 
local FOODS =
{
  [6394] = {1, "Transformation!"}
  }
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local food = FOODS[item.itemid]
	if(not food) then
		return false
	end
 
	if((getPlayerFood(cid) + food[1]) >= 400) then
		doPlayerSendCancel(cid, "You are full.")
		return true
	end
 
	doPlayerFeed(cid, food[1] * 4)
	doCreatureSay(cid, food[2], TALKTYPE_ORANGE_1)
	doCreatureChangeOutfit(cid, {lookType = math.random(2, 134), lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0, lookTypeEx = 0, lookAddons = 0})
	doSendMagicEffect(getCreaturePos(cid), 17)
	doRemoveItem(item.uid, 1)
	return true
end
 
Back
Top