Na chwil? obecn? dzia?aj?cy kod(skr?c? to edytuj? post):
[lua]local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler
nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler
nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler
nCreatureSay(cid, type, msg) end
function onThink() npcHandler
nThink() end
local function rollDice(roll, dice_pos, npc)
local dice_ids = {5792, 5793, 5794, 5795, 5796, 5797}
local random_rollval = math.random(1,6)
local win_teleport_to = {x = 460, y = 501, z = 7}
local npc = getNpcCid()
local player_pos = {x = 458, y = 501, z = 7}
player_pos.stackpos = STACKPOS_TOP_CREATURE
local player_uid = getThingfromPos(player_pos).uid
for _, itemId in pairs(dice_ids) do
if(getTileItemById(dice_pos, itemId).uid > 0) then
doTransformItem(getTileItemById(dice_pos, itemId).uid, dice_ids[random_rollval])
doSendMagicEffect(dice_pos, CONST_ME_CRAPS)
end
end
doCreatureSay(npc, string.format("%s rolled a %d.", getCreatureName(npc), random_rollval), TALKTYPE_ORANGE_1, false, 0, dice_pos)
if (roll == 1 and random_rollval == 1) then
doTeleportThing(player_uid, win_teleport_to, true)
elseif (roll == 2 and random_rollval == 2) then
doTeleportThing(player_uid, win_teleport_to, true)
elseif (roll == 3 and random_rollval == 3) then
doTeleportThing(player_uid, win_teleport_to, true)
elseif (roll == 4 and random_rollval == 4) then
doTeleportThing(player_uid, win_teleport_to, true)
elseif (roll == 5 and random_rollval == 5) then
doTeleportThing(player_uid, win_teleport_to, true)
elseif (roll == 6 and random_rollval == 6) then
doTeleportThing(player_uid, win_teleport_to, true)
else
doTeleportThing(player_uid, getTownTemplePosition(getPlayerTown(player_uid)), true)
end
return true
end
function creatureSayCallback(cid, type, msg)
local npc = getNpcCid()
local player_pos = {x = 458, y = 501, z = 7}
player_pos.stackpos = STACKPOS_TOP_CREATURE
local player_uid = getThingfromPos(player_pos).uid
local dice_pos = {x = 456, y = 502, z = 7}
local ROLL, num1, num2, num3, num4, num5, num6 = 0, 1, 2, 3, 4, 5, 6
if (player_uid ~= 0) then
if (msg == "1" and (isPlayer(player_uid) and player_uid == cid)) then
ROLL = num1
elseif (msg == "2" and (isPlayer(player_uid) and player_uid == cid)) then
ROLL = num2
elseif (msg == "3" and (isPlayer(player_uid) and player_uid == cid)) then
ROLL = num3
elseif (msg == "4" and (isPlayer(player_uid) and player_uid == cid)) then
ROLL = num4
elseif (msg == "5" and (isPlayer(player_uid) and player_uid == cid)) then
ROLL = num5
elseif (msg == "6" and (isPlayer(player_uid) and player_uid == cid)) then
ROLL = num6
else
return false
end
addEvent(rollDice, 500, ROLL, dice_pos, npc)
else
return false
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)[/lua]