Skip to content

Instantly share code, notes, and snippets.

@jonas747 jonas747/accountloader.txt
Last active Dec 27, 2015

Embed
What would you like to do?
My autogunshop e2
@name AccountLoader
@inputs
@outputs
@persist Accounts:gtable
@trigger
if(first() || duped()){
fileLoad("accounts.txt")
runOnFile(1)
}elseif(fileClk()){
Accounts = gTable("accounts")
Accounts:clear()
Content = fileRead()
Carr = Content:explode("|")
Num = 0
foreach(K,V:string=Carr){
Info = V:explode(";")
Sid = Info[1, string]
Money = Info[2, string]
Accounts[Sid, number] = Money:toNumber()
Num++
#print(Sid + " : "+Money+"$")
}
print("======== Done =========")
print("Loaded "+Num+" Accounts")
signalSend("updatemoney", 0)
}
@name AccountSaver
@inputs
@outputs
@persist Accounts:gtable
@trigger
if(first() || duped()){
Accounts = gTable("accounts")
timer("save", 100)
}elseif(clk("save")){
timer("save", 60000)
Str = ""
First = 1
Count = 0
foreach(K,V:number=Accounts){
if(V <= 0){
continue
}
if(!First){
Str+="|"
}
First = 0
Str+= K+";"+V
Count++
}
if(Count > 0 && fileCanWrite()){
fileWrite("accounts.txt", Str)
print("Saved "+Count+" Accounts")
}else{
print("Warning, tried to save 0 accounts")
}
}
#[##########################################################
# #
# Jonas747 - Ricky Rich #
# #
############################################################
AutoGunShop made by Jonas747
V2.4 Changes:
General:
- When you spawn the chip with no screen, it will disable itself untill you wire it to a screen
- Reduced ops when clicking on the screen by around 50-100
- Reduced ops when purchasing weapons
- More code cleanup and optimising
- You can now change the store name
- The shop chips now get assigned id's, The id's are updated automaticly everytime you spawn a new shop or remove one
- Notifies you when you run out of a shipment
UI:
- Stock for each item is now shown before the item name
- Removed the weapons disensing count
- Moved the welcom text
- Added a MOTD
- The header is now the store name
Commands:
- Completely overhauled how chat commands works
- New commands:
- !ag who <player>
Shows information about <player> (Currently only money, will show more later)
- !ag help OK
Displays help on all commands
- !ag bankset <amount> <player>
Sets the money of <player>'s account to <amount>
- !ag bankmod <amount> <player>
Modifies <player>'s account by <amount>
!ag bankmod ricky 100 - Adds 100 to ricky's account
!ag bankmod ricky -100 - Removes 100 from ricky's account
- !ag bankundo
Undo's the last bank command
- !ag name <newname>
Changes the shop's name to <newname>
- !ag motd <new motd>
Changes the MOTD to <new motd>
Wiring:
Inputs:
- Screen:wirelink: goes to the screen(emitters currenly broken
- ScreenUser:entity: goes to the screen -> User
- MoneyPotMoney: goes to the moneypot -> storedamount
- R1 .... R20:entity: goes to the rangers
Optional inputs:
- OtherUsing: you can ignore this. this is only if you have 2 booths, then you want to wire this to the other booth's e2 output "IsDispensing".
if you want to have MORE than 2 booths than you have to use some add/or gates in conjunction with this input and the output "IsDispensing"
Outputs:
Required outputs for it to work correctly:
- MoneyPotDeploy: goes to the moneypot -> spawnamount!(not spawnall)
- U1 ... U20: goes to the users
Optional:
- IsDisensing: 1 when it's dispensing, 0 when not. When someone starts dispensing it will reset to 0, 4 seconds after
- Queue:table: The dispening queue in form of a table: [Name of shipment, amount]
- CurrentUser:entity: outputs the currentuser (or the last user if no one is using the shop)
- MoneyPotDeployReady: Ouputs 1 if the moneypot is ready(the moneypot can still accept money when it's not ready so this is not realy usefull)
- LoggedOn: 1 when someone is using the shop, 0 when not. You can wire this to a privacy door for example(then you have to reverse the fading door though)
Notes:
- Rangers and User needs to have the same number or it will fuck up(the shipment thats on ranger1 is also on user1 and not user2)
Commands:
type !ag help to view all the available commands
Operations per second:
Idling at around sub 40ops, When someone is moving pointer around 200ops, when buying it spikes a bit because it
have to add items to the history and send datasignals which costs a lot of ops
###########################################################################]#
@name AutoGunShop
@inputs Screen:wirelink MoneyPotMoney OtherUsing ScreenUser:entity
@inputs [R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20]:entity
@outputs Queue:table MoneyPotDeploy CurrentUser:entity MoneyPotDeployReady IsDispensing LoggedOn
@outputs U1 U2 U3 U4 U5 U6 U7 U8 U9 U10 U11 U12 U13 U14 U15 U16 U17 U18 U19 U20
@persist MX MY Use SelectedSlot SelectedPageButton ShopOpen CurrentPage History:gtable State2BuyHover MiscTable:gtable MOYD:string ShopId StoreName:string
@persist ReadyUsers:array HelpButtonHover Accounts:gtable MaxPages Emitter ScreenState KeyUseStart State2Amount Weapons:table WeaponsArr:array
@persist [SoundHover SoundSelect SoundBuy SoundError]:string Freemode State2XHover State2PlusHover State2MinusHover LogOffDist LogOffSelected
@persist DispensingCount State2SelectedWeapon:string PriceFactor CurrentSteamId:string ScreenEnt:entity PRINTOPS Version:string CommandTable:table
@persist ShipmentNotifyCD:table LastBankCmd:string LastBankPlayer:entity LastBankPlayerS:string LastBankAmount
#colors
@persist [ColorButton ColorButtonHover]:vector4
@trigger all
#this reduces ops becuase timers are the thing that will be triggered the most, reduces ops by not having to go trhough if(first() || duped()) every time a timer is triggered
#and other clk(name)'s
#Supports arguments, if a timer has a comma(,) in it's name it will also call the clk function with name:explode(",") as argument
#but make sure the clk function has an array argument declared
ClkName = clkName()
if(ClkName != ""){
Split = ClkName:explode(",")
Func = "clk"+Split[1, string]
if(Split:count() > 1){
Func(Split)
}else{
Func()
}
}elseif(first() || duped()){
PRINTOPS=0
Version = "v2.4"
function agPrint(Msg:string, Important){
ChatTitleColor = vec(122, 122, 10)
ChatBracketColor = vec(0, 100, 150)
ChatNormalColor = Important == 0 ? vec(200, 200, 100) : vec(220, 80, 80)
printColor(ChatBracketColor, "[", ChatTitleColor, "AutoGunshop#"+ShopId, ChatBracketColor, "] ", ChatNormalColor, Msg)
}
function agPrint(Msg:string){
agPrint(Msg, 0)
}
function number getPrice(Shipment:entity){
local Price = round((Shipment:shipmentCost()/Shipment:shipmentSpawnAmount())*PriceFactor)
Price = Freemode == 0 ? Price : -1
return Price
}
function addToQueue(Item:string, Times){
Queue[Item, number] = Queue[Item, number] + Times
DispensingCount += Times
}
function addToQueue(Item:string){
addToQueue(Item, 1)
}
function popup(Title:string, Msg:string, MSize, Duration){
stoptimer("removepopup")
Marr = Msg:explode("\n")
Screen:egpRoundedBox(201, vec2(256, 256), vec2(500, 500))
Screen:egpColor(201, 200, 100, 10, 210)
CurY = 256
CurY -= (Marr:count()-1)*25
foreach(K,V:string=Marr){
if(K==8){
break
}
Screen:egpText(K+202, V, vec2(256, CurY))
Screen:egpSize(K+202, MSize)
Screen:egpAlign(K+202, 1, 0)
CurY+=50
}
Screen:egpText(210, Title, vec2(256, 50))
Screen:egpAlign(210, 1, 1)
Screen:egpSize(210, 50)
if(Title:lower() == "error"){
ScreenEnt:soundPlay(1, 1, SoundError)
}
timer("removepopup", Duration*1000)
}
function popup(Title:string, Msg:string){
popup(Title, Msg, 30, 4)
}
function void activateUser(Num){
if(Num == 1){
U1 = 1
}elseif(Num == 2){
U2 = 1
}elseif(Num == 3){
U3 = 1
}elseif(Num == 4){
U4 = 1
}elseif(Num == 5){
U5 = 1
}elseif(Num == 6){
U6 = 1
}elseif(Num == 7){
U7 = 1
}elseif(Num == 8){
U8 = 1
}elseif(Num == 9){
U9 = 1
}elseif(Num == 10){
U10 = 1
}elseif(Num == 11){
U11 = 1
}elseif(Num == 12){
U12 = 1
}elseif(Num == 13){
U13 = 1
}elseif(Num == 14){
U14 = 1
}elseif(Num == 15){
U15 = 1
}elseif(Num == 16){
U16 = 1
}elseif(Num == 17){
U17 = 1
}elseif(Num == 18){
U18 = 1
}elseif(Num == 19){
U19 = 1
}elseif(Num == 20){
U20 = 1
}
ReadyUsers[Num, number] = 0
timer("resetuser,"+Num, 500)
IsDispensing = 1
stoptimer("rdispensing")
timer("rdispensing", 4000)
}
function entity entityFromNum(Num){
if(Num == 1){
return R1
}elseif(Num == 2){
return R2
}elseif(Num == 3){
return R3
}elseif(Num == 4){
return R4
}elseif(Num == 5){
return R5
}elseif(Num == 6){
return R6
}elseif(Num == 7){
return R7
}elseif(Num == 8){
return R8
}elseif(Num == 9){
return R9
}elseif(Num == 10){
return R10
}elseif(Num == 11){
return R11
}elseif(Num == 12){
return R12
}elseif(Num == 13){
return R13
}elseif(Num == 14){
return R14
}elseif(Num == 15){
return R15
}elseif(Num == 16){
return R16
}elseif(Num == 17){
return R17
}elseif(Num == 18){
return R18
}elseif(Num == 19){
return R19
}elseif(Num == 20){
return R20
}
return noentity()
}
function void buildWeaponsTable(){
OldWeapons = Weapons
Weapons = table()
WeaponsArr = array()
for(I=1, 20, 1){
E = entityFromNum(I)
if(E:isShipment() && !E:isEmptyShipment()){
OldWeapons:removeNumber(E:shipmentName())
Weapons[E:shipmentName(), number] = I
WeaponsArr:pushEntity(E)
}
}
Count = WeaponsArr:count()
MaxPages = floor(Count/8)+1
foreach(K,V:number=OldWeapons){
if(!ShipmentNotifyCD[K, number]){
agPrint("Ran out of "+K, 1)
ShipmentNotifyCD[K, number] = 1
timer("rnotship,"+K, 5000)
}
}
}
function void addItemHistory(Player:entity, Item:string){
CurList = History[Player:steamID(), string]
if(CurList == ""){
CurList = realtime()+"_*_"+Item
}else{
CurList = realtime()+"_*_"+Item+"-*-"+CurList
}
History[Player:steamID(), string] = CurList
}
function void displayHistory(Player:entity){
List = History[Player:steamID(), string]
MArr = List:explode("-*-")
for(I=1, 8, 1){
DI = I+3
if(MArr[I, string] != ""){
Split = MArr[I, string]:explode("_*_")
Time = Split[1, string]:toNumber()
Now = realtime()
Delta = Now - Time
S = floor(Delta % 60)
M = floor(floor(Delta / 60)%60)
H = floor(floor(Delta/60)/60)
Str = S+"s"
if(M>0){
Str = M+"m "+Str
}
if(H>0){
Str= H+"h "+Str
}
Item = Split[2, string]
Screen:egpSetText(DI, Str+": "+Item)
}else{
Screen:egpSetText(DI, "")
}
}
}
function void createObjects(){
Screen:egpClear()
#background
Screen:egpBox(14, vec2(256,256), vec2(512, 512))
Screen:egpColor(14, 153, 204, 255, 100)
#Header
#Welcome box extension
Screen:egpRoundedBox(28, vec2(256, 60), vec2(200, 80))
Screen:egpColor(28, 0, 77, 153, 255)
Screen:egpRoundedBox(17, vec2(256, 35), vec2(300, 60))
Screen:egpColor(17, 77, 0, 255, 255)
Screen:egpText(18, StoreName, vec2(256, 10))
Screen:egpAlign(18, 1)
Screen:egpSize(18, 50)
Screen:egpFont(18, "Coolvetica")
#Products
for(I=2, 9, 1){
Y = 125+(50*(I-2))
AI = I+70-1
Screen:egpRoundedBox(AI, vec2(125, Y), vec2(250, 45))
Screen:egpColor(AI, ColorButton)
}
for(I=8, 15, 1){
RI = I - 8
AI = I+80-7
TPos = vec2(10, 115+(50*RI))
Screen:egpText(AI, "Empty Slot", TPos)
#Screen:egpAlign(AI, 1)
}
for(I=90, 97, 1){
Y = 125+(50*(I-90))
Screen:egpRoundedBox(I, vec2(225, Y), vec2(50, 45))
Screen:egpColor(I, 200, 10, 10, 255)
AI = I+40
Screen:egpText(AI, "N/A$", vec2(225, Y))
Screen:egpColor(AI, 0, 255, 0, 255)
Screen:egpAlign(AI, 1, 1)
}
for(I=2, 9, 1){
Y = 125+(50*(I-2))
AI = I+70-1
Screen:egpRoundedBoxOutline(AI+100, vec2(125, Y), vec2(250, 45))
Screen:egpColor(AI+100, 100, 0, 200, 255)
}
#Welcome text
Screen:egpText(20, "Welcome " + CurrentUser:name(), vec2(256, 70))
Screen:egpAlign(20, 1)
Screen:egpSize(20, 25)
#money box
Screen:egpRoundedBox(19, vec2(380,120), vec2(250, 30))
Screen:egpColor(19, 0, 77, 153, 255)
#Current money
Screen:egpText(27, "Money on your account: ", vec2(260, 110))
Screen:egpText(50, "0$", vec2(440, 110))
Screen:egpColor(50, 10, 255, 100, 255)
#MOTD box
Screen:egpRoundedBox(29, vec2(380, 187), vec2(250, 90))
Screen:egpColor(29, 0, 77, 153, 255)
#MOTD
Screen:egpText(15, "Message of the day:", vec2(380, 145))
Screen:egpAlign(15, 1)
Screen:egpTextLayout(16, "Welcome to ricky's guns!", vec2(260, 165), vec2(240, 100))
#Pages/Help box
Screen:egpRoundedBox(53, vec2(380, 270), vec2(250, 60))
Screen:egpColor(53, 0, 77, 153, 255)
#Page buttons/text
Screen:egpRoundedBox(21, vec2(360, 270), vec2(50,50))
Screen:egpRoundedBox(22, vec2(460, 270), vec2(50,50))
Screen:egpColor(21, ColorButton)
Screen:egpColor(22, ColorButton)
# + -
Screen:egpText(23, "-", vec2(360, 270))
Screen:egpSize(23, 50)
Screen:egpText(24, "+", vec2(460, 275))
Screen:egpSize(24, 50)
Screen:egpAlign(23, 1, 1)
Screen:egpAlign(24, 1, 1)
#outlines
Screen:egpRoundedBoxOutline(110, vec2(360, 270), vec2(50, 50))
Screen:egpRoundedBoxOutline(111, vec2(460, 270), vec2(50, 50))
Screen:egpColor(110, 200, 100, 0, 255)
Screen:egpColor(111, 200, 100, 0, 255)
#current page
Screen:egpText(25, "1", vec2(410, 260))
Screen:egpSize(25, 40)
Screen:egpAlign(25, 1)
Screen:egpText(26, "Page", vec2(395, 240))
#Help
Screen:egpRoundedBox(112, vec2(285, 270), vec2(50, 50))
Screen:egpRoundedBoxOutline(114, vec2(285, 270), vec2(50, 50))
Screen:egpColor(114, 200, 100, 0, 255)
Screen:egpColor(112, ColorButton)
Screen:egpText(113, "?", vec2(285, 270))
Screen:egpAlign(113, 1, 1)
Screen:egpSize(113, 30)
#Open indicator
Screen:egpRoundedBox(32, vec2(450, 50), vec2(70, 50))
Screen:egpColor(32, 0, 200, 0, 255)
Screen:egpText(33, "Open!", vec2(450, 50))
Screen:egpAlign(33, 1, 1)
Screen:egpSize(33, 20)
#history
#box
Screen:egpRoundedBox(2, vec2(380,400), vec2(250, 190))
Screen:egpColor(2, 0, 77, 153, 255)
#header
Screen:egpText(3, "Your History", vec2(380, 310))
Screen:egpAlign(3, 1)
Screen:egpSize(3, 25)
#items
for(I=1, 8, 1){
DI = I+3
Y = 310+(I*20)
Screen:egpText(DI, "", vec2(260, Y))
Screen:egpSize(DI, 20)
}
#logoff
Screen:egpRoundedBox(115, vec2(60, 50), vec2(80, 50))
Screen:egpColor(115, ColorButton)
Screen:egpText(116, "Log off", vec2(60, 50))
Screen:egpAlign(116, 1, 1)
Screen:egpSize(116, 20)
Screen:egpRoundedBoxOutline(117, vec2(60, 50), vec2(80, 50))
Screen:egpColor(117, 100, 0, 200, 255)
#cursor DISABLED: Caused huge fps lag
}
function void updateInfo(){
#update welcome text
Screen:egpSetText(20, CurrentUser:name())
#update current page
Screen:egpSetText(25, ""+CurrentPage)
#Update current money
Screen:egpSetText(50, Accounts[CurrentSteamId, number]+"$")
#Open indicator
if(ShopOpen){
Screen:egpColor(32, 0, 200, 0, 255)
Screen:egpSetText(33, "Open")
}else{
Screen:egpColor(32, 200, 0, 0, 255)
Screen:egpSetText(33, "Closed")
}
}
function void updatePageItems(){
local Account = Accounts[CurrentSteamId, number]
for(I=1, 8){
local CalculatedSlot = (CurrentPage*8)-8+I
local Ship = WeaponsArr[CalculatedSlot, entity]
local EGPId = I+80
local EGPPriceId = EGPId + 49
if(Ship:isShipment()){
Screen:egpSetText(EGPId, "#"+Ship:shipmentAmount()+" - "+Ship:shipmentName())
local Price = getPrice(Ship)
Screen:egpSetText(EGPPriceId, Price+"$")
if(Price <= Account){
Screen:egpColor(EGPPriceId-40, 51, 102, 0, 255)
}else{
Screen:egpColor(EGPPriceId-40, 200, 10, 10, 255)
}
}else{
Screen:egpSetText(EGPId, "Empty Slot")
Screen:egpSetText(EGPPriceId, "0$")
Screen:egpColor(EGPPriceId-40, 200, 10, 10, 255)
}
if(I == 8){
break
}
}
}
function void removeQuantityPopup(){
for(I=60, 70, 1){
Screen:egpRemove(I)
}
Screen:egpRemove(12)
Screen:egpRemove(13)
ScreenState = 0
State2BuyHover = 0
State2PlusHover = 0
State2MinusHover = 0
State2Amount = 0
State2XHover = 0
}
function void createQuantityPopup(E:entity){
#60-70, 12, 13
Screen:egpRoundedBox(60, vec2(256, 256), vec2(250, 250))
Screen:egpRoundedBoxOutline(61, vec2(256, 256), vec2(250, 250))
Screen:egpColor(60, 0, 77, 153, 255)
#exit
Screen:egpRoundedBox(62, vec2(350, 155), vec2(30, 30))
Screen:egpColor(62, ColorButton)
Screen:egpText(63, "X", vec2(350, 155))
Screen:egpAlign(63, 1, 1)
Screen:egpSize(63, 30)
#title
Screen:egpText(64, "Quantity selection", vec2(256, 150))
Screen:egpSize(64, 20)
Screen:egpAlign(64, 1)
#+- buttons
Screen:egpRoundedBox(65, vec2(186, 300), vec2(50, 50))
Screen:egpRoundedBox(66, vec2(320, 300), vec2(50, 50))
Screen:egpColor(65, ColorButton)
Screen:egpColor(66, ColorButton)
# + -
Screen:egpText(67, "-", vec2(186, 300))
Screen:egpSize(67, 50)
Screen:egpText(68, "+", vec2(320, 300))
Screen:egpSize(68, 50)
Screen:egpAlign(67, 1, 1)
Screen:egpAlign(68, 1, 1)
Screen:egpText(69, "0", vec2(250, 300))
Screen:egpAlign(69, 1, 1)
Screen:egpSize(69, 50)
Screen:egpText(70, "Cost: 0$", vec2(150, 200))
Screen:egpSize(70, 50)
Screen:egpRoundedBox(12, vec2(256, 350), vec2(100, 50))
Screen:egpColor(12, ColorButton)
Screen:egpText(13, "Buy", vec2(256, 350))
Screen:egpAlign(13, 1, 1)
Screen:egpSize(13, 30)
Screen:egpOrder(1, 999)
}
function void updatePointerPos(){
if(ScreenState == 0){
if(MY > 100 && MY < 500 && MX < 256){
# Item selection updateting
LocY = floor((MY - 100)/50)
SelectedSlot = LocY
LocY = LocY + 2
for(I=70, 78, 1){
LI = I-69
if(LocY == LI){
Screen:egpColor(I, ColorButtonHover)
}else{
Screen:egpColor(I, ColorButton)
}
}
if($SelectedSlot != 0 ){
ScreenEnt:soundPlay(1, 1, SoundHover)
}
}elseif(MY > 245 && MY < 295){
NewPage = 0
if(MX > 335 && MX < 385){
#PageDown button
Screen:egpColor(21, ColorButtonHover)
NewPage = 1
}elseif(MX > 435 && MX < 485){
#PageUp button
Screen:egpColor(22, ColorButtonHover)
NewPage = 2
}else{
Screen:egpColor(21, ColorButton)
Screen:egpColor(22, ColorButton)
}
SelectedPageButton = NewPage
if($SelectedPageButton != 0 && NewPage > 0){
ScreenEnt:soundPlay(1, 1, SoundHover)
}
#Help button
if(MX > 260 && MX < 310){
if(!HelpButtonHover){
Screen:egpColor(112, ColorButtonHover)
ScreenEnt:soundPlay(1, 1, SoundHover)
HelpButtonHover = 1
}
}else{
HelpButtonHover = 0
Screen:egpColor(112, ColorButton)
}
}elseif(SelectedPageButton || HelpButtonHover){
Screen:egpColor(21, ColorButton)
Screen:egpColor(22, ColorButton)
SelectedPageButton = 0
HelpButtonHover = 0
Screen:egpColor(112, ColorButton)
}
#Screen:egpRoundedBox(115, vec2(60, 50), vec2(80, 50))
if(MY < 75 && MY > 25 && MX < 100 && MX > 20){
if(!LogOffSelected){
Screen:egpColor(115, ColorButtonHover)
ScreenEnt:soundPlay(1, 1, SoundHover)
LogOffSelected = 1
}
}elseif(LogOffSelected){
Screen:egpColor(115, ColorButton)
LogOffSelected = 0
}
}elseif(ScreenState == 2){
if(MY > 140 && MY < 170 && MX > 335 && MX < 365){
if(!State2XHover){
Screen:egpColor(62, ColorButtonHover)
State2XHover = 1
ScreenEnt:soundPlay(1, 1, SoundHover)
}
}elseif(State2XHover){
State2XHover = 0
Screen:egpColor(62, ColorButton)
}
if(MY > 275 && MY < 325){
if(MX > 161 && MX < 211){
if(!State2MinusHover){
State2MinusHover = 1
Screen:egpColor(65, ColorButtonHover)
ScreenEnt:soundPlay(1, 1, SoundHover)
}
}elseif(State2MinusHover){
Screen:egpColor(65, ColorButton)
State2MinusHover = 0
}
if(MX > 301 && MX < 351){
if(!State2PlusHover){
State2PlusHover = 1
Screen:egpColor(66, ColorButtonHover)
ScreenEnt:soundPlay(1, 1, SoundHover)
}
}elseif(State2PlusHover){
Screen:egpColor(66, ColorButton)
State2PlusHover = 0
}
}elseif(State2PlusHover || State2MinusHover){
Screen:egpColor(65, ColorButton)
Screen:egpColor(66, ColorButton)
State2PlusHover = 0
State2MinusHover = 0
}
if(MY > 325 && MY < 375 && MX > 206 && MX < 306){
if(!State2BuyHover){
Screen:egpColor(12, ColorButtonHover)
State2BuyHover = 1
ScreenEnt:soundPlay(1, 1, SoundHover)
}
}elseif(State2BuyHover){
State2BuyHover = 0
Screen:egpColor(12, ColorButton)
}
}
}
function void onWeaponBuy(Ent:entity){
ScreenEnt:soundPlay(1, 1, SoundBuy)
updateInfo()
timer("updateitems", 1000)
addItemHistory(CurrentUser, Ent:shipmentName())
displayHistory(CurrentUser)
}
function void onWeaponBuy(Ent:entity, Amount){
ScreenEnt:soundPlay(1, 1, SoundBuy)
updateInfo()
timer("updateitems", 1000)
for(I=1, Amount, 1){
addItemHistory(CurrentUser, Ent:shipmentName())
}
}
function void onKeyUse(){
if(!Emitter && CurrentUser:aimEntity() != ScreenEnt){
return
}
if(ScreenState==0){ # Page switching
if(SelectedPageButton > 0){
if(SelectedPageButton == 1 && CurrentPage > 1){
CurrentPage--
ScreenEnt:soundPlay(1, 1, SoundSelect)
updatePageItems()
}elseif(SelectedPageButton == 2 && CurrentPage < MaxPages){
CurrentPage++
ScreenEnt:soundPlay(1, 1, SoundSelect)
updatePageItems()
}
updateInfo()
}elseif(SelectedSlot >= 0 && MY > 100 && MY < 500 && MX < 256){ # Buying a gun
if(!ShopOpen){
popup("You can't do that!","Shop is currently closed")
}elseif(perf()){
CalculatedSlot = (CurrentPage*8)-7+SelectedSlot
Ent = WeaponsArr[CalculatedSlot, entity]
Price = 0
if(Ent:isShipment() && DispensingCount < 100 && Queue[Ent:shipmentName(), number] < Ent:shipmentAmount()){
local Price = getPrice(Ent)
Account = Accounts[CurrentSteamId, number]
if(Account >= Price || Freemode){
if(!Freemode){
Accounts[CurrentSteamId, number] = Account - Price
}
addToQueue(Ent:shipmentName())
onWeaponBuy(Ent)
}else{
popup("Error", "You can't afford that! \nAdd some money to your account \n(put money in the moneypot)\nbefore you buy something")
}
}elseif(DispensingCount > 99){
popup("Error", "100 items in dispensing queue")
}elseif(Ent:isShipment()){
popup("Error", "Out of stock")
}else{
popup("Error", "That's an empty slot...")
}
}
}elseif(HelpButtonHover){
popup("Help!", "To add money to your account make sure \n Your name stand on the right\n Then insert money into the moneypot!\nTo buy something press \"E\" on \n The item you want", 30, 10)
}elseif(LogOffSelected){
ScreenEnt:soundPlay(1, 1, SoundSelect)
"changeToIdleState"()
}
}elseif(ScreenState == 2){
if(State2XHover){
removeQuantityPopup()
}elseif(State2PlusHover){
Ent = WeaponsArr[Weapons[State2SelectedWeapon, number], entity]
local Price = getPrice(Ent)
if(State2Amount+1 <= Ent:shipmentAmount() - Queue[Ent:shipmentName(), number]){
if((State2Amount+1)*Price <= Accounts[CurrentSteamId, number]){
State2Amount++
Screen:egpSetText(69, ""+State2Amount)
ScreenEnt:soundPlay(1, 1, SoundSelect)
NewPrice = round(State2Amount*Price)
Screen:egpSetText(70, "Cost: "+NewPrice+"$")
}else{
ScreenEnt:soundPlay(1, 1, SoundError)
}
}else{
ScreenEnt:soundPlay(1, 1, SoundError)
}
}elseif(State2MinusHover){
local Ent = WeaponsArr[Weapons[State2SelectedWeapon, number], entity]
local Price = getPrice(Ent)
if(State2Amount > 1){
State2Amount--
Screen:egpSetText(69, ""+State2Amount)
ScreenEnt:soundPlay(1, 1, SoundSelect)
NewPrice = round(State2Amount*Price)
Screen:egpSetText(70, "Cost: "+NewPrice+"$")
}else{
ScreenEnt:soundPlay(1, 1, SoundError)
}
}elseif(State2BuyHover){
local Ent = WeaponsArr[Weapons[State2SelectedWeapon, number], entity]
local Price = getPrice(Ent)
local TotPrice = round(Price*State2Amount)
if(TotPrice <= Accounts[CurrentSteamId, number]){
Accounts[CurrentSteamId, number] = Accounts[CurrentSteamId, number] - TotPrice
onWeaponBuy(Ent, State2Amount)
addToQueue(Ent:shipmentName(), State2Amount)
removeQuantityPopup()
}else{
ScreenEnt:soundPlay(1, 1, SoundError)
}
}
}
}
function changeToIdleState(){
ScreenState = 3
LoggedOn = 0
#98 - 109
Screen:egpRoundedBox(98, vec2(256, 256), vec2(450, 400))
Screen:egpRoundedBoxOutline(99, vec2(256, 256), vec2(450, 400))
Screen:egpColor(98, 0, 77, 153, 255)
Screen:egpText(100, "Welcome to Ricky's autoshop "+Version, vec2(256, 70))
Screen:egpAlign(100, 1)
Screen:egpSize(100, 30)
Screen:egpText(101, "How to use this shop: ", vec2(70, 105))
Screen:egpSize(101, 25)
Screen:egpTextLayout(102, "1. Insert money into your account by dropping money (/d amount) into the moneypot after you have logged in", vec2(40, 130), vec2(440, 400))
Screen:egpTextLayout(103, "2. Press your use key (E) on an item to purchase 1 of that item. Alternatively if you need to buy more than 1 of a item, you can hold in E", vec2(40, 175), vec2(440, 400))
Screen:egpTextLayout(104, "3. Wait (If the weapon isn't there in 10 seconds /pm the shopowner)", vec2(40, 230), vec2(440, 400))
Screen:egpRoundedBox(109, vec2(256, 300), vec2(395, 35))
Screen:egpColor(109, ColorButton)
Screen:egpText(105, "> Press E(or your use key) to log in <", vec2(256, 285))
Screen:egpSize(105, 25)
Screen:egpAlign(105, 1)
Screen:egpText(106, "Changelog for "+Version, vec2(70, 325))
Screen:egpSize(106, 20)
Screen:egpTextLayout(107, "- Code cleanup, optimising here and there", vec2(40, 350), vec2(430, 400))
Screen:egpTextLayout(108, "- UI update: no overlapping on 720p resolutions, MOTD", vec2(40, 380), vec2(430, 400))
Screen:egpTextLayout(1, "- Chat commands overhaul", vec2(40, 410), vec2(430, 400))
}
function removeIdleState(){
ScreenState = 0
for(I=98, 109, 1){
Screen:egpRemove(I)
}
Screen:egpRemove(1)
LoggedOn = 1
updateInfo()
updatePageItems()
displayHistory(CurrentUser)
timer("checkcursor", 100)
timer("checkdistance", 2500)
}
function onKeyHold(){
if(SelectedSlot >= 0 && MY > 100 && MY < 500 && MX < 256){
if(!ShopOpen){
popup("You can't do that!","Shop is currently closed")
}else{
local CalculatedSlot = (CurrentPage*8)-7+SelectedSlot
local Ent = WeaponsArr[CalculatedSlot, entity]
if(Ent:isShipment()){
local Price = round((Ent:shipmentCost()/Ent:shipmentSpawnAmount())*PriceFactor)
local Account = Accounts[CurrentSteamId, number]
if(Account >= Price || Freemode){
ScreenState = 2
State2SelectedWeapon = Ent:shipmentName()
createQuantityPopup(Ent)
}else{
popup("Error", "You can't afford that! \nAdd some money to your account \n(put money in the moneypot)\nbefore you buy something")
}
}else{
popup("Error", "That's an empty slot...")
}
}
}
}
#timer functions
function clkqueue(){
timer("queue", 1000)
if(DispensingCount > 0 && !OtherUsing){
foreach(K,V:number=Queue){
if(V < 1){
continue
}
local Slot = Weapons[K, number]
if(Slot > 0){
if(ReadyUsers[Slot, number]){
activateUser(Slot)
DispensingCount -= 1
Queue[K, number] = Queue[K, number] -1
}
}else{
# We need to restock on this ASAP!
hint(V+" Items is in queue for "+K+" But there is no "+K+" in stock!", 1)
}
}
}
}
function clkrdispensing(){
IsDispensing = 0
}
function clkupdatehistory(){
timer("updatehistory", 5000)
displayHistory(CurrentUser)
}
function clkcheckcursor(){
if(ScreenState != 3){
timer("checkcursor", 100)
}else{
return
}
if(CurrentUser:aimEntity() == ScreenEnt){
AimPos = Screen:egpCursor(CurrentUser)
MX = AimPos:x()
MY = AimPos:y()
if($MX != 0 || $MY != 0){
updatePointerPos()
}
if(CurrentUser:keyUse()){
if(Use){
Now = realtime()
if(Now - KeyUseStart >= 1){
onKeyHold()
Use = 0
}
}
}else{
if(Use){
Use = 0
Now = realtime()
if((Now - KeyUseStart) < 1){
onKeyUse()
}
}
}
}else{
if(Use){
Use = 0
Now = realtime()
if((Now - KeyUseStart) < 1){
onKeyUse()
}
}
}
}
function clkcheckdistance(){
if(ScreenState != 3){
timer("checkdistance", 2500)
}else{
return
}
if(CurrentUser:pos():distance(ScreenEnt:pos()) > LogOffDist){
changeToIdleState()
}
}
function clkremovepopup(){
for(I=201, 210, 1){
Screen:egpRemove(I)
}
}
function clkmoneypotdeploy(){
if(!MoneyPotDeployReady){
MoneyPotDeployReady = 1
MoneyPotDeploy = 0
}
}
function clkrnotship(Arr:array){
Shipment = Arr[2, string]
ShipmentNotifyCD[Shipment, number] = 0
}
function clkresetuser(User:array){
Num = User[2, string]:toNumber()
if(Num == 1){
U1 = 0
}elseif(Num == 2){
U2 = 0
}elseif(Num == 3){
U3 = 0
}elseif(Num == 4){
U4 = 0
}elseif(Num == 5){
U5 = 0
}elseif(Num == 6){
U6 = 0
}elseif(Num == 7){
U7 = 0
}elseif(Num == 8){
U8 = 0
}elseif(Num == 9){
U9 = 0
}elseif(Num == 10){
U10 = 0
}elseif(Num == 11){
U11 = 0
}elseif(Num == 12){
U12 = 0
}elseif(Num == 13){
U13 = 0
}elseif(Num == 14){
U14 = 0
}elseif(Num == 15){
U15 = 0
}elseif(Num == 16){
U16 = 0
}elseif(Num == 17){
U17 = 0
}elseif(Num == 18){
U18 = 0
}elseif(Num == 19){
U19 = 0
}elseif(Num == 20){
U20 = 0
}
timer("readybuy,"+Num, 1000)
}
function clkreadybuy(N:array){
ReadyUsers[N[2, string]:toNumber(), number] = 1
}
function clkcheckmoneypot(){
timer("checkmoneypot", 1000)
if(MoneyPotDeployReady && MoneyPotMoney > 0 && ScreenState != 3){
timer("moneypotdeploy", 2000)
local Sid = CurrentSteamId
Accounts[Sid, number] = Accounts[Sid, number] + MoneyPotMoney
MoneyPotDeploy = MoneyPotMoney
MoneyPotDeployReady = 0
updateInfo()
}
}
function clkupdateitems(){
updatePageItems()
}
function clkops(){
timer("ops", 1000)
agPrint("Ops: "+ops())
}
#end timer functions
###########################################
function addCommand(Cmd:string, Handler:string, MinArgs, Info:string){
CommandTable["cmd_"+Cmd, string] = Handler
CommandTable["narg_"+Cmd, number] = MinArgs
CommandTable["info_"+Cmd, string] = Info
}
#Chat commands
function cmdHelp(Marr:array){
if(ShopId != 1){ #Only execute this on once chip so the chat dosent get spammed if you have multiple
return
}
foreach(K,V:string=CommandTable){
if(K:find("info_")){
Sub = K:sub(6)
agPrint("!ag "+Sub+V)
}
}
}
function cmdClose(Marr:array){
ShopOpen = 0
hint("Shop Closed!", 5)
updateInfo()
}
function cmdOpen(Marr:array){
ShopOpen = 1
hint("Shop Opened!", 5)
updateInfo()
}
function cmdRefresh(Marr:array){
ScreenEnt = Screen:entity()
createObjects()
updatePageItems()
changeToIdleState()
}
function cmdLogOff(Marr:array){
if(ScreenState != 3){
changeToIdleState()
agPrint("Logged off "+ CurrentUser:name(), 1)
}
}
function cmdLogOffDistance(Marr:array){
if(Marr:count() < 3){
agPrint("Current logoffdistance: "+LogOffDist)
}else{
LogOffDist = Marr[3, string]:toNumber()
agPrint("Set logoffdist to "+LogOffDist, 1)
}
}
function cmdPriceFactor(Marr:array){
if(Marr:count() < 3){
agPrint("Current pricefactor: " + PriceFactor)
}else{
PriceFactor = Marr[3, string]:toNumber()
agPrint("Set price factor to: "+PriceFactor, 1)
updatePageItems()
}
}
function cmdMotd(Marr:array){
Newmotd = ""
for(I=3, Marr:count()){
Newmotd += Marr[I, string] + (I != Marr:count() ? " " : "")
}
MOTD = Newmotd
Screen:egpSetText(16, Newmotd)
agPrint("MOTD set to: "+Newmotd)
}
function cmdSetName(Marr:array){
NewName = ""
for(I=3, Marr:count()){
NewName += Marr[I, string] + (I != Marr:count() ? " " : "")
}
StoreName = NewName
Screen:egpSetText(18, StoreName)
agPrint("Set name to "+StoreName)
}
function cmdGetFreeIds(Marr:array){
}
function cmdWho(Marr:array){
if(ShopId != 1){
return
}
Name = ""
for(I=3, Marr:count()){
Name += Marr[I, string] + (I != Marr:count() ? " " : "")
}
Ply = findPlayerByName(Name)
if(!Ply:isPlayer()){
agPrint("No player named \""+Name+"\" Found", 1)
return
}
Money = Accounts[Ply:steamID(), number]
agPrint(Ply:name()+"'s Balance: "+Money+"$", 0)
}
function cmdBankSet(Marr:array){
if(ShopId != 1){
return
}
Name = ""
for(I=4, Marr:count()){
Name += Marr[I, string] + (I != Marr:count() ? " " : "")
}
Amount = Marr[3, string]:toNumber()
Ply = findPlayerByName(Name)
if(!Ply:isPlayer()){
agPrint("No player named \""+Name+"\" Found", 1)
return
}
CurAmount = Accounts[Ply:steamID(), number]
Accounts[Ply:steamID(), number] = Amount
LastBankCmd = "set"
LastBankAmount = CurAmount
LastBankPlayer = Ply
LastBankPlayerS = Ply:steamID()
agPrint("Changed "+Ply:name()+"'s balance from "+CurAmount+"$ to "+Amount+"$ (undo with !ag bankundo)")
}
function cmdBankMod(Marr:array){
if(ShopId != 1){
return
}
Name = ""
for(I=4, Marr:count()){
Name += Marr[I, string] + (I != Marr:count() ? " " : "")
}
Amount = Marr[3, string]:toNumber()
Ply = findPlayerByName(Name)
if(!Ply:isPlayer()){
agPrint("No player named \""+Name+"\" Found", 1)
return
}
CurAmount = Accounts[Ply:steamID(), number]
Accounts[Ply:steamID(), number] = CurAmount + Amount
LastBankCmd = "mod"
LastBankAmount = Amount
LastBankPlayer = Ply
LastBankPlayerS = Ply:steamID()
agPrint("Modified "+Ply:name()+"'s bank account by "+Amount+"$, new balance: "+Accounts[Ply:steamID(), number]+"$ (undo with !ag bankundo)")
}
function cmdBankUndo(Marr:array){
if(LastBankCmd == "set"){
CurAmount = Accounts[LastBankPlayerS, number]
Accounts[LastBankPlayerS, number] = LastBankAmount
LastBankCmd = ""
agPrint("Changed "+Ply:name()+"'s balance from "+CurAmount+"$ to "+LastBankAmount+"$")
}elseif(LastBankCmd == "mod"){
CurAmount = Accounts[LastBankPlayerS, number]
Accounts[LastBankPlayerS, number] = CurAmount - LastBankAmount
LastBankCmd = ""
agPrint("Changed "+Ply:name()+"'s balance from "+CurAmount+"$ to "+(CurAmount - LastBankAmount)+"$")
}else{
agPrint("No previous bank commands entered", 1)
}
}
addCommand("help", "cmdHelp", 0, ": Displays this help text")
addCommand("close", "cmdClose", 0, ": Closes the shop")
addCommand("open", "cmdOpen", 0, ": Opens the shop")
addCommand("refresh", "cmdRefresh", 0, ": Refreshes the screen")
addCommand("logoff", "cmdLogOff", 0, ": Logs of the gunshop")
addCommand("logoffdist", "cmdLogOffDistance", 0, ": Displays the current log off distance")
addCommand("setlogoffdist", "cmdLogOffDistance", 1, " <distance>: Sets the log off distance to <distance>")
addCommand("pricefactor", "cmdPriceFactor", 0, ": Displays the current pricefactor")
addCommand("setpricefactor", "cmdPriceFactor", 1, " <pricefactor>: Sets the pricefactor to <pricefactor>")
addCommand("setmotd", "cmdMotd", 1, " <motd>: Sets the MOTD(message of the day) to <motd>")
addCommand("setname", "cmdSetName", 1, " <name>: Sets the shop name to <name>")
addCommand("who", "cmdWho", 1, " <player>: Displays information about <player>")
addCommand("bankset", "cmdBankSet", 2, " <amount> <player>: Sets <player>'s bank account to <amount>")
addCommand("bankmod", "cmdBankMod", 2, " <amount> <player>: Modifies <player>'s bank account by <amount>")
addCommand("bankundo", "cmdBankUndo", 0, ": Undos the last bank command(bankset or bankmod)")
#if(1){
if(->Screen){
for(I=1, 20, 1){
ReadyUsers[I, number] = 1
}
ColorButton = vec4(100, 150, 50, 255)
ColorButtonHover = vec4(255, 77, 0, 255)
SoundHover = "garrysmod/ui_hover.wav"
SoundSelect = "garrysmod/ui_click.wav"
SoundBuy = "buttons/weapon_confirm.wav"
SoundError = "buttons/weapon_cant_buy.wav"
ShopOpen = 1
LogOffDist = 100
PriceFactor = 1.2
MoneyPotDeployReady = 1
Accounts = gTable("accounts")
History = gTable("history")
CurrentPage = 1
MiscTable = gTable("misc")
ScreenEnt = Screen:entity()
StoreName = "Ricky's Guns"
createObjects()
buildWeaponsTable()
updatePageItems()
changeToIdleState()
dsJoinGroup("jonas747")
dsSetScope(0)
runOnChat(1)
runOnLast(1)
runOnSignal("updatemoney", 0, 1)
runOnSignal("updateids", 0, 1)
timer("checkcursor", 100)
timer("checkmoneypot", 100)
timer("queue", 100)
timer("updatehistory", 5000)
timer("updateitems", 100)
if(PRINTOPS){
timer("ops", 100)
}
ShopId = MiscTable["num_shops", number] + 1
MiscTable["num_shops", number] = ShopId
MiscTable["shop_"+ShopId, entity] = entity()
setName("Autogunshop #"+ShopId+" "+Version)
agPrint("Successfully started!")
}else{
agPrint("Screen is not wired, restarting E2 chip when you wire the screen.")
}
}elseif(inputClk()){
if(~Screen && ->Screen){
reset()
}elseif(~ScreenUser && ScreenUser:isPlayer() && ScreenUser:aimEntity() == ScreenEnt){
if(ScreenState != 3){
if(ScreenUser == CurrentUser){
Use = 1
KeyUseStart = realtime()
}
}else{
CurrentUser = ScreenUser
CurrentSteamId = CurrentUser:steamID()
ScreenEnt:soundPlay(1, 1, SoundSelect)
removeIdleState()
}
}elseif(!~ScreenUser){
buildWeaponsTable()
updatePageItems()
}
}elseif(chatClk(owner())){
Msg = lastSaid()
Marr = Msg:explode(" ")
if(Marr[1, string]:lower() == "!ag"){
hideChat(1)
Cmd = Marr[2, string]:lower()
Handler = CommandTable["cmd_"+Cmd, string]
if(Handler){
ReqArgs = 2+CommandTable["narg_"+Cmd, number]
if(Marr:count() >= ReqArgs){
Handler(Marr)
}else{
agPrint("Not enough arguments to execute command "+Cmd, 1)
}
}else{
agPrint("Unknown command "+Cmd, 1)
}
}
}elseif(signalClk("updatemoney")){
updateInfo()
updatePageItems()
}elseif(signalClk("updateids")){
NumShops = MiscTable["num_shops", number]
ShopId = NumShops+1
MiscTable["num_shops", number] = ShopId
MiscTable["shop_"+ShopId, entity] = entity()
setName("Autogunshop #"+ShopId+" "+Version)
agPrint("ShopId's updated", 1)
}elseif(last()){
if(ShopId == MiscTable["num_shops", number]){
MiscTable["num_shops", number] = ShopId - 1
}else{
MiscTable["num_shops", number] = 0
signalSend("updateids", 0)
}
}
@Rafcin

This comment has been minimized.

Copy link

Rafcin commented Dec 27, 2015

What e2 Libraries do these use? I might work on this add some holos etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.