local npcs = {
["Hoaxette"] = SOUTH
}
function onStartup()
for name, direction in pairs(npcs) do
local npc = Npc(name)
if npc ~= nil then
npc:setDirection(direction)
end
end
end
function onStepIn(cid, item, pos)
local crePos = {x = 1000, y = 997, z = 7} --- Position of the creature whose direction you wanna change
local direction = 2 --- direction that you want it to face
doCreatureSetLookDirection(getTopCreature(crePos).uid, direction)
return TRUE
end
local config = {
npcs = {
[2] = {x = 1000, y = 997, z = 7},
},
}
}
function onStepIn(cid, item, pos)
for dir, pos in pairs(config.npcs) do
doCreatureSetLookDirection(getTopCreature(pos).uid, dir)
end
return true
end
Yes, but it's all in one table so it is not so much work to do.
@edit
Well, it turned out that the script doesn't work at all. You can set up only one npc per direction. Can anyone fix this?
local npcs = {
[2] = { {x = 2911, y = 2624, z = 7}, {x = 2924, y = 2611, z = 7} },
[3] = { {x = 2914, y = 2633, z = 7}, {x = 2933, y = 2614, z = 7} }
}
function onStartup(cid, item, pos)
for dir, posArray in pairs(npcs) do
for indx, pos in ipairs(posArray) do
doCreatureSetLookDirection(getTopCreature(pos).uid, dir)
end
end
return true
end
local npcPositions = {
{ position={x = 2911, y = 2624, z = 7}, direction=NORTH },
{ position={x = 2924, y = 2611, z = 7}, direction=SOUTH },
{ position={x = 2914, y = 2633, z = 7}, direction=EAST },
{ position={x = 2955, y = 2644, z = 7}, direction=NORTH },
{ position={x = 2933, y = 2614, z = 7}, direction=WEST }
}
function onStartup(cid, item, pos)
for indx, npcLoc in ipairs(npcPositions) do
npcUid = getTopCreature(npcLoc.position).uid
doCreatureSetLookDirection(npcUid, npcLoc.direction)
end
return true
end
[Error - GlobalEvent::configureEvent] No valid type "start" for globalevent with name npc positioningOK, SOLVED!!!
For everyone interested:
In the data\globalevents\scripts\npcpositioning.lua
local npcs = {
[2] = {x = 2911, y = 2624, z = 7}, --the number in [] is the direction to which npc should be set and {} is obviously the position of that npc
[3] = {x = 2914, y = 2633, z = 7},
}
function onStartup(cid, item, pos)
for dir, pos in pairs(npcs) do
doCreatureSetLookDirection(getTopCreature(pos).uid, dir)
end
return true
end
Now in data\globalevents\globalevents.xml
<globalevent name="npc positioning" event="script" type="start" value="npcpositioning.lua"/>
That's all .