• 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 [Action] Dog race

iKaS

Member
Joined
May 9, 2009
Messages
217
Reaction score
16
Location
Barcelona
Hi,

Lua:
local maxSpeed = 100 
local minSpeed = 1000
local creaturePos = {
{x=1048, y=1047, z=7}, 
{x=1048, y=1049, z=7},
{x=1048, y=1051, z=7},
{x=1048, y=1053, z=7}
}

function onUse(cid, item)
	if getGlobalStorageValue(1212) < 1 then
		setGlobalStorageValue(1212,1)
		setGlobalStorageValue(1211,#creaturePos)
		setGlobalStorageValue(12344,0)
		for i,v in pairs(creaturePos) do
			local c = doSummonCreature("Dog",v)
			doPlayerSetNoMove(c, true)
			doSendAnimatedText(v,"Let's GO!", math.random(255))
			addEvent(moveCreature,math.random(maxSpeed,minSpeed),getCreaturePosition(c),item.actionid-1000)
		end
	else
		doPlayerSendCancel(cid,"Wait until the current race finish.")
	end
	return false
end

function direcPos(pos,direc)
local p = {
[1] = {x=pos.x,y=(pos.y-1),z=pos.z},
[2] = {x=(pos.x+1),y=pos.y,z=pos.z},
[3] = {x=pos.x,y=(pos.y+1),z=pos.z},
[4] = {x=(pos.x-1),y=pos.y,z=pos.z}
}
	return p[direc]
end

function moveCreature(pos,direc)
	pos.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
	local topos = direcPos(pos,direc)
	local creature = getThingFromPos(pos).uid
	if creature ~= 0 then
		doTeleportThing(creature,topos,true,true)
		addEvent(moveCreature,math.random(maxSpeed,minSpeed),topos,direc)
	end
	return true
end

Code:
[14:21:26.843] [Error - Action Interface]
[14:21:26.843] In a timer event called from:
[14:21:26.843] data/actions/scripts/race.lua:onUse
[14:21:26.843] Description:
[14:21:26.843] data/actions/scripts/race.lua:45: attempt to index local 'pos' (a
 boolean value)
[14:21:26.843] stack traceback:
[14:21:26.843]  data/actions/scripts/race.lua:45: in function <data/actions/scri
pts/race.lua:44>
 
try This:
Code:
local maxSpeed = 100
local minSpeed = 1000
local creaturePos = {
{x=1048, y=1047, z=7},
{x=1048, y=1049, z=7},
{x=1048, y=1051, z=7},
{x=1048, y=1053, z=7}
}
local pos = getPlayerPosition(cid)

function onUse(cid, item)
if getGlobalStorageValue(1212) < 1 then
setGlobalStorageValue(1212,1)
setGlobalStorageValue(1211,#creaturePos)
setGlobalStorageValue(12344,0)
for i,v in pairs(creaturePos) do
local c = doSummonCreature("Dog",v)
doPlayerSetNoMove(c, true)
doSendAnimatedText(v,"Let's GO!", math.random(255))
addEvent(moveCreature,math.random(maxSpeed,minSpeed),getCreaturePosition(c),item.actionid-1000)
end
else
doPlayerSendCancel(cid,"Wait until the current race finish.")
end
return false
end

function direcPos(pos,direc)
local p = {
[1] = {x=pos.x,y=(pos.y-1),z=pos.z},
[2] = {x=(pos.x+1),y=pos.y,z=pos.z},
[3] = {x=pos.x,y=(pos.y+1),z=pos.z},
[4] = {x=(pos.x-1),y=pos.y,z=pos.z}
}
return p[direc]
end

function moveCreature(pos,direc)
pos.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
local topos = direcPos(pos,direc)
local creature = getThingFromPos(pos).uid
if creature ~= 0 then
doTeleportThing(creature,topos,true,true)
addEvent(moveCreature,math.random(maxSpeed,minSpeed),topos,direc)
end
return true
end
 
try This:
Code:
local maxSpeed = 100
local minSpeed = 1000
local creaturePos = {
{x=1048, y=1047, z=7},
{x=1048, y=1049, z=7},
{x=1048, y=1051, z=7},
{x=1048, y=1053, z=7}
}
local pos = getPlayerPosition(cid)

function onUse(cid, item)
if getGlobalStorageValue(1212) < 1 then
setGlobalStorageValue(1212,1)
setGlobalStorageValue(1211,#creaturePos)
setGlobalStorageValue(12344,0)
for i,v in pairs(creaturePos) do
local c = doSummonCreature("Dog",v)
doPlayerSetNoMove(c, true)
doSendAnimatedText(v,"Let's GO!", math.random(255))
addEvent(moveCreature,math.random(maxSpeed,minSpeed),getCreaturePosition(c),item.actionid-1000)
end
else
doPlayerSendCancel(cid,"Wait until the current race finish.")
end
return false
end

function direcPos(pos,direc)
local p = {
[1] = {x=pos.x,y=(pos.y-1),z=pos.z},
[2] = {x=(pos.x+1),y=pos.y,z=pos.z},
[3] = {x=pos.x,y=(pos.y+1),z=pos.z},
[4] = {x=(pos.x-1),y=pos.y,z=pos.z}
}
return p[direc]
end

function moveCreature(pos,direc)
pos.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
local topos = direcPos(pos,direc)
local creature = getThingFromPos(pos).uid
if creature ~= 0 then
doTeleportThing(creature,topos,true,true)
addEvent(moveCreature,math.random(maxSpeed,minSpeed),topos,direc)
end
return true
end

error!
jpkn.png
 
Code:
local maxSpeed = 100
local minSpeed = 1000
local creaturePos = {
{x=1048, y=1047, z=7},
{x=1048, y=1049, z=7},
{x=1048, y=1051, z=7},
{x=1048, y=1053, z=7}
}
local pos = getPlayerPosition(cid)

function onUse(cid, item)
if getGlobalStorageValue(1212) < 1 then
setGlobalStorageValue(1212,1)
setGlobalStorageValue(1211,#creaturePos)
setGlobalStorageValue(12344,0)
for i,v in pairs(creaturePos) do
local c = doSummonCreature("Dog",v)
doPlayerSetNoMove(c, true)
doSendAnimatedText(v,"Let's GO!", math.random(255))
addEvent(moveCreature,math.random(maxSpeed,minSpeed),getCreaturePosition(c),item.actionid-1000)
end
else
doPlayerSendCancel(cid,"Wait until the current race finish.")
end
return false
end

function direcPos(pos,direc)
local pos = getPlayerPosition(cid)
local p = {
[1] = {x=pos.x,y=(pos.y-1),z=pos.z},
[2] = {x=(pos.x+1),y=pos.y,z=pos.z},
[3] = {x=pos.x,y=(pos.y+1),z=pos.z},
[4] = {x=(pos.x-1),y=pos.y,z=pos.z}
}
return p[direc]
end

function moveCreature(pos,direc)
local pos = getPlayerPosition(cid)
pos.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
local topos = direcPos(pos,direc)
local creature = getThingFromPos(pos).uid
if creature ~= 0 then
doTeleportThing(creature,topos,true,true)
addEvent(moveCreature,math.random(maxSpeed,minSpeed),topos,direc)
end
return true
end
 
Code:
local maxSpeed = 100
local minSpeed = 1000
local creaturePos = {
{x=1048, y=1047, z=7},
{x=1048, y=1049, z=7},
{x=1048, y=1051, z=7},
{x=1048, y=1053, z=7}
}
local pos = getPlayerPosition(cid)

function onUse(cid, item)
if getGlobalStorageValue(1212) < 1 then
setGlobalStorageValue(1212,1)
setGlobalStorageValue(1211,#creaturePos)
setGlobalStorageValue(12344,0)
for i,v in pairs(creaturePos) do
local c = doSummonCreature("Dog",v)
doPlayerSetNoMove(c, true)
doSendAnimatedText(v,"Let's GO!", math.random(255))
addEvent(moveCreature,math.random(maxSpeed,minSpeed),getCreaturePosition(c),item.actionid-1000)
end
else
doPlayerSendCancel(cid,"Wait until the current race finish.")
end
return false
end

function direcPos(pos,direc)
local pos = getPlayerPosition(cid)
local p = {
[1] = {x=pos.x,y=(pos.y-1),z=pos.z},
[2] = {x=(pos.x+1),y=pos.y,z=pos.z},
[3] = {x=pos.x,y=(pos.y+1),z=pos.z},
[4] = {x=(pos.x-1),y=pos.y,z=pos.z}
}
return p[direc]
end

function moveCreature(pos,direc)
local pos = getPlayerPosition(cid)
pos.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
local topos = direcPos(pos,direc)
local creature = getThingFromPos(pos).uid
if creature ~= 0 then
doTeleportThing(creature,topos,true,true)
addEvent(moveCreature,math.random(maxSpeed,minSpeed),topos,direc)
end
return true
end

Thank you for the help, 2 errors now, one at starting, another at executing the script.
The change you made apperently would not make the script run, since you've added 'getplayersposition' twice and we want the position from the creature not the player, to make it move foward on the race.

errors running the last script
58k4.png
 
Back
Top