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

donation dicer npc

Nerevr back

Member
Joined
Nov 7, 2014
Messages
269
Reaction score
7
im search for donation dicer npc this npc work like this
player add donation items next npc and say H or l and npc roll if he won npc back items 2x if player lost npc remove items
im use 0.4
 
well, for one, 0.4 is kinda outdated and you should consider TFS 1.1. For two, this is the type of thing to be posted in requests, not support. Support is for help with existing things, not for requesting new things
 
This is the one you want...

Code:
function onCreatureAppear(cid)
end

local focuses = {}

local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end

local function addFocus(cid)
    if(not isFocused(cid)) then
        table.insert(focuses, cid)
    end
end

local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            table.remove(focuses, i)
            break
        end
    end
end

local function NpcLookDirection(cid, direction) --1(west), 2(north), 3(east), 4(south) --
    doCreatureSetLookDirection(cid, direction)
end

local function lookAtFocus()
    for i, v in pairs(focuses) do
        if(isPlayer(v)) then
            doNpcSetCreatureFocus(v)
            return
        end
    end
    doNpcSetCreatureFocus(0)
end

function onCreatureDisappear(cid)
    if(isFocused(cid)) then
        selfSay("Hmph!")
        removeFocus(cid)
        if(isPlayer(cid)) then --Be sure he's online
            closeShopWindow(cid)
        end
    end
end

function onThink()
    for i, focus in pairs(focuses) do
        if(not isCreature(focus)) then
            removeFocus(focus)
        else
            local distance = getDistanceTo(focus) or -1
            if((distance > 4) or (distance == -1)) then
                closeShopWindow(focus)
                removeFocus(focus)
            end
        end
    end
    lookAtFocus()
end

function onPlayerCloseChannel(cid)
    if(isFocused(cid)) then
        selfSay("Hmph!")
        closeShopWindow(cid)
        removeFocus(cid)
    end
end

local GREET_MESSAGE = {"hi", "Hi", "hello", "Hello", "hey", "Hey"}
local BYE_MESSAGE = {"bye", "Bye", "goodbye", "Goodbye", "cya", "Cya"}
local NO_MESSAGE = {"no", "No", "nah", "Nah", "nope", "Nope"}
local YES_MESSAGE = {"yes", "Yes", "yeah", "Yeah", "ya", "Ya"}

-----Set this to the position of the counter players put their items on.----
local item1 = {x = 1000, y = 1000, z = 7, stackpos = 1} --first item on counter
local item2 = {x = 1000, y = 1000, z = 7, stackpos = 2} -- second
local item3 = {x = 1000, y = 1000, z = 7, stackpos = 3} --third

-----set this to where the player must be standing to play.--------------
local pos_player_spot = {x = 1000, y = 1000, z = 7}
local npc_pos = {x = 1000, y = 1000, z = 7} --pos of npc

----------if false: The NPC will ignore players who are in the wrong spot. if true: he will tell them they are standing in the wrong spot.
local talk_to_player_if_in_wrong_spot = false

--------Item's that can be played----------
local item_array = {1111, 1111, 1111, 1111, 1111, 1111}

----Storages can be anything...--------
local storage1 = 34111
local storage2 = 34112
local storage3 = 34113

function onCreatureSay(cid, type, msg)
if((isInArray(GREET_MESSAGE, msg)) and not (isFocused(cid)) and getDistanceTo(cid) <= 3) then
if getPlayerPosition(cid) == pos_player_spot then
    selfSay("I am the Dice NPC. If you win my game you will receive 2x the items. {play}", cid)
    selfSay("You must put 3 items on the counter between us.", cid)
    addFocus(cid)
else
    if talk_to_player_if_in_wrong_spot == false
return false
else
    selfSay("You must be standing in the spot next to me to play.", cid)
return false
end
end
    --------------Guess the number---------------------
elseif((isFocused(cid)) and (msg == "play") and getDistanceTo(cid) <= 3) then
    selfSay("Say h or l for high or low", cid)
elseif((isFocused(cid)) and (msg == "h") or (msg == "high") and getDistanceTo(cid) <= 3) then
        local roll = math.random(1, 6)
    if isInArray(item_array, getThingFromPos(item1)) then
        if isInArray(item_array, getThingFromPos(item2)) then
            if isInArray(item_array, getThingFromPos(item3)) then
                local player_item1 = getThingFromPos(item1)
                local player_item2 = getThingFromPos(item2)
                local player_item3 = getThingFromPos(item3)
                setPlayerStorageValue(cid, storage1, player_item1)
                setPlayerStorageValue(cid, storage2, player_item2)
                setPlayerStorageValue(cid, storage3, player_item3)
                doRemoveItem(item1)
                doRemoveItem(item2)
                doRemoveItem(item3)
                if roll >= 5 then
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage1), 2)
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
                    doSendMagicEffect(npc_pos, math.random(1, 30))
                    doSendAnimatedText(npc_pos, ""..roll, math.random(1, 30))
                    selfSay("You have WON! Here is your reward.", cid)
                    setPlayerStorageValue(cid, storage1, 0)
                    setPlayerStorageValue(cid, storage2, 0)
                    setPlayerStorageValue(cid, storage3, 0)
                    selfSay("Would you like to {play} again?", cid)
                else
                    selfSay("You have lost with a roll of "..roll..". Better luck next time.", cid)
                    setPlayerStorageValue(cid, storage1, 0)
                    setPlayerStorageValue(cid, storage2, 0)
                    setPlayerStorageValue(cid, storage3, 0)
                end
            else
                selfSay("One of your items cannot be played. You can only play donation items.", cid)
            end
        else
        selfSay("One of your items cannot be played. You can only play donation items.", cid)
        end
    else
    selfSay("One of your items cannot be played. You can only play donation items.", cid)
    end
elseif((isFocused(cid)) and (msg == "l") or (msg == "low") and getDistanceTo(cid) <= 3) then
        local roll = math.random(1, 6)
    if isInArray(item_array, getThingFromPos(item1)) then
        if isInArray(item_array, getThingFromPos(item2)) then
            if isInArray(item_array, getThingFromPos(item3)) then
                local player_item1 = getThingFromPos(item1)
                local player_item2 = getThingFromPos(item2)
                local player_item3 = getThingFromPos(item3)
                setPlayerStorageValue(cid, storage1, player_item1)
                setPlayerStorageValue(cid, storage2, player_item2)
                setPlayerStorageValue(cid, storage3, player_item3)
                doRemoveItem(item1)
                doRemoveItem(item2)
                doRemoveItem(item3)
                if roll <= 4 then
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage1), 2)
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
                    doSendMagicEffect(npc_pos, math.random(1, 30))
                    doSendAnimatedText(npc_pos, ""..roll, math.random(1, 30))
                    selfSay("You have WON! Here is your reward.", cid)
                    setPlayerStorageValue(cid, storage1, 0)
                    setPlayerStorageValue(cid, storage2, 0)
                    setPlayerStorageValue(cid, storage3, 0)
                    selfSay("Would you like to {play} again?", cid)
                else
                    selfSay("You have lost with a roll of "..roll..". Better luck next time.", cid)
                    setPlayerStorageValue(cid, storage1, 0)
                    setPlayerStorageValue(cid, storage2, 0)
                    setPlayerStorageValue(cid, storage3, 0)
                end
            else
                selfSay("One of your items cannot be played. You can only play donation items.", cid)
            end
        else
        selfSay("One of your items cannot be played. You can only play donation items.", cid)
        end
    else
    selfSay("One of your items cannot be played. You can only play donation items.", cid)
    end
   
   
       
        --bye message
    elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
        selfSay("Good-bye.", cid)
        closeShopWindow(cid)
        removeFocus(cid)
    end
end
 
This is the one you want...

Code:
function onCreatureAppear(cid)
end

local focuses = {}

local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end

local function addFocus(cid)
    if(not isFocused(cid)) then
        table.insert(focuses, cid)
    end
end

local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            table.remove(focuses, i)
            break
        end
    end
end

local function NpcLookDirection(cid, direction) --1(west), 2(north), 3(east), 4(south) --
    doCreatureSetLookDirection(cid, direction)
end

local function lookAtFocus()
    for i, v in pairs(focuses) do
        if(isPlayer(v)) then
            doNpcSetCreatureFocus(v)
            return
        end
    end
    doNpcSetCreatureFocus(0)
end

function onCreatureDisappear(cid)
    if(isFocused(cid)) then
        selfSay("Hmph!")
        removeFocus(cid)
        if(isPlayer(cid)) then --Be sure he's online
            closeShopWindow(cid)
        end
    end
end

function onThink()
    for i, focus in pairs(focuses) do
        if(not isCreature(focus)) then
            removeFocus(focus)
        else
            local distance = getDistanceTo(focus) or -1
            if((distance > 4) or (distance == -1)) then
                closeShopWindow(focus)
                removeFocus(focus)
            end
        end
    end
    lookAtFocus()
end

function onPlayerCloseChannel(cid)
    if(isFocused(cid)) then
        selfSay("Hmph!")
        closeShopWindow(cid)
        removeFocus(cid)
    end
end

local GREET_MESSAGE = {"hi", "Hi", "hello", "Hello", "hey", "Hey"}
local BYE_MESSAGE = {"bye", "Bye", "goodbye", "Goodbye", "cya", "Cya"}
local NO_MESSAGE = {"no", "No", "nah", "Nah", "nope", "Nope"}
local YES_MESSAGE = {"yes", "Yes", "yeah", "Yeah", "ya", "Ya"}

-----Set this to the position of the counter players put their items on.----
local item1 = {x = 1000, y = 1000, z = 7, stackpos = 1} --first item on counter
local item2 = {x = 1000, y = 1000, z = 7, stackpos = 2} -- second
local item3 = {x = 1000, y = 1000, z = 7, stackpos = 3} --third

-----set this to where the player must be standing to play.--------------
local pos_player_spot = {x = 1000, y = 1000, z = 7}
local npc_pos = {x = 1000, y = 1000, z = 7} --pos of npc

----------if false: The NPC will ignore players who are in the wrong spot. if true: he will tell them they are standing in the wrong spot.
local talk_to_player_if_in_wrong_spot = false

--------Item's that can be played----------
local item_array = {1111, 1111, 1111, 1111, 1111, 1111}

----Storages can be anything...--------
local storage1 = 34111
local storage2 = 34112
local storage3 = 34113

function onCreatureSay(cid, type, msg)
if((isInArray(GREET_MESSAGE, msg)) and not (isFocused(cid)) and getDistanceTo(cid) <= 3) then
if getPlayerPosition(cid) == pos_player_spot then
    selfSay("I am the Dice NPC. If you win my game you will receive 2x the items. {play}", cid)
    selfSay("You must put 3 items on the counter between us.", cid)
    addFocus(cid)
else
    if talk_to_player_if_in_wrong_spot == false
return false
else
    selfSay("You must be standing in the spot next to me to play.", cid)
return false
end
end
    --------------Guess the number---------------------
elseif((isFocused(cid)) and (msg == "play") and getDistanceTo(cid) <= 3) then
    selfSay("Say h or l for high or low", cid)
elseif((isFocused(cid)) and (msg == "h") or (msg == "high") and getDistanceTo(cid) <= 3) then
        local roll = math.random(1, 6)
    if isInArray(item_array, getThingFromPos(item1)) then
        if isInArray(item_array, getThingFromPos(item2)) then
            if isInArray(item_array, getThingFromPos(item3)) then
                local player_item1 = getThingFromPos(item1)
                local player_item2 = getThingFromPos(item2)
                local player_item3 = getThingFromPos(item3)
                setPlayerStorageValue(cid, storage1, player_item1)
                setPlayerStorageValue(cid, storage2, player_item2)
                setPlayerStorageValue(cid, storage3, player_item3)
                doRemoveItem(item1)
                doRemoveItem(item2)
                doRemoveItem(item3)
                if roll >= 5 then
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage1), 2)
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
                    doSendMagicEffect(npc_pos, math.random(1, 30))
                    doSendAnimatedText(npc_pos, ""..roll, math.random(1, 30))
                    selfSay("You have WON! Here is your reward.", cid)
                    setPlayerStorageValue(cid, storage1, 0)
                    setPlayerStorageValue(cid, storage2, 0)
                    setPlayerStorageValue(cid, storage3, 0)
                    selfSay("Would you like to {play} again?", cid)
                else
                    selfSay("You have lost with a roll of "..roll..". Better luck next time.", cid)
                    setPlayerStorageValue(cid, storage1, 0)
                    setPlayerStorageValue(cid, storage2, 0)
                    setPlayerStorageValue(cid, storage3, 0)
                end
            else
                selfSay("One of your items cannot be played. You can only play donation items.", cid)
            end
        else
        selfSay("One of your items cannot be played. You can only play donation items.", cid)
        end
    else
    selfSay("One of your items cannot be played. You can only play donation items.", cid)
    end
elseif((isFocused(cid)) and (msg == "l") or (msg == "low") and getDistanceTo(cid) <= 3) then
        local roll = math.random(1, 6)
    if isInArray(item_array, getThingFromPos(item1)) then
        if isInArray(item_array, getThingFromPos(item2)) then
            if isInArray(item_array, getThingFromPos(item3)) then
                local player_item1 = getThingFromPos(item1)
                local player_item2 = getThingFromPos(item2)
                local player_item3 = getThingFromPos(item3)
                setPlayerStorageValue(cid, storage1, player_item1)
                setPlayerStorageValue(cid, storage2, player_item2)
                setPlayerStorageValue(cid, storage3, player_item3)
                doRemoveItem(item1)
                doRemoveItem(item2)
                doRemoveItem(item3)
                if roll <= 4 then
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage1), 2)
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
                    doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
                    doSendMagicEffect(npc_pos, math.random(1, 30))
                    doSendAnimatedText(npc_pos, ""..roll, math.random(1, 30))
                    selfSay("You have WON! Here is your reward.", cid)
                    setPlayerStorageValue(cid, storage1, 0)
                    setPlayerStorageValue(cid, storage2, 0)
                    setPlayerStorageValue(cid, storage3, 0)
                    selfSay("Would you like to {play} again?", cid)
                else
                    selfSay("You have lost with a roll of "..roll..". Better luck next time.", cid)
                    setPlayerStorageValue(cid, storage1, 0)
                    setPlayerStorageValue(cid, storage2, 0)
                    setPlayerStorageValue(cid, storage3, 0)
                end
            else
                selfSay("One of your items cannot be played. You can only play donation items.", cid)
            end
        else
        selfSay("One of your items cannot be played. You can only play donation items.", cid)
        end
    else
    selfSay("One of your items cannot be played. You can only play donation items.", cid)
    end
  
  
      
        --bye message
    elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
        selfSay("Good-bye.", cid)
        closeShopWindow(cid)
        removeFocus(cid)
    end
end
Pretty cool script overall, but these two parts concern me. :P
Code:
if roll >= 5 then
.
.
.
if roll <= 4 then
Why is high 5,6 and low 1,2,3,4? :P
Shouldn't it be like this?
Code:
if roll >= 4 then
.
.
.
if roll <= 3 then
 
lol true, it all depends how you want the win rate.... 5, 6 out of 1-6 is 1/3 win ability rather then a 50% win chance. I suppose for his server donation items arn't that important.

You have to change the scripts in there, but it is what you want. I do not know 0.4+ script systems so I can only script this way. I was just giving you the outline of a script that will work....If you actually put some time in you can change the scripts to what you need. I will not do everything for you...
 
Last edited by a moderator:
nerever stop being lazy man. If you can't make a script this simple stop making an OT server now. I already showed you how it needs to be made.
 
nerever stop being lazy man. If you can't make a script this simple stop making an OT server now. I already showed you how it needs to be made.
You're out of line. He's on the request board asking for a full script, not for advice on how he can make his own. Not everyone knows how to write code, some people are mappers or just good at project management, or maybe they're only doing it for fun. You're in no place to tell him to stop just because he doesn't know how to create scripts of his own.
 
Back
Top