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

Lua Script Help - 'getThingFromPos' (a nil value)

Crunch

Member
Joined
Jun 21, 2011
Messages
353
Reaction score
19
Location
England
Hello,

I have this script, its for an archery game, however I cannot figure out why it wont work. The problem is
Lua:
if (getThingFromPos(arrowpos).itemid) == 5779 then
I have tried various different things but have to ask for some help. Could someone tell me the problem and also why mine wont work. I'm using TFS 1.3, not sure if this is the issue as this was written for a much earlier version, however I cant remember if it ever got it to actually work or not.
Many thanks!

Lua:
local allowedPositions = {{x=1429, y=1055, z=7}, {x=1431, y=1055, z=7}, {x=1433, y=1055, z=7}, {x=1435, y=1055, z=7}}

function onUse(cid, item, fromPosition, itemEx, toPosition)
        local arrowpos = {x=getCreaturePosition(cid).x, y=1051, z=7, stackpos=3}
         fromPosition = getCreaturePosition(cid)
         local inPosition = false
    for i=1, #allowedPositions, 1 do
        if allowedPositions[i].x == fromPosition.x and allowedPositions[i].y == fromPosition.y and allowedPositions[i].z == fromPosition.z then
        inPosition = true
        break
    end
end
    if not inPosition then
        doCreatureSay(cid, 'Your not at the Archery Range.', TALKTYPE_ORANGE_1)
    end   

    if inPosition then
        if (getThingFromPos(arrowpos).itemid) == 5779 then
            doRemoveItem(getThingFromPos(arrowpos).uid)
        end 

    if math.random(1, 100) <= 10 then
          doSendDistanceShoot(getThingPos(cid), {x=fromPosition.x, y=1051, z=7}, 2)
          doSendMagicEffect({x=fromPosition.x, y=1051, z=7}, 31)
          doPlayerAddItem(cid, 6527, 1)
          doCreatureSay(cid, 'You hit the target and won!!', TALKTYPE_ORANGE_1)
          doCreateItem(5779, 1, {x=fromPosition.x, y=1051, z=7})
    else
          doSendDistanceShoot(getThingPos(cid), {x=fromPosition.x, y=1051, z=7}, 2) 
          doSendMagicEffect({x=fromPosition.x, y=1051, z=7}, 2)         
          doCreatureSay(cid, 'You missed!', TALKTYPE_ORANGE_1)       
      end
   end 
   return true
end
 
getThingFromPos doesn't exist in your context, it's a legacy function that has to be included in your compat.lua to work properly.

If you are using TFS 1.3 you shouldn't go wrong with this
how should i replace in this context? have tfs 1.5 and many scripts with this function ain't working. example:
Lua:
-- by Nottinghster
function onStepIn(cid, item, pos)

    coin = {x=33098, y=32816, z=13, stackpos=1}
    newpos = {x=33093, y=32824, z=13}

    getcoin = getThingfromPos(coin)
    
    if item.actionid == 6000 and getcoin.itemid == 2159 then
        doTeleportThing(cid,newpos)
        doRemoveItem(getcoin.uid,1)
        doSendMagicEffect(coin, CONST_ME_MAGIC_RED)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)   
        else
    end
    
    if item.actionid == 5999 then
    doTeleportThing(cid, {x=33097, y=32815, z=13})
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)   
    end
    return true
end

tried

changing to
-- by Nottinghster
function onStepIn(cid, item, pos)

coin = {x=33098, y=32816, z=13, stackpos=1}
newpos = {x=33093, y=32824, z=13}

getcoin = getThingfromPos(coin)

if item.actionid == 6000 and getcoin.itemid == 2159 then
doTeleportThing(cid,newpos)
doRemoveItem(getcoin.uid,1)
doSendMagicEffect(coin, CONST_ME_MAGIC_RED)
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)
else
end

if item.actionid == 5999 then
doTeleportThing(cid, {x=33097, y=32815, z=13})
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)
end
return true
end

--getThingPosition and getThingPos. but script is still no working, have no error displayed in console
 
Back
Top