Postado Julho 30, 2018 6 anos data > npc > lib crie um arquivo.lua e renomei para npc-func.lua local focuses = {} function isFocused(cid, t) for i, v in pairs(t) do if(v == cid) then return true end end return false end function addFocus(cid, t) if(not isFocused(cid, t)) then table.insert(t, cid) end end function setFocus(t) for i, v in pairs(t) do if(isPlayer(v)) then doNpcSetCreatureFocus(v) return end end doNpcSetCreatureFocus(0) end function removeFocus(cid, t) for i, v in pairs(t) do if(v == cid) then table.remove(t, i) setFocus(focuses) break end end end function onCreatureDisappear(cid) if isFocused(cid, focuses) then removeFocus(cid, focuses) if isPlayer(cid) then closeShopWindow(cid) end end end e seu script usa assim dofile("data/npc/lib/npc-func.lua") local focuses = {} -- do not change local talkState = {} local focus, old_focus = 0, 0 local dice_pos = {x=32465,y=32497,z=7,stackpos=255} local player_pos = {x=32464,y=32499,z=7} local nme = "Dice" function msgcontains(txt, str) return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)')) end function onCreatureSay(cid, type, msg) local msg = string.lower(msg) local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid local function rollDice(cid,ammount) if not isCreature(cid) then return LUA_ERROR end local value = math.random(5792, 5797) local item = getThingFromPos(dice_pos) if item and item.uid and item.uid > 0 and item.itemid >= 5792 and item.itemid <= 5797 then doTransformItem(item.uid, value) end doSendMagicEffect(dice_pos, CONST_ME_CRAPS) local rolled = value - 5791 doCreatureSay(getNpcId(), getCreatureName(getNpcId()) .. ' rolled a ' .. rolled .. '.', TALKTYPE_ORANGE_1) if rolled == ammount then local backpack = doCreateItemEx(10521) doAddContainerItem(backpack,12627,3) doAddContainerItem(backpack,12626,3) doAddContainerItem(backpack,5957,1) doAddContainerItem(backpack,10310,1) doPlayerAddItemEx(cid,backpack) doSendMagicEffect(getThingPos(cid),29) doCreatureSay(cid,gm(cid,nme,1),TALKTYPE_ORANGE_1) else doCreatureSay(cid,gm(cid,nme,2),TALKTYPE_ORANGE_1) doSendMagicEffect(getThingPos(cid),CONST_ME_POFF) end addEvent(function() if not isCreature(cid) then return LUA_ERROR end doPlayerSetStorageValue(cid,722522,-1) doTeleportThing(cid,{x=165,y=59,z=7}) end,2000) end if isInArray({1,2,3,4,5,6},tonumber(msg)) and isFocused(cid, focuses) then if not isCreature(cid) then return LUA_ERROR end local storage = getPlayerStorageValue(cid, 722522) if storage == -1 then doPlayerSetStorageValue(cid,722522,1) rollDice(cid, tonumber(msg)) end end end function onThink() local player = getTopCreature(player_pos) if player and player.uid and player.uid > 0 and isPlayer(player.uid) then if not isFocused(cid, player.uid) then addFocus(player.uid, focuses) selfFocus(player.uid) selfSay(gm(cid,nme,3).." "..getCreatureName(player.uid)..".") addEvent(function() if not isCreature(player.uid) then return LUA_ERROR end if isPlayer(player.uid) then doSendMagicEffect(getThingPos(player.uid),CONST_ME_POFF) doPlayerSetStorageValue(player.uid,722522.-1) doTeleportThing(player.uid,{x=165,y=59,z=7}) end end,10000) end end for _, focus in pairs(focuses) do if not isCreature(focus) then removeFocus(focus, focuses) talk_step = 0 else local distance = getDistanceTo(focus) or 5 if distance > 4 then selfSay("Hmpf!", focus) removeFocus(focus, focuses) talk_step = 0 end end end setFocus(focuses) end
Postado Julho 30, 2018 6 anos Autor @Vodkart Fiz isso que você falou, agora está dando este erro. O erro acontece quando o player para na frente no npc para jogar. [Error - NpcScript Interface] data/npc/scripts/cassino.lua:onThink Description: data/npc/lib/npc-func.lua:3: bad argument #1 to 'pairs' (table expected, got number) stack traceback: [C]: in function 'pairs' data/npc/lib/npc-func.lua:3: in function 'isFocused' data/npc/scripts/cassino.lua:55: in function <data/npc/scripts/cassino.lua:52>
Postado Julho 30, 2018 6 anos local talkState = {} local focus, old_focus = 0, 0 local dice_pos = {x=32465,y=32497,z=7,stackpos=255} local player_pos = {x=32464,y=32499,z=7} local nme = "Dice" function msgcontains(txt, str) return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)')) end function onCreatureSay(cid, type, msg) local msg = string.lower(msg) local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid local function rollDice(cid,ammount) if not isCreature(cid) then return LUA_ERROR end local value = math.random(5792, 5797) local item = getThingFromPos(dice_pos) if item and item.uid and item.uid > 0 and item.itemid >= 5792 and item.itemid <= 5797 then doTransformItem(item.uid, value) end doSendMagicEffect(dice_pos, CONST_ME_CRAPS) local rolled = value - 5791 doCreatureSay(getNpcId(), getCreatureName(getNpcId()) .. ' rolled a ' .. rolled .. '.', TALKTYPE_ORANGE_1) if rolled == ammount then local backpack = doCreateItemEx(10521) doAddContainerItem(backpack,12627,3) doAddContainerItem(backpack,12626,3) doAddContainerItem(backpack,5957,1) doAddContainerItem(backpack,10310,1) doPlayerAddItemEx(cid,backpack) doSendMagicEffect(getThingPos(cid),29) doCreatureSay(cid,gm(cid,nme,1),TALKTYPE_ORANGE_1) else doCreatureSay(cid,gm(cid,nme,2),TALKTYPE_ORANGE_1) doSendMagicEffect(getThingPos(cid),CONST_ME_POFF) end addEvent(function(cid ) if not isCreature(cid) then return LUA_ERROR end doPlayerSetStorageValue(cid,722522,-1) doTeleportThing(cid,{x=165,y=59,z=7}) end, 2000, cid) end if isInArray({1,2,3,4,5,6}, tonumber(msg)) and focus == cid then if not isCreature(cid) then return LUA_ERROR end local storage = getPlayerStorageValue(cid, 722522) if storage == -1 then doPlayerSetStorageValue(cid,722522,1) rollDice(cid, tonumber(msg)) end end end function onThink() local m = getTopCreature(player_pos).uid if m ~= 0 and isPlayer(m) then if focus ~= m then focus = m selfSay(gm(cid,nme,3).." "..getCreatureName(m)..".") addEvent(function(cid) if not isCreature(cid) then return LUA_ERROR end if isPlayer(cid) then doSendMagicEffect(getThingPos(cid),CONST_ME_POFF) doPlayerSetStorageValue(cid,722522.-1) doTeleportThing(cid,{x=165,y=59,z=7}) end end, 10000, m) end end end
Postado Julho 30, 2018 6 anos Autor @Vodkart Agora está dando este erro, a principio o mesmo erro do começo... [Error - NpcScript Interface] data/npc/scripts/cassino.lua:onThink Description: (LuaInterface::luaGetCreatureStorage) Creature not found
Postado Julho 30, 2018 6 anos local talkState = {} local dice_pos = {x=32465,y=32497,z=7,stackpos=255} local player_pos = {x=32464,y=32499,z=7} local nme = "Dice" function msgcontains(txt, str) return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)')) end focus, old_focus = 0, 0 function onCreatureSay(cid, type, msg) local msg = string.lower(msg) local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid local function rollDice(cid,ammount) local value = math.random(5792, 5797) local item = getThingFromPos(dice_pos) if item and item.uid and item.uid > 0 and item.itemid >= 5792 and item.itemid <= 5797 then doTransformItem(item.uid, value) end doSendMagicEffect(dice_pos, CONST_ME_CRAPS) local rolled = value - 5791 doCreatureSay(getNpcId(), getCreatureName(getNpcId()) .. ' rolled a ' .. rolled .. '.', TALKTYPE_ORANGE_1) if rolled == ammount then local backpack = doCreateItemEx(10521) doAddContainerItem(backpack,12627,3) doAddContainerItem(backpack,12626,3) doAddContainerItem(backpack,5957,1) doAddContainerItem(backpack,10310,1) doPlayerAddItemEx(cid,backpack) doSendMagicEffect(getThingPos(cid),29) doCreatureSay(cid,gm(cid,nme,1),TALKTYPE_ORANGE_1) else doCreatureSay(cid,gm(cid,nme,2),TALKTYPE_ORANGE_1) doSendMagicEffect(getThingPos(cid),CONST_ME_POFF) end addEvent(function(cid) doPlayerSetStorageValue(cid,722522,-1) focus = 0 doTeleportThing(cid,{x=165,y=59,z=7}) end,2000,cid) end if isInArray({1,2,3,4,5,6},tonumber(msg)) and getPlayerStorageValue(cid,722522) < 0 and focus == cid then doPlayerSetStorageValue(cid,722522,1) rollDice(cid,tonumber(msg)) end end function onThink() local player = getTopCreature(player_pos) if player and player.uid and player.uid > 0 and isPlayer(player.uid) then if focus ~= player.uid then focus = player.uid selfSay(gm(cid,nme,3).." "..getCreatureName(player.uid)..".") addEvent(function(cid) if isPlayer(cid) then doSendMagicEffect(getThingPos(cid),CONST_ME_POFF) doPlayerSetStorageValue(cid,722522.-1) focus = 0 doTeleportThing(cid,{x=165,y=59,z=7}) end end,10000,player.uid) end end end
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.