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

Creaturescript problem

kafar1

New Member
Joined
Apr 4, 2013
Messages
78
Reaction score
1
Hi i need sript that will be move a player from temple position to random sqm next to temple posiotion.. Player can not stand at this sqm becouse this script should move him to another sqm automaticaly.


I have this script but doesnt work good.

Code:
data\creaturescripts    creaturescripts.xml add:
<event type="login" name="PlayerLogin" event="script" value="ranpos.lua"/>

data\creaturescripts\scripts  make: ranpos.lua and add:
function onLogin(cid)
local pos = getTownTemplePosition(cid)
local config = {
position = {{x=pos.x-1, y=pos.y, z=pos.z}, {x=pos.x, y=pos.y-1, z=pos.z}, {x=pos.x+1, y=pos.y-1, z=pos.z}},
number = math.random(1, 3)
}
doTeleportThing(cid, config.position[config.number])
return true
end

any ideas?
 
Try this:
Globalevents.xml:
Code:
<globalevent name="movePlayer" interval="1000" event="script" value="moveplayer.lua"/>

globalevents/scripts/moveplayer.lua:
Code:
function onLogin(cid)
local pos = getTownTemplePosition(cid)
local config = {
position = {{x=pos.x-1, y=pos.y, z=pos.z}, {x=pos.x, y=pos.y-1, z=pos.z}, {x=pos.x+1, y=pos.y-1, z=pos.z}},
number = math.random(1, 3)
}
if (isPlayer(position.uid)) then
    doTeleportThing(cid, config.position[config.number])
end
return true
end
 
Bueno esto no funciona, creo que esa no es la posición del jugador intenta una variable con la posición del jugador

Posición local = getCreaturePosition(cid) or getTopCreature(cid)
 
Last edited:
The message is because you've defined a "think" event, but you didn't connect it to a script with a correctly defined onThink() function in it.

Here's an example for setting up a think event:

in \data\creaturescripts\creaturescripts.xml:
<event type="think" name="SkullDebuff" script="SkullDebuff.lua"/>

in \data\creaturescripts\scripts\login.lua
player:registerEvent("SkullDebuff")

in \data\creaturescripts\scripts
a script called SkullDebuff.lua with function onThink(cid, interval)


If you can't figure this out yourself I suggest you find an OT scripter to help you.
 
Code:
[30/04/2014 10:40:56] zaas has logged in.

[30/04/2014 10:40:56] [Error - CreatureScript Interface]
[30/04/2014 10:40:56] data/creaturescripts/scripts/move.lua:onLogin
[30/04/2014 10:40:56] Description:
[30/04/2014 10:40:56] data/creaturescripts/scripts/move.lua:7: attempt to index global 'position' (a nil value)
[30/04/2014 10:40:56] stack traceback:
[30/04/2014 10:40:56]    data/creaturescripts/scripts/move.lua:7: in function <data/creaturescripts/scripts/move.lua:1>
[30/04/2014 10:40:56] zaas has logged out.
 
Different problem.

You'll get that message from Eazy M's example, because he made a small error. But you should have picked up the error yourself - you need to find a scripter.

Change if (isPlayer(position.uid)) then to if (isPlayer(pos.uid)) then and try again.

BTW the original script will work only if the player always starts the game at their default town temple. This isn't the default behavior when I play, except for a brand new character.

If the player is at the temple the script moves them to a random location right beside it. The original blows up if the player is located somewhere else on login. Eazy M's version fixes that: it does nothing if the player isn't at that location.

The original is weird though - where did you get it? For example it's a very bad idea to use "position" as a variable name because there is an Object called position, and it's used in a bunch of function names. A serious coder would call that table something like "targetPlayerPos" so it's easier to read.
 
Last edited:
That script checks to see if the player logs in at the position returned by getTownTemplePosition(playersCreatureId), and if they are located there it teleports them to one of three positions one tile away from that.

It runs exactly once per player session - walking onto that tile doesn't trigger it.

Are you testing it correctly?
 
Back
Top