Skip to content

Commit

Permalink
Add wiremod integration to card reader
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDotBat committed May 27, 2020
1 parent bc3127b commit 505c079
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lua/entities/glorifiedbanking_cardreader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ function ENT:SetMerchant(ply)
self:CPPISetOwner(ply)
end

--Transer money method, the main function of the card reader
--OnTransfer can be overriden to get data about transfers when complete
function ENT:OnTransfer(sender, merchant, amount) end

--Transfer money method, the main function of the card reader
function ENT:Transfer(sender)
local merchant = self:GetMerchant()
if not IsValid(merchant) then return end
Expand All @@ -40,7 +43,7 @@ function ENT:Transfer(sender)
local fee = math.Clamp(math.floor(amount / 100 * GlorifiedBanking.Config.CARD_PAYMENT_FEE), 0, amount)

if not GlorifiedBanking.CanPlayerAfford(sender, amount) then
GlorifiedBanking.Notify(sender, NOTIFY_ERROR, 5, i18n.GetPhrase( "gbCannotAfford"))
GlorifiedBanking.Notify(sender, NOTIFY_ERROR, 5, i18n.GetPhrase("gbCannotAfford"))
return
end

Expand All @@ -50,12 +53,15 @@ function ENT:Transfer(sender)
self:SetScreenID(4)

timer.Simple(3, function() --Wait while we contact the server
GlorifiedBanking.TransferAmount(sender, merchant, amount)

if not IsValid(self) then return end

self:SetTransactionAmount(0)
self:SetScreenID(1)

GlorifiedBanking.TransferAmount(sender, merchant, amount)
self:OnTransfer(sender, merchant, amount)

GlorifiedBanking.Notify(sender, NOTIFY_GENERIC, 5, i18n.GetPhrase("gbPaidByCard", merchant:Name(), GlorifiedBanking.FormatMoney(amount)))
GlorifiedBanking.Notify(merchant, NOTIFY_GENERIC, 5, i18n.GetPhrase("gbPaidByCardReceive", sender:Name(), GlorifiedBanking.FormatMoney(amount)))
end)
Expand Down
61 changes: 61 additions & 0 deletions lua/entities/glorifiedbanking_cardreader_controller.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

if not WireLib then return end

AddCSLuaFile()

DEFINE_BASECLASS( "base_wire_entity" )

ENT.PrintName = "Glorified Card Reader Controller"
ENT.WireDebugName = "Glorified Card Reader Controller"

if CLIENT then return end

function ENT:Initialize()
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)

self.Inputs = WireLib.CreateInputs(self, {})
self.Outputs = WireLib.CreateOutputs(self, {"Sender [ENTITY]", "Merchant [ENTITY]", "Amount"})

self.WInputs = {}
end

function ENT:LinkEnt(CardReader)
if not IsValid(CardReader) or CardReader:GetClass() != "glorifiedbanking_cardreader" then
return false, i18n.GetPhrase("gbOnlyLinkReaders")
end

CardReader.OnTransfer = function(s, sender, merchant, amount)
WireLib.TriggerOutput(self, "Sender", sender)
WireLib.TriggerOutput(self, "Merchant", merchant)
WireLib.TriggerOutput(self, "Amount", amount)
end

self:SetReader(CardReader)
WireLib.SendMarks(self, {CardReader})

return true
end
function ENT:UnlinkEnt()
if IsValid(self.CardReader) then
self.CardReader.OnTransfer = function(s, sender, merchant, amount) end
end

self.CardReader = nil

WireLib.SendMarks(self, {})

return true
end

function ENT:SetReader(CardReader)
if not IsValid(CardReader) or CardReader:GetClass() != "glorifiedbanking_cardreader" then return false end

self.CardReader = CardReader

return true
end

duplicator.RegisterEntityClass("glorifiedbanking_cardreader_controller", WireLib.MakeWireEnt, "Data")
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,10 @@ i18n.RegisterPhrases( "en", {
gbToolSnap = "Snap Amount:",
gbToolSnapHelp = "The distance between each snapping point.",
gbToolHeight = "Height Offset:",
gbToolHeightHelp = "The distance from the floor the ATM will be placed at."
gbToolHeightHelp = "The distance from the floor the ATM will be placed at.",
gbWireToolName = "Card Reader Controller",
gbWireToolDesc = "Spawn/link a card reader controller.",
gbWireToolStep1 = "Primary: Create card reader controller. Secondary: Link controller.",
gbWireToolStep2 = "Now select a card reader to link to.",
gbOnlyLinkReaders = "You can only link card readers to the controller."
} )
26 changes: 26 additions & 0 deletions lua/wire/stools/wire_gbcardreader.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

WireToolSetup.setCategory("Input, Output/Glorified Banking")
WireToolSetup.open("gbcardreader", "Card Reader Controller", "glorifiedbanking_cardreader_controller", nil, "Card Reader Controller")

if CLIENT then
language.Add("tool.wire_gbcardreader.name", i18n.GetPhrase("gbWireToolName"))
language.Add("tool.wire_gbcardreader.desc", i18n.GetPhrase("gbWireToolDesc"))
language.Add("tool.wire_gbcardreader.0", i18n.GetPhrase("gbWireToolStep1"))
language.Add("tool.wire_gbcardreader.1", i18n.GetPhrase("gbWireToolStep2"))
end

WireToolSetup.BaseLang()
WireToolSetup.SetupMax(2)

TOOL.NoLeftOnClass = true
TOOL.ClientConVar = {
model = "models/jaanus/wiretool/wiretool_siren.mdl"
}

WireToolSetup.SetupLinking(true)

function TOOL.BuildCPanel(panel)
ModelPlug_AddToCPanel(panel, "Misc_Tools", "wire_gbcardreader", nil, 1)
end

WireToolSetup.close()

0 comments on commit 505c079

Please sign in to comment.