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

Lua [SQLite] -=[TFS]=- [ACTION] 0.4 8.60 I bet 2k VIP coins and I don't win the 12 items

samuel157

/root
Joined
Mar 19, 2010
Messages
447
Solutions
3
Reaction score
49
Location
São Paulo, Brazil
GitHub
Samuel10M
Lua:
-- Cassino System by LucasHere
function onUse(cid, item, frompos, item2, topos)
  pos1 = {x=256, y=344, z=7, stackpos=1} --posição que vai cria os items
  pos2 = {x=257, y=344, z=7, stackpos=1}
  pos3 = {x=258, y=344, z=7, stackpos=1}
  local config = {
    moneyneed = 100 * 20, -- money needed to play (scarab 100)
  }
 
  local premios = {
    [2189] = 1,
    [6529] = 1,
    [2546] = 1,
    [2352] = 1,
    [2545] = 1,
    [8851] = 1,
    [7424] = 1,
    [7735] = 1,
    [8293] = 1,
    [7450] = 1,
    [8931] = 1,
    [8856] = 1
  }
  function additem(cid, premios)
    for itemId, quantity in pairs(premios) do
      doPlayerAddItem(cid, itemId, quantity)
    end
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Desculpe, você não tem 2K de Vip Coins moeda suficiente para jogar.")
  end
 
  if item.itemid == 1945 and getPlayerItemCount(cid, 11192) < config.moneyneed then
    doPlayerSendCancel(cid, "Desculpe, você não tem 2K de Vip Coin moeda suficiente para jogar!")
    return true
  end
 
  if item.itemid == 1945 then
    doTransformItem(item.uid, 1946)
    doPlayerRemoveItem(cid, 11192, config.moneyneed)
    doCreateItem(6556,1,pos1)
addEvent(doCreateItem, 1000, 6556, 1, pos2)
addEvent(doCreateItem, 2000, 6556, 1, pos3)
      addEvent(additem,2000,cid,premio,premio_cont)
                    return true
elseif item.itemid == 1945 and math.random(0, 8) == 2 then
doTransformItem(item.uid,1946)
        doPlayerRemoveMoney(cid,config.moneyneed)
    doCreateItem(6557,1,pos1)
addEvent(doCreateItem, 1000, 6557, 1, pos2)
 addEvent(doCreateItem, 2000, 6556, 1, pos3)
                          return true
     elseif item.itemid == 1945 and math.random(0, 8) == 3 then
     doTransformItem(item.uid,1946)
        doPlayerRemoveMoney(cid,config.moneyneed)
    doCreateItem(6557,1,pos1)
addEvent(doCreateItem, 1000, 6557, 1, pos2)
addEvent(doCreateItem, 2000, 6557, 1, pos3)
  addEvent(additem,2000,cid,premio,premio_cont)
                                  return true
                   elseif item.itemid == 1945 and math.random(0, 8) == 4 then
                   doTransformItem(item.uid,1946)
                        doPlayerRemoveMoney(cid,config.moneyneed)
addEvent(doCreateItem, 1000, 6556, 1, pos2)
addEvent(doCreateItem, 2000, 6556, 1, pos3)
    doCreateItem(6557,1,pos1)
    return true
                          elseif item.itemid == 1945 and math.random(0, 8) == 5 then
                   doTransformItem(item.uid,1946)
                        doPlayerRemoveMoney(cid,config.moneyneed)
addEvent(doCreateItem, 1000, 6557, 1, pos2)
addEvent(doCreateItem, 2000, 6556, 1, pos3)
    doCreateItem(6557,1,pos1)
    return true
                       elseif item.itemid == 1945 and math.random(0, 8) == 6 then
                   doTransformItem(item.uid,1946)
                        doPlayerRemoveMoney(cid,config.moneyneed)
addEvent(doCreateItem, 1000, 6556, 1, pos2)
addEvent(doCreateItem, 2000, 6557, 1, pos3)
    doCreateItem(6557,1,pos1)
        return true
                           elseif item.itemid == 1945 and math.random(0, 8) == 7 then
                   doTransformItem(item.uid,1946)
                        doPlayerRemoveMoney(cid,config.moneyneed)
addEvent(doCreateItem, 1000, 6557, 1, pos2)
addEvent(doCreateItem, 2000, 6556, 1, pos3)
    doCreateItem(6557,1,pos1)
    return true
                           elseif item.itemid == 1945 and math.random(0, 8) == 8 then
                   doTransformItem(item.uid,1946)
                        doPlayerRemoveMoney(cid,config.moneyneed)
addEvent(doCreateItem, 1000, 6556, 1, pos2)
addEvent(doCreateItem, 2000, 6557, 1, pos3)
    doCreateItem(6556,1,pos1)
    return true

end
                item0 = getThingfromPos(pos1)
                item1 = getThingfromPos(pos2)
                item2 = getThingfromPos(pos3)
                        if item.itemid == 1946 then
                doTransformItem(item.uid,1945) 
                if item0.itemid ~= 0 and item1.itemid ~= 0 and item2.itemid ~= 0 then
                        doRemoveItem(item0.uid,1)
                                        doRemoveItem(item1.uid,1)
                                doRemoveItem(item2.uid,1)
                end
        else
                doTransformItem(item.uid,1945)
        end
        return 1
end
 
Get your code formatted, once it's clear to read you'd understand how simple it actually is.
Assuming you know english you should be able to read most of the flow easilly.

You can easilly test your algorithm ideas here:

Lookup how server' lua functions work in C++ source code: luascript.cpp e.g.
C++:
int32_t LuaInterface::luaDoPlayerRemoveMoney(lua_State* L)
{
    //doPlayerRemoveMoney(cid,money)
    uint64_t money = popNumber(L);

    ScriptEnviroment* env = getEnv();
    if(Player* player = env->getPlayerByUID(popNumber(L)))
        lua_pushboolean(L, g_game.removeMoney(player, money));
    else
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }

    return 1;
}

Read a bit of how LUA stack works (to the level you have some idea how values are passed between LUA and C++).
Once you do that things would no longer be as complex as they look.

Basic explanation:

Use proper tool set:
  • Some editor VS Code / IntelliJ IDEA
  • use some extension to e.g. format code / language servers / etc.
  • version your code (git)
 
Before, I didn't know how to tinker with the latest TFS 1x. I only knew how to move well in TFS 0.4. Over time, I learned and developed, with some people helping me. Thanks to Lurscy, who taught me how to convert/change and add to spells, I was able to learn normally.
Samuel, you could practice and learn LUA.
 

Similar threads

Back
Top