• 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 Need help with movement script!

matthewharrison

New Member
Joined
Nov 21, 2011
Messages
42
Reaction score
1
Hi, I have a script for removing walls, it works fine, but I wanted to change it, if possible. I'll post the script then talk about what I'm trying to do below it. Here's the script:
Code:
local wall = [B][COLOR="#FF0000"]{x=501, y=301, z=11}[/COLOR][/B][B] ---- I want to make this to x+2 somehow, instead of writing out the coordinates[/B]
local wallid = 1111
 
function onStepIn(cid, item, pos)
    local getwall = getTileItemById(wall, wallid)
    if(isPlayer(cid)) then
        if item.actionid == 15000 then
            doRemoveItem(getwall.uid, 1)
            doTransformItem(item.uid, 425)
        elseif item.actionid == 15001 then
            doCreateItem(wallid, 1, wall)
            doTransformItem(item.uid, 426)
        end
    end
    return true
end


Now what I'm trying to do is change it so that it will remove the wall, let's say, 2 tiles to the right, so X+2 from the tile position. I want to have the script made so that it can get the players position, or tile position, and add 2 to the X value of that position, then it would remove the wall two tiles away, instead of having to put the coordinates in.

Reason for this is because I have a bunch of spaces on my map where this script is going to be used, and the walls are all the same distance away from the tiles being stepped on, so instead of having to find a bunch of coordinates, I can just set the actionid on the tile and be good to go!

Any help would be greatly appreciated!!!
 
ok thanks, but how do i write it so that the script can understand the x+2 part?

Code:
local pos = getPlayerPosition(cid)
local newwall = pos.x+2, pos.y, pos.z

something similar to that?
 
instead of typing in the coordinates, i want the script to be able to get your position, or the tile's position, add 2 to the X value, and put a wall there
 
LUA:
local wall = (getPlayerPosition(cid).x+2)

Sorry, didn't work :/

Code:
[08/12/2011 00:50:56] [Error - MoveEvents Interface] 
[08/12/2011 00:50:56] data/movements/scripts/walltile.lua
[08/12/2011 00:50:56] Description: 
[08/12/2011 00:50:56] (luaGetThingPosition) Thing not found

[08/12/2011 00:50:56] [Error - MoveEvents Interface] 
[08/12/2011 00:50:56] data/movements/scripts/walltile.lua
[08/12/2011 00:50:56] Description: 
[08/12/2011 00:50:56] data/movements/scripts/doorhoptile.lua:1: attempt to index a boolean value
[08/12/2011 00:50:56] [Warning - Event::loadScript] Cannot load script (data/movements/scripts/walltile.lua)

[08/12/2011 00:50:56] Reloaded movements.

Local was in the wrong place, fixed that, but now got another error

Code:
[08/12/2011 00:53:32] [Error - MoveEvents Interface] 
[08/12/2011 00:53:32] data/movements/scripts/walltile.lua:onStepIn
[08/12/2011 00:53:32] Description: 
[08/12/2011 00:53:32] attempt to index a number value
[08/12/2011 00:53:32] stack traceback:
[08/12/2011 00:53:32] 	[C]: in function 'getTileItemById'
[08/12/2011 00:53:32] 	data/movements/scripts/walltile.lua:6: in function <data/movements/scripts/walltile.lua:4>
 
LUA:
local wallid = 1111

function onStepIn(cid, item, fromPosition, toPosition)
local wall = (toPosition.x+2)
local getwall = getTileItemById(wall, wallid)
	if(isPlayer(cid)) then
		if item.actionid == 15000 then
			doRemoveItem(getwall.uid, 1)
			doTransformItem(item.uid, 425)
		elseif item.actionid == 15001 then
			doCreateItem(wallid, 1, wall)
			doTransformItem(item.uid, 426)
		end
	end
return true
end
 
Code:
[08/12/2011 01:01:56] [Error - MoveEvents Interface] 
[08/12/2011 01:01:56] data/movements/scripts/doorhoptile.lua:onStepIn
[08/12/2011 01:01:56] Description: 
[08/12/2011 01:01:56] attempt to index a number value
[08/12/2011 01:01:56] stack traceback:
[08/12/2011 01:01:56] 	[C]: in function 'getTileItemById'
[08/12/2011 01:01:56] 	data/movements/scripts/doorhoptile.lua:5: in function <data/movements/scripts/doorhoptile.lua:3>

Sorry for all the messages, just really want to get this fixed :/
 
What I'm actually trying to do is remove the door, and replace it with another one by stepping on the tile in front of it, DONT ASK WHY, it's complicated but that's what I'm trying to accomplish, the door's id=1250, when you step on the tile I want it to remove that door and make it id=1249.

UO0001.jpgUO0002.jpg

EDIT: And it's actually x+1, I knew that all along, and changed it in your scripts
 
LUA:
local wallid = 1111
 
function onStepIn(cid, item, fromPosition, toPosition)
local wall = (toPosition.x+1)
local getwall = getTileItemById(wall, wallid)
	if(isPlayer(cid)) then
		if item.actionid == 15000 then
			doRemoveItem(getwall.uid, 1)
			doTransformItem(item.uid, 425)
		elseif item.actionid == 15001 then
			doCreateItem(wallid, 1, wall)
			doTransformItem(item.uid, 426)
		end
	end
return true
end
 
Last edited:
LUA:
local wallid = 1111
 
function onStepIn(cid, item, fromPosition, toPosition)
local wall = (toPosition.x+1)
local getwall = getTileItemById(wall, wallid)
	if(isPlayer(cid)) then
		if item.actionid == 15000 then
			doRemoveItem(getwall.uid, 1)
			doTransformItem(item.uid, 425)
		elseif item.actionid == 15001 then
			doCreateItem(wallid, 1, wall)
			doTransformItem(item.uid, 426)
		end
	end
return true
end


Still getting this error:
Code:
[08/12/2011 01:42:40] [Error - MoveEvents Interface] 
[08/12/2011 01:42:40] data/movements/scripts/doorhoptile.lua:onStepIn
[08/12/2011 01:42:40] Description: 
[08/12/2011 01:42:40] attempt to index a number value
[08/12/2011 01:42:40] stack traceback:
[08/12/2011 01:42:40] 	[C]: in function 'getTileItemById'
[08/12/2011 01:42:40] 	data/movements/scripts/doorhoptile.lua:5: in function <data/movements/scripts/doorhoptile.lua:3>


Here's the script I had originally, it worked but as you can see I had to put the coordinates in:
Code:
function onStepIn(cid, item, pos)
local wall = {x=345, y=319, z=7}
local wallid = 1250
local getwall = getTileItemById(wall, wallid)
    if(isPlayer(cid)) then
        if item.actionid == 15000 then
		doRemoveItem(getwall.uid, 1)
		doCreateItem(1249, 1, wall)
		end
	end
end
 
Nevermind, I got it!! :D:p

Here's the script if you want to see it, it's doing exactly what I want it to without any errors:

Code:
function onStepIn(cid, item, fromPosition, toPosition)
local wall = {x=fromPosition.x+1, y=fromPosition.y, z=fromPosition.z}
local getwall = getTileThingByPos(wall)
    if(isPlayer(cid)) then
        if item.actionid == 15000 then
		doRemoveItem(getwall.uid, 1)
		doCreateItem(1249, 1, wall)
		end
	end
end

Thanks for the help, much appreciated!
 
Back
Top