Code Redeemer

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Code Redeemer

      I am curious if this LUA script would work with ascemu
      --[[
      - Redeemer script:

      This script allows players to redeem predetermined
      passphrases given out during events etc.

      Passphrases are stored in its own table in the
      database, as well as the rewards that are tied to the
      said passphrase.

      Once a passphrase is redeemed, it will be marked as
      redeemed in the database, as well as what player
      redeemed it and date/time it was redeemed.
      The passphrase will then be unavailable for future use.'


      - Table structure query:

      DROP TABLE IF EXISTS `redemption`;
      CREATE TABLE `redemption` (
      `passphrase` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
      `type` int(32) NOT NULL DEFAULT '0',
      `entry` int(32) NOT NULL DEFAULT '0',
      `count` int(32) NOT NULL DEFAULT '0',
      `redeemed` int(32) NOT NULL DEFAULT '0',
      `player_guid` int(32) DEFAULT NULL,
      `date` varchar(32) DEFAULT NULL,
      PRIMARY KEY (`passphrase`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


      - Available types of code redemptions:

      1: Item -- entry = item entry, count = item count
      2: Title -- entry = title id, count = 0
      3: Money -- entry = 0, count = copper amount
      ]]

      local Redeemer = {
      Entry = x
      }

      function Redeemer.LoadCache(event)
      Redeemer["Cache"] = {}

      local Query = CharDBQuery("SELECT * FROM redemption;");
      if(Query)then
      repeat
      if(Query:GetUInt32(4) ~= 1) then
      Redeemer["Cache"][Query:GetString(0)] = {
      -- passphrase
      rtype = Query:GetUInt32(1),
      entry = Query:GetUInt32(2),
      count = Query:GetUInt32(3)
      -- redeemed
      -- player_guid
      -- date
      };
      end
      until not Query:NextRow()
      end
      end

      function Redeemer.OnGossipHello(event, player, unit)
      player:GossipMenuAddItem(0, "I would like to redeem my secret code.", 0, 1, true, "Please insert your code below.")
      if(player:IsGM()) then
      player:GossipMenuAddItem(0, "Refresh passphrases.", 0, 2)
      end
      player:GossipSendMenu(1, unit)
      end

      function Redeemer.OnGossipSelect(event, player, object, sender, intid, code)
      if (intid == 1) then
      local sCode = tostring(code)
      if(Redeemer["Cache"][sCode]) then
      local rtype, entry, count = Redeemer["Cache"][sCode]["rtype"], Redeemer["Cache"][sCode]["entry"], Redeemer["Cache"][sCode]["count"]
      if(rtype == 1) then
      player:AddItem(entry, count)
      elseif(rtype == 2) then
      player:SetKnownTitle(entry)
      elseif(rtype == 3) then
      player:ModifyMoney(count)
      else
      player:SendAreaTriggerMessage("ERROR: Redemption failed, wrong redemption type. Please report to developers.")
      return;
      end

      player:SendAreaTriggerMessage("Congratulations! Your code has been successfully redeemed!.")
      CharDBExecute("UPDATE redemption SET redeemed=1, player_guid="..player:GetGUIDLow()..", date='"..os.date("%x, %X", os.time()).."' WHERE BINARY passphrase='"..sCode.."';");
      Redeemer["Cache"][sCode] = nil;
      else
      player:SendAreaTriggerMessage("You have entered an invalid code, or code has already been redeemed.")
      end
      elseif(intid == 2) then
      Redeemer.LoadCache()
      player:SendAreaTriggerMessage("Available passphrases have been refreshed.")
      end
      player:GossipComplete()
      end

      RegisterServerEvent(14, Redeemer.LoadCache)
      RegisterCreatureGossipEvent(Redeemer.Entry, 1, Redeemer.OnGossipHello)
      RegisterCreatureGossipEvent(Redeemer.Entry, 2, Redeemer.OnGossipSelect)


      I did not make this code