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

Xikini's Free Scripting Service. [0.3.7 & (0.3.6/0.4)]

Status
Not open for further replies.

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,788
Solutions
581
Reaction score
5,354
Doing quick (30 min or less) scripts for [0.3.7 & (0.3.6/0.4)]
I am not here to fix your broken scripts, although I will give advice if requested.
I am here for script requests of scripts not already available on the forum.
If you require support for your scripting issues please make a thread in the support section.

For clarity's sake,
I will script actionscripts, creaturescripts, globalevents, talkactions, movements, npcs for you.
I will not script spells, weapons, raids or monster scripts.
Additionally, source editing, websites and database queries are a no go as well.

Code:
How to make shorter links to posts.
https://otland.net/threads/234306/page-14#post-2330703
 
Last edited:
This is the difference.

Using min/max it's impossible to screw up your table.
Code:
local config = {
     [1] = {min_roll = 1, max_roll = 3, item_id = 2160, item_amount = 5}, -- 3% -- accurate
     [2] = {min_roll = 4, max_roll = 30, item_id = 2160, item_amount = 3}, -- 27%
     [3] = {min_roll = 31, max_roll = 100, item_id = 2160, item_amount = 1} -- 70%
}

local config = {
     [1] = {min_roll = 31, max_roll = 100, item_id = 2160, item_amount = 1} -- 70% -- accurate
     [2] = {min_roll = 4, max_roll = 30, item_id = 2160, item_amount = 3}, -- 27%
     [3] = {min_roll = 1, max_roll = 3, item_id = 2160, item_amount = 5}, -- 3%
}

local config = {
     [1] = {min_roll = 4, max_roll = 30, item_id = 2160, item_amount = 3}, -- 27% -- accurate
     [2] = {min_roll = 1, max_roll = 3, item_id = 2160, item_amount = 5}, -- 3%
     [3] = {min_roll = 31, max_roll = 100, item_id = 2160, item_amount = 1} -- 70%
}
Using only 1 number, it will iterate through the table faster, however if scripted incorrectly, or the table is set-up incorrectly, will become inaccurate.
Code:
local config = {
     [1] = {chance = 3, item_id = 2160, item_amount = 5}, -- 3% -- accurate
     [2] = {chance = 30, item_id = 2160, item_amount = 3}, -- 27%
     [3] = {chance = 100, item_id = 2160, item_amount = 1} -- 70%
}

local config = {
     [1] = {chance = 100, item_id = 2160, item_amount = 1} -- 70% -- accurate (if you use reverse logic)
     [2] = {chance = 30, item_id = 2160, item_amount = 3}, -- 27%
     [3] = {chance = 3, item_id = 2160, item_amount = 5}, -- 3%
}

local config = {
     [1] = {chance = 30, item_id = 2160, item_amount = 3}, -- 27% -- inaccurate
     [2] = {chance = 3, item_id = 2160, item_amount = 5}, -- 3% -- this item will never be received.
     [3] = {chance = 100, item_id = 2160, item_amount = 1} -- 70%
}
You want to provide me with the rest of the script, and I will try it later :) thanks
 
You want to provide me with the rest of the script, and I will try it later :) thanks
Code:
local config = {
     [1] = {min_roll = 1, max_roll = 3, item_id = 2160, item_amount = 5}, -- 3% -- accurate
     [2] = {min_roll = 4, max_roll = 30, item_id = 2160, item_amount = 3}, -- 27%
     [3] = {min_roll = 31, max_roll = 100, item_id = 2160, item_amount = 1} -- 70%
}
--[[
local config = {
     [1] = {min_roll = 31, max_roll = 100, item_id = 2160, item_amount = 1} -- 70% -- accurate
     [2] = {min_roll = 4, max_roll = 30, item_id = 2160, item_amount = 3}, -- 27%
     [3] = {min_roll = 1, max_roll = 3, item_id = 2160, item_amount = 5}, -- 3%
}

local config = {
     [1] = {min_roll = 4, max_roll = 30, item_id = 2160, item_amount = 3}, -- 27% -- accurate
     [2] = {min_roll = 1, max_roll = 3, item_id = 2160, item_amount = 5}, -- 3%
     [3] = {min_roll = 31, max_roll = 100, item_id = 2160, item_amount = 1} -- 70%
}
]]

-- Use any table above.
function onKill(cid, target, damage, flags)
    
     if not isPlayer(cid) or not isPlayer(target) then
         return true
     end
    
     if getTileInfo(getThingPos(target)).pvp then
         return true
     end
    
     if getPlayerLevel(target) >= 200 and getPlayerLevel(target) < 1000 then
         local rand = math.random(100)
         print(rand)
         for i = 1, #config do
             if rand >= config[i].min_roll and rand <= config[i].max_roll then
                 doPlayerAddItem(cid, config[i].item_id, config[i].item_amount)
                 break
             end
         end
     end
    
     return true
end
Code:
local config = {
     [1] = {chance = 3, item_id = 2160, item_amount = 5}, -- 3% -- accurate
     [2] = {chance = 30, item_id = 2160, item_amount = 3}, -- 27%
     [3] = {chance = 100, item_id = 2160, item_amount = 1} -- 70%
}
--[[
local config = {
     [1] = {chance = 100, item_id = 2160, item_amount = 1} -- 70% -- accurate (if you use reverse logic)
     [2] = {chance = 30, item_id = 2160, item_amount = 3}, -- 27%
     [3] = {chance = 3, item_id = 2160, item_amount = 5}, -- 3%
}

local config = {
     [1] = {chance = 30, item_id = 2160, item_amount = 3}, -- 27% -- inaccurate
     [2] = {chance = 3, item_id = 2160, item_amount = 5}, -- 3% --
     [3] = {chance = 100, item_id = 2160, item_amount = 1} -- 70%
}
]]

-- use as-is for tables 1 & 3
-- change line in script for reverse logic.
function onKill(cid, target, damage, flags)
    
     if not isPlayer(cid) or not isPlayer(target) then
         return true
     end
    
     if getTileInfo(getThingPos(target)).pvp then
         return true
     end
    
     if getPlayerLevel(target) >= 200 and getPlayerLevel(target) < 1000 then
         local rand = math.random(100)
         print(rand)
         for i = 1, #config do -- normal logic
         -- for i = #config, 1, -1 do -- reverse logic
             if rand <= config[i].chance then
                 doPlayerAddItem(cid, config[i].item_id, config[i].item_amount)
                 break
             end
         end
     end
    
     return true
end
 
What the heck are you on about @Xikini and @Cornex
First of all it is as much accurate as it is with min/max, there is no freaking difference!!! NONE
Secondly how is it easier to read and write?
2 examples:
chance = 20 vs. {min=1, max=5}
chance = 24.35 vs. {min=???, max=???} (not going to even try to calculate it in my head)

[1] = {chance = 30, item_id = 2160, item_amount = 3}, -- 27% -- inaccurate [2] = {chance = 3, item_id = 2160, item_amount = 5}, -- 3% -- this item will never be received. [3] = {chance = 100, item_id = 2160, item_amount = 1} -- 70%
What the heck you doing?
chance = 30 means 30%
chance = 100 means 100%
where are you taking these calculations.
 
What the heck are you on about @Xikini and @Cornex
First of all it is as much accurate as it is with min/max, there is no freaking difference!!! NONE
Secondly how is it easier to read and write?
2 examples:
chance = 20 vs. {min=1, max=5}
chance = 24.35 vs. {min=???, max=???} (not going to even try to calculate it in my head)


What the heck you doing?
chance = 30 means 30%
chance = 100 means 100%
where are you taking these calculations.
I'm doing it the way I thought you were trying to do it.
If you do it your proposed way..
Code:
local config = {
     [1] = {chance = 20, item_id = 2160, item_amount = 5}, -- 20%
     [2] = {chance = 20, item_id = 2160, item_amount = 3}, -- 20%
     [3] = {chance = 20, item_id = 2160, item_amount = 1}  -- 20%
}

function onKill(cid, target, damage, flags)
 
     if not isPlayer(cid) or not isPlayer(target) then
         return true
     end
 
     if getTileInfo(getThingPos(target)).pvp then
         return true
     end
 
     if getPlayerLevel(target) >= 200 and getPlayerLevel(target) < 1000 then
         for i = 1, #config do
             if math.random(100) <= config[i].chance then
                 doPlayerAddItem(cid, config[i].item_id, config[i].item_amount)
                 break
             end
         end
     end
 
     return true
end
If you don't add in a 100% chance somewhere, then there is a possibility of the player getting nothing.

Also, for every 20% chance you add in, the next item in the list will actually only have a percentage of a percentage of a chance of actually being picked.

First roll, chance = 20 -- 20% chance to get
Second roll, chance = 20 -- IF the first item doesn't get chosen, this one have 20% chance.
Third roll, chance = 20 -- IF the first item AND IF the second item doesn't get chosen, this one have 20% chance.

The chance to get lower items on the list, with the same percent chance get's lower and lower to be chosen, hence the chance you've defined is inaccurate. (except for the first item in the list.)

-- Edit for more explanation.

Let's pretend we are rolling a 6 sided die.
What's the probability of rolling a six on roll one, two, three, four (etc.) rolls?
Let's examine this roll by roll.

In one roll, the probability of rolling a 6 is 1/6.

For two rolls, there is a 1/6 probability of rolling a six on the first roll.
If this occurs, we've satisfied our condition.
There is a 5/6 probability that the first roll is not a 6.
In that case, we need to see if the second roll is a 6.
The probability of the second roll being a 6 is 1/6, so our overall probability is 1/6 + (5/6)*(1/6) = 11/36.
Why did I multiply the second 1/6 by 5/6?
Because I only need to consider the 5/6 of the time that the first roll wasn't a 6.
As you can see the probability is slightly less than 2/6.

For three rolls, there is a 1/6 probability of rolling a six on the first roll.
There is a 5/6 probability that the first roll is not a 6.
In that case, we need to see if the second roll is a 6.
The probability of the second roll being a 6 is 1/6, giving us a probability of 11/36.
There is a 25/36 probability that neither of the first two rolls was a 6.
In that case, we need to see if the third roll is a 6.
The probability of the third roll being a 6 is 1/6, giving us a probability of 1/6 + (5/6)*(1/6) + (25/36)*(1/6) = 91/216.
Again, this is less than 3/6.
 
Last edited:
I get it now what you are doing. Even still its not complicated to solve the problem and lay out an chance map constructed from chances.

What I'm getting at is that, you present way more complicated configuration.
Sure the script itself will get a bit longer, but who cares about the length of function?
 
I'm doing it the way I thought you were trying to do it.
If you do it your proposed way..
Code:
local config = {
     [1] = {chance = 20, item_id = 2160, item_amount = 5}, -- 20%
     [2] = {chance = 20, item_id = 2160, item_amount = 3}, -- 20%
     [3] = {chance = 20, item_id = 2160, item_amount = 1}  -- 20%
}

function onKill(cid, target, damage, flags)

     if not isPlayer(cid) or not isPlayer(target) then
         return true
     end

     if getTileInfo(getThingPos(target)).pvp then
         return true
     end

     if getPlayerLevel(target) >= 200 and getPlayerLevel(target) < 1000 then
         for i = 1, #config do
             if math.random(100) <= config[i].chance then
                 doPlayerAddItem(cid, config[i].item_id, config[i].item_amount)
                 break
             end
         end
     end

     return true
end
If you don't add in a 100% chance somewhere, then there is a possibility of the player getting nothing.

Also, for every 20% chance you add in, the next item in the list will actually only have a percentage of a percentage of a chance of actually being picked.

First roll, chance = 20 -- 20% chance to get
Second roll, chance = 20 -- IF the first item doesn't get chosen, this one have 20% chance.
Third roll, chance = 20 -- IF the first item AND IF the second item doesn't get chosen, this one have 20% chance.

The chance to get lower items on the list, with the same percent chance get's lower and lower to be chosen, hence the chance you've defined is inaccurate. (except for the first item in the list.)

-- Edit for more explanation.

Let's pretend we are rolling a 6 sided die.
What's the probability of rolling a six on roll one, two, three, four (etc.) rolls?
Let's examine this roll by roll.

In one roll, the probability of rolling a 6 is 1/6.

For two rolls, there is a 1/6 probability of rolling a six on the first roll.
If this occurs, we've satisfied our condition.
There is a 5/6 probability that the first roll is not a 6.
In that case, we need to see if the second roll is a 6.
The probability of the second roll being a 6 is 1/6, so our overall probability is 1/6 + (5/6)*(1/6) = 11/36.
Why did I multiply the second 1/6 by 5/6?
Because I only need to consider the 5/6 of the time that the first roll wasn't a 6.
As you can see the probability is slightly less than 2/6.

For three rolls, there is a 1/6 probability of rolling a six on the first roll.
There is a 5/6 probability that the first roll is not a 6.
In that case, we need to see if the second roll is a 6.
The probability of the second roll being a 6 is 1/6, giving us a probability of 11/36.
There is a 25/36 probability that neither of the first two rolls was a 6.
In that case, we need to see if the third roll is a 6.
The probability of the third roll being a 6 is 1/6, giving us a probability of 1/6 + (5/6)*(1/6) + (25/36)*(1/6) = 91/216.
Again, this is less than 3/6.
Like for effort :rolleyes:
 
xikini bro this script dosnt work with tfs 0.4 , can you fix for 8.6
Can you be more specific with which script?
Also, what errors do you receive?
I get it now what you are doing. Even still its not complicated to solve the problem and lay out an chance map constructed from chances.

What I'm getting at is that, you present way more complicated configuration.
Sure the script itself will get a bit longer, but who cares about the length of function?
To be fair, I did ask for an example if you had time. :oops:
 
Need script TFS 0.4
if time 12:00 then script remove ID: 9485.
pagx3e.png
 
Need script TFS 0.4
if time 12:00 then script remove ID: 9485.
pagx3e.png
Code:
<globalevent name="event" time="12:00" event="script" value="event.lua"/>
Code:
local position = {x = 883, y = 223, z = 6}
local item_id = 9485

function onTime()
   doRemoveItem(getTileItemById(position, item_id).uid)
   return true
end
 
Code:
-- as I understand you always want to give an item to player, its up to chance how rare or which amount it has.
-- 100% is the the total of all the chances (you can make it easy and make make sure your chances make it up to 100, but if you know math you can up the numbers to make it more complicated)

local monsterLoot = {
    {chance = 70, itemID = 2160, amount = 1},
    {chance = 20, itemID = 2160, amount = 3},
    {chance = 10, itemID = 2160, amount = 5},
}
--[[ -- the complicated one, but still works
local monsterLoot = {
    {chance = 654, itemID = 2160, amount = 1},
    {chance = 341, itemID = 2160, amount = 3},
    {chance = 125, itemID = 2160, amount = 5},
}
]]
local totalChance = 0 -- automatic

for ID, lootT in ipairs(monsterLoot) do
    if not lootT.chance then return print("ERROR - monsterLoot.chance is missing in (script location)") end
    totalChance = totalChance + lootT.chance
end

function getIDFromMonsterLoot(monsterLoot)
local chanceMap = getChanceMap(monsterLoot)
local randomNumber = math.random(1, totalChance)
  
    for chanceT, ID in pairs(chanceMap) do
        if randomNumber >= chanceT[1] and randomNumber <= chanceT[2] then return ID end
    end
end

function getChanceMap(monsterLoot)
local chanceMap = {}
local startChance = 0
local monsterLootID
  
    for x=1, #monsterLoot do
        local nextChance = totalChance
      
        for ID, lootT in ipairs(monsterLoot) do
            if lootT.chance < nextChance and lootT.chance > startChance then
                nextChance = lootT.chance
                monsterLootID = ID
            end
        end
      
        if startChance == 0 then
            startChance = 1
        else
            nextChance = nextChance + startChance
        end
        chanceMap[{startChance, nextChance}] = monsterLootID
        startChance = nextChance
    end
    return chanceMap
end
 
could you do a lottery NPC that works with tfs 0.3.6?

NPC - Lottery Npc v1.0 - this one doesn't quite get all the features but maybe something you could go of off?

Lottery Npc -

Variables:
the item(s) being auctioned up to 3?
the ticket prices
number of tickets each player can buy
max amount of tickets sold

Rules:
lottery wont start until all tickets have sold
reward sent directly to players depot
when a lottery ends it deletes the list and starts over

Broadcast is created when:
Lottery Starts - tell prize and price per ticket - ex: "LotteryOne has 20 Tickets for 100gp each. You can win ItemA, ItemB, ItemC."
Lottery Ends - tell winner and prize - ex: "Congratulations! PlayerName has won LotteryOne; ItemA, ItemB, ItemC."

player: hi
npc: Hello PlayerName. I hope you can participate in a lottery today!
player:join
npc: ok, which lottery would you like to hear about: Lottery1, Lottery2, or Lottery3
player:Lottery#
npc: Lottery# has 5 of 20 tickets remaining. Items: ItemA, ItemB, ItemC. Would you like to join this lottery for 100gp or would you like to learn about another lottery?
player: Yes
npc: Good choice! (remove 100gp, register player for lottery) Is there anything I can do for you?
player: Lottery#
npc:Lottery# has 4 of 20 tickets remaining. Items: ItemA, ItemB, ItemC. Would you like to join this lottery for 100gp or would you like to learn about another lottery?
player:Yes
npc: You are allowed up to 3 tickets for this lottery. You already have 1. Would you like to buy another for 100gp?
player: No
npc:Ok, is there something else I could help you with?
player:No
npc: Farewell!

@Xikini bump for request
 
Last edited by a moderator:
Heyo I need a script for tfs 0.3.6

On push also explain:

If someone stands on the depot tile peoples cant move these ppls also like a push block xD
 
Status
Not open for further replies.

Similar threads

Back
Top