Skip to content

Instantly share code, notes, and snippets.

@Divran
Last active July 16, 2018 16:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Divran/8de3b7a298ccab8fa5bba33a498d1a78 to your computer and use it in GitHub Desktop.
Save Divran/8de3b7a298ccab8fa5bba33a498d1a78 to your computer and use it in GitHub Desktop.
byb gunshop v2
@name gunshop v2
@inputs [EGP WireUser]:wirelink
@inputs [BaseProp EGPUser]:entity
@inputs SearchShipments MoneyPotStoredAmount
@outputs MoneyPotOutputAmount CurrentlyLoggedIn:entity AUserIsLoggedIn
@persist CurrentMoneyPotStoredAmount
@persist [Shipments]:table [UserAccounts BannedPlayers]:string
@persist OriginalUserPos:vector Cursor:vector2
@persist AntiSpamCD ExtraSearchRadius TotalEarnings Scroll
@persist ChatPrefix:string
@persist OldX X ItemsPerPage AutoLogOutDistance ErrorDisplayed
@persist VERSION:string MoneyCachedUser:entity MoneyCache
@persist [MoneyFile BansFile]:string AllowBuyEntireShipment
#EGP Button IDs
@persist NextPageButton PrevPageButton LogInButton LogOutButton UserMoneyLabel
if (first()|duped()|dupefinished()|~EGP) {
#Source: https://gist.github.com/Divran/8de3b7a298ccab8fa5bba33a498d1a78
#[
HOW TO USE
1. BUILD:
Build some sort of contraption which has a
slope with super ice for guns to slide to the customer.
You know, the usual. Also make a space for the
money pot, of course.
2. SPAWN:
Spawn an EGP screen, placed anywhere.
Spawn a wire user, placed anywhere. Make sure the user is nocollided to everything.
3. WIRING INPUTS:
- Wire "EGP" to the EGP screen.
- Wire "BaseProp" to the "floor" of your gunshop
(generally the large prop which all of your
shipments are sitting on top of. See
"ExtraSearchRadius" below if you don't
have a big prop like this)
- Wire "EGPUser" to the EGP screen's user output
- Wire "WireUser" to the "Create wirelink" output of the wire user.
- Optionally wire "SearchShipments" to whatever you want (For example a button).
This input causes the E2 to find nearby shipments.
You can also use chat commands for this.
- Wire "MoneyPotStoredAmount" to the "Stored amount" output of the money pot.
4. WIRING OUTPUTS:
- Wire "SpawnAmount" of the money pot to the "MoneyPotOutputAmount" output of this E2.
5. Done.
The E2 will now automatically find nearby shipments
and it will teleport the wire user to the shipment that the user wants to buy.
It will notify you if a shipment is out of stock, and it will tell you
how much money you have earned so far.
It will remember how much money each user has by saving it to a file
on your computer.
It will remember banned players by saving it to a file on your computer.
6. Configure some options down below.
7. Chat commands
The chat prefix can be changed (default is dot ".")
.ban <name>
Bans the person from using the gunshop (saved until e2 is respawned)
.unban <name>
.returnchange
The same as pressing the return change button on the screen
.outputmoney
Output all the money (same as pressing Use on the money pot)
.searchshipments
Scan for nearby shipments (same as triggering the SearchShipments input)
.givemoney [amount] [user]
Add this much money to the user's account
]#
# OPTIONS
######################################
ChatPrefix = "."
#[ Allow the user to buy the entire shipment at once
The price is calculated by calling the pricePerUnit
function once, and multiplying that by the remaining
number of items in the shipment
then, the shipment is teleported straight up, high
enough to land on the ramp and slide down.
If you use this feature, make sure to make room for this
NOTE: A purchased shipment will be ignored & not added
back onto the screen until 60 seconds has passed after purchase ]#
AllowBuyEntireShipment = 1
#[ Search radius is BaseProp:boxSize():length()*2+ExtraSearchRadius
By default, this number is 0 and is unecessary, but its usefulness
depends on how your shop is built ]#
ExtraSearchRadius = 0
#When the logged in user walks away from the egp screen, log them out
AutoLogOutDistance = 200
#Cost of a single gun/etc from a shipment
function number entity:pricePerUnit() {
#default: add 50% and ceil at nearest 100
return ceil(This:shipmentPricePerUnit()*1.50,-2)
#you can change this function to change the price
#for example if (Name == "name of gun") {return 1337}
#or whatever you want
}
#Function called every time a user presses the screen
#Checks for bans and outputs a reason
#If it returns an empty string, the user is allowed
#You can add more checks here
function string entity:isPlayerBanned() {
local SteamID = This:steamID64()
#I would've used a function call here to "getPlayerBan" below, but
#E2 doesn't allow calling functions that aren't defined above the calling function
#oh well
if (BannedPlayers:find(This:steamID64()) != 0) {
return "You have been banned from this gunshop."
}
if (This:isAuthorisedPersonnel()) {
return "You are a cop."
}
if (CurrentlyLoggedIn:isValid() & This != CurrentlyLoggedIn) {
return "You are currently not logged in.\nWait for the current user to log out first."
}
return ""
}
######################################
# END OPTIONS
VERSION = "2.1"
setName("gunshop v"+VERSION)
Shipments = table()
BannedPlayers = ""
UserAccounts = ""
Scroll = 0
OldX = 0
ItemsPerPage = 18
TotalEarnings = 0
CurrentMoneyPotStoredAmount = 0
MoneyFile = "divrans_gunshop/money.txt"
BansFile = "divrans_gunshop/bans.txt"
OriginalUserPos = WireUser:entity():pos()
runOnFile(1)
runOnChat(1)
fileLoad( MoneyFile )
EGP:egpClear()
timer("searchShipments",1000)
timer("updateScreen",100)
function print_(Str:string,IsError) {
local C = vec(255)
if (IsError) {C = vec(200,75,75)}
printColor(vec(75,200,75),"[gunshop] ",C,Str)
}
function print_(Str:string) {print_(Str,0)}
function displayError(Error:string,Duration) {
EGP:entity():soundPlay(1,0.5,"buttons/button11.wav")
if (!ErrorDisplayed) {
OldX+=2
}
local Idx1 = OldX-1
local Idx2 = OldX
EGP:egpRoundedBox(Idx1,vec2(256,256),vec2(500,64))
EGP:egpSize(Idx1,6)
EGP:egpColor(Idx1,vec(200,75,75))
EGP:egpTextLayout(Idx2,Error,vec2(16,256-24),vec2(486,48))
EGP:egpSize(Idx2,24)
EGP:egpColor(Idx2,vec(255))
EGP:egpAlign(Idx2,1,1)
EGP:egpParent(Idx1)
timer("removeErrorPopup",Duration)
ErrorDisplayed = 1
}
function displayError(Error:string) {
displayError(Error,4000)
}
function hideError() {
ErrorDisplayed = 0
EGP:egpRemove(OldX-1)
EGP:egpRemove(OldX)
stoptimer("removeErrorPopup")
}
function saveUserMoney() {
fileWrite( MoneyFile, UserAccounts )
}
function number getUserMoney(User:entity) {
if (User:isValid()) {
if (MoneyCachedUser == User) {
return MoneyCache
}
local SteamID = User:steamID64()
local Matches = UserAccounts:match(SteamID+":([0-9]+)\n")
return Matches[1,string]:toNumber()
}
return 0
}
function setUserMoney(User:entity,Money) {
if (User:isValid()) {
local SteamID = User:steamID64()
if (UserAccounts:find(SteamID) > 0) {
UserAccounts = UserAccounts:replaceRE(SteamID+":[0-9]+\n",SteamID+":"+Money+"\n")
} else {
UserAccounts += SteamID + ":" + Money + "\n"
}
MoneyCachedUser = User
MoneyCache = Money
}
}
function number getPlayerBan(Ply:entity) {
if (BannedPlayers:find(Ply:steamID64()) != 0) {
return 1
}
return 0
}
function banPlayer(Name:string,Bool) {
local Ply = findPlayerByName(Name)
if (Ply) {
if (Bool) {
if (!getPlayerBan(Ply)) {
BannedPlayers += Ply:steamID64()+"\n"
}
} else {
if (getPlayerBan(Ply)) {
BannedPlayers = BannedPlayers:replace(Ply:steamID64()+"\n","")
}
}
fileWrite( BansFile, BannedPlayers )
print_("Player '" + Ply:name() + "' has been " + (Bool ? "banned." : "unbanned."))
} else {
print_("Unable to find a player named '" + Name + "'.")
}
}
function insertShipment(E:entity) {
if (E == entity()) {
Shipments:pushTable(table(
"entity" = entity(),
"pricePerUnit" = randint(1000,4000)#Shipments:count()+1
))
return
}
local UserCost = E:pricePerUnit()
local Shipment = table(
"entity" = E,
"pricePerUnit" = UserCost
)
for(I=1,Shipments:count()) {
local ThisUserCost = Shipments[I,table]["pricePerUnit",number]
if (UserCost > ThisUserCost) {
Shipments:insertTable(I,Shipment)
return
}
}
Shipments:pushTable(Shipment)
}
function forEachShipmentOnScreen(Callback:string) {
local Num = Shipments:count()
for(I=1,min(Num,ItemsPerPage)) {
if (I+Scroll > Num) {break}
local Shipment = Shipments[I+Scroll,table]
Callback(I,Shipment)
}
}
function insertMoney_ex(I,Shipment:table) {
local EGPID = Shipment["egpid",number]
local Money = getUserMoney(CurrentlyLoggedIn)
local PricePerUnit = Shipment["pricePerUnit",number]
local YesColor = vec(75,200,75)
local NoColor = vec(75)
if (AllowBuyEntireShipment) {
NoColor = vec(200,75,75)
#Check buy all
local Amount = 0
local E = Shipment["entity",entity]
if (E) {Amount = E:shipmentAmount()}
if (Money >= PricePerUnit * Amount) {
EGP:egpColor(EGPID+4,YesColor)
} else {
EGP:egpColor(EGPID+4,NoColor)
}
#Increase ID for buy one button
EGPID += 6
}
if (Money >= PricePerUnit) {
EGP:egpColor(EGPID,YesColor)
} else {
EGP:egpColor(EGPID,NoColor)
}
}
function number buyShipment(I,Shipment:table,EntireShipment) {
local Money = getUserMoney(CurrentlyLoggedIn)
local Ent = Shipment["entity",entity]
if (!Ent:isValid()) {
displayError("The shipment entity has been removed!")
print_("A user attempted to buy a shipment which has been removed! Searching for shipments...",1)
timer("searchShipments",1250)
return 0
}
if (Ent:shipmentAmount() == 0) {
displayError("This shipment has no stock!")
print_("A user attempted to buy a shipment which is out of stock (but for some reason wasn't deleted?). Searching for shipments...",1)
timer("searchShipments",1250)
return 0
}
local EGPID = Shipment["egpid",number]
local Amount = Ent:shipmentAmount()
local PricePerUnit = Shipment["pricePerUnit",number] * (EntireShipment ? Amount : 1)
if (Money < PricePerUnit) {
displayError("You can't afford that.")
return 0
}
Money = floor(Money-PricePerUnit)
setUserMoney(CurrentlyLoggedIn,Money)
EGP:egpSetText(UserMoneyLabel,"$" + Money)
saveUserMoney()
forEachShipmentOnScreen("insertMoney_ex")
timer("runInsertMoneyExAgain",1250)
if (EntireShipment) {
Ent:setPos(Ent:pos() + Ent:up() * (Ent:boxSize():z()+10))
} else {
WireUser:entity():setPos(Ent:pos())
WireUser["Fire",number] = 0
timer("activateuser",10)
}
if (Amount == 1 | EntireShipment) {
print_(Ent:shipmentName() + " is out of stock!",1)
EGP:egpRemove(EGPID)
EGP:egpRemove(EGPID+1)
EGP:egpRemove(EGPID+2)
EGP:egpRemove(EGPID+3)
if (EntireShipment) {
EGP:egpRemove(EGPID+4)
EGP:egpRemove(EGPID+5)
EGP:egpRemove(EGPID+6)
EGP:egpRemove(EGPID+7)
}
Shipments:remove(I)
timer("searchShipments",1250)
Ent["alreadyPurchased",number] = curtime()+60
} else {
EGP:egpSetText(EGPID+3,"Stock: " + (Ent:shipmentAmount()-1) + "/" + Ent:shipmentSpawnAmount())
}
local YouPayed = Ent:shipmentPricePerUnit() * (EntireShipment ? Amount : 1)
local Earned = PricePerUnit - YouPayed
TotalEarnings+=Earned
if (EntireShipment) {
print_(EGPUser:name() + " bought an entire shipment of " + Ent:shipmentName() +
"! You earned $" + Earned + "! " +
"Total earnings this session: $" + TotalEarnings )
} else {
print_(EGPUser:name() + " bought a " + Ent:shipmentName() +
". You earned $" + Earned + "! " +
"Total earnings this session: $" + TotalEarnings )
}
return 1
}
function logOutUser() {
CurrentlyLoggedIn = noentity()
AUserIsLoggedIn = 0
timer("updateScreen",100)
}
function insertMoney(ForceUpdate) {
if (MoneyPotStoredAmount > CurrentMoneyPotStoredAmount | ForceUpdate) {
if (CurrentlyLoggedIn) {
local Diff = floor(MoneyPotStoredAmount-CurrentMoneyPotStoredAmount)
local Money = getUserMoney(CurrentlyLoggedIn)
Money += Diff
setUserMoney(CurrentlyLoggedIn,Money)
saveUserMoney()
EGP:egpSetText(UserMoneyLabel,"$" + Money)
CurrentMoneyPotStoredAmount = MoneyPotStoredAmount
forEachShipmentOnScreen("insertMoney_ex")
}
} else {
CurrentMoneyPotStoredAmount = MoneyPotStoredAmount
if (CurrentlyLoggedIn) {
local Money = getUserMoney(CurrentlyLoggedIn)
EGP:egpSetText(UserMoneyLabel,"$" + Money)
}
}
}
function insertMoney() {insertMoney(0)}
function screenPress_ex(I,Shipment:table) {
local EGPID = Shipment["egpid",number]
if (AllowBuyEntireShipment) {
EGPID+=6
}
#Check buy one button
local MinCorner = vec2(EGP:egpGlobalPos(EGPID)) - EGP:egpSize(EGPID)/2
local MaxCorner = vec2(EGP:egpGlobalPos(EGPID)) + EGP:egpSize(EGPID)/2
if (inrange(Cursor,MinCorner,MaxCorner)) {
if (buyShipment(I,Shipment,0)) {
EGP:entity():soundPlay(1,0.2,"buttons/button14.wav")
} else {
EGP:entity():soundPlay(1,0.6,"buttons/button16.wav")
}
return
}
if (!AllowBuyEntireShipment) {return}
#Check buy all button
local MinCorner = vec2(EGP:egpGlobalPos(EGPID-2)) - EGP:egpSize(EGPID-2)/2
local MaxCorner = vec2(EGP:egpGlobalPos(EGPID-2)) + EGP:egpSize(EGPID-2)/2
if (inrange(Cursor,MinCorner,MaxCorner)) {
if (buyShipment(I,Shipment,1)) {
EGP:entity():soundPlay(1,0.2,"buttons/button14.wav")
} else {
EGP:entity():soundPlay(1,0.6,"buttons/button16.wav")
}
return
}
}
function entity:pressScreen() {
local Banned = This:isPlayerBanned()
if (Banned != "") {
displayError(Banned)
return
}
Cursor = EGP:egpCursor(This)
#Log in button
if (!CurrentlyLoggedIn:isValid()) {
local MinCorner = EGP:egpPos(LogInButton) - EGP:egpSize(LogInButton)/2
local MaxCorner = EGP:egpPos(LogInButton) + EGP:egpSize(LogInButton)/2
if (inrange(Cursor,MinCorner,MaxCorner)) {
CurrentlyLoggedIn = This
AUserIsLoggedIn = 1
timer("checkLoggedInDistance",1000)
timer("updateScreen",100)
insertMoney()
EGP:entity():soundPlay(1,0.2,"buttons/button14.wav")
exit()
}
} else {
#Next page
local MinCorner = EGP:egpPos(NextPageButton) - EGP:egpSize(NextPageButton)/2
local MaxCorner = EGP:egpPos(NextPageButton) + EGP:egpSize(NextPageButton)/2
if (inrange(Cursor,MinCorner,MaxCorner)) {
if (Shipments:count() > Scroll+ItemsPerPage) {
Scroll += ItemsPerPage
#if (Scroll > Shipments:count()-ItemsPerPage) {Scroll = Shipments:count()-ItemsPerPage}
if (Scroll < 0) {Scroll = 0}
stoptimer("updateScreen")
timer("updateScreen",100)
EGP:entity():soundPlay(1,0.2,"buttons/button14.wav")
}
exit()
}
#Prev page
local MinCorner = EGP:egpPos(PrevPageButton) - EGP:egpSize(PrevPageButton)/2
local MaxCorner = EGP:egpPos(PrevPageButton) + EGP:egpSize(PrevPageButton)/2
if (inrange(Cursor,MinCorner,MaxCorner)) {
if (Scroll >= ItemsPerPage) {
Scroll -= ItemsPerPage
if (Scroll < 0) {Scroll = 0}
stoptimer("updateScreen")
timer("updateScreen",100)
EGP:entity():soundPlay(1,0.2,"buttons/button14.wav")
}
exit()
}
#Log out button
local MinCorner = EGP:egpPos(LogOutButton) - EGP:egpSize(LogOutButton)/2
local MaxCorner = EGP:egpPos(LogOutButton) + EGP:egpSize(LogOutButton)/2
if (inrange(Cursor,MinCorner,MaxCorner)) {
logOutUser()
EGP:entity():soundPlay(1,0.2,"buttons/button14.wav")
exit()
}
}
if (curtime() < AntiSpamCD) {
EGP:entity():soundPlay(1,0.6,"buttons/button16.wav")
return
}
AntiSpamCD = curtime() + 1
forEachShipmentOnScreen("screenPress_ex")
}
function searchShipments() {
findIncludeClass("spawned_shipment")
findInSphere(BaseProp:pos(),BaseProp:boxSize():length()*2+ExtraSearchRadius)
#findClipToClass("spawned_shipment")
local ShipmentEntities = findToArray()
local OldNum = Shipments:count()
#Clear shipments
Shipments = table()
for(I=1,ShipmentEntities:count()) {
local E = ShipmentEntities[I,entity]
if (E:isShipment() & E:shipmentAmount() > 0 & E["alreadyPurchased",number] < curtime()) {
insertShipment(E)
}
}
print_("Found " + (Shipments:count()-OldNum) + " new shipments.")
#[
#for testing purposes:
for(I=1,40) {
insertShipment(
entity()
)
}
#]#
timer("updateScreen",500)
}
function outputAllMoney() {
MoneyPotOutputAmount = MoneyPotStoredAmount
}
function chatCommand(Msg:array) {
if (Msg[1,string] == "ban") {
hideChat(1)
local Name = Msg:concat(" ",2)
banPlayer(Name,1)
} elseif (Msg[1,string] == "unban") {
hideChat(1)
local Name = Msg:concat(" ",2)
banPlayer(Name,0)
} elseif (Msg[1,string] == "outputmoney") {
outputAllMoney()
print_("Outputting all the money.")
hideChat(1)
} elseif (Msg[1,string] == "searchshipments") {
searchShipments()
hideChat(1)
print_("Searching for shipments.")
} elseif (Msg[1,string] == "givemoney") {
hideChat(1)
local Ply = findPlayerByName(Msg:concat(" ",3))
if (Ply) {
local AddMoney = Msg[2,string]:toNumber()
local Money = getUserMoney(Ply)
setUserMoney(Ply,max(floor(Money + AddMoney),0))
saveUserMoney()
insertMoney(1)
print_("$" + floor(AddMoney) + " added to " + Ply:name() + "'s account!")
} else {
print_("Player '" + Msg:concat(" ",3) + "' not found.")
}
}
}
function updateScreen_ex(I,Shipment:table) {
local Side = (I+1) % 2
local Y = (I - Side) * 23.5 + 24
local CenterPos = vec2(128+(Side ? 255 : 1),Y)
local Size = vec2(248,40)
local Money = getUserMoney(CurrentlyLoggedIn)
local E = Shipment["entity",entity]
local PricePerUnit = Shipment["pricePerUnit",number]
local Name = E:shipmentName()
local Amount = E:shipmentAmount()
local SpawnAmount = E:shipmentSpawnAmount()
X++
local Box = X
Shipment["egpid",number] = X
EGP:egpRoundedBox(X,CenterPos,Size)
EGP:egpRadius(X,6)
if (!AllowBuyEntireShipment) {
if (Money >= PricePerUnit) {
EGP:egpColor(X,vec(75,200,75))
} else {
EGP:egpColor(X,vec(75))
}
} else {
EGP:egpColor(X,vec(75))
}
X++
EGP:egpText(X,Name,-Size/2+vec2(4,2))
EGP:egpColor(X,vec(255))
EGP:egpAlign(X,0,0)
EGP:egpSize(X,16)
EGP:egpParent(X,Box)
X++
local PriceOffset = 4
local BuyShipmentSize = vec2(Size:y()+8,Size:y())
if (AllowBuyEntireShipment) {PriceOffset = BuyShipmentSize:x()*2}
EGP:egpText(X,"$"+PricePerUnit,Size/2-vec2(PriceOffset,4))
EGP:egpAlign(X,2,2)
EGP:egpSize(X,16)
EGP:egpColor(X,vec(255))
EGP:egpParent(X,Box)
X++
local Str = "Stock: " + Amount + "/" + SpawnAmount
EGP:egpText(X,Str,Size/2*vec2(-1,1)+vec2(4,-4))
EGP:egpColor(X,vec(255))
EGP:egpAlign(X,0,2)
EGP:egpSize(X,14)
EGP:egpParent(X,Box)
if (AllowBuyEntireShipment) {
#BUY ALL BUTTON
X++
EGP:egpRoundedBox(X,vec2(Size:x()/2-BuyShipmentSize:x()/2,0),BuyShipmentSize)
EGP:egpRadius(X,6)
local Amount = 0
local Ent = Shipment["entity",entity]
if (Ent) {Amount = Ent:shipmentAmount()}
if (Money >= Shipment["pricePerUnit",number] * Amount) {
EGP:egpColor(X,vec(75,200,75))
} else {
EGP:egpColor(X,vec(200,75,75))
}
EGP:egpParent(X,Box)
X++
EGP:egpTextLayout(X,"BUY\nALL",-BuyShipmentSize/2,BuyShipmentSize)
EGP:egpAlign(X,1,1)
EGP:egpColor(X,vec(255))
EGP:egpSize(X,18)
EGP:egpParent(X,X-1)
#BUY ONE BUTTON
X++
EGP:egpBox(X,vec2(Size:x()/2-BuyShipmentSize:x()*(3/2)+4,0),BuyShipmentSize)
if (Money >= PricePerUnit) {
EGP:egpColor(X,vec(75,200,75))
} else {
EGP:egpColor(X,vec(200,75,75))
}
EGP:egpParent(X,Box)
X++
EGP:egpTextLayout(X,"BUY\nONE",-BuyShipmentSize/2,BuyShipmentSize)
EGP:egpAlign(X,1,1)
EGP:egpColor(X,vec(255))
EGP:egpSize(X,18)
EGP:egpParent(X,X-1)
}
}
function updateScreen() {
hideError()
X = 1
EGP:egpText(X,"Divran's gunshop v" + VERSION,vec2(512-4,2))
EGP:egpSize(X,14)
EGP:egpAlign(X,2,0)
EGP:egpColor(X,vec(255))
EGP:egpAngle(X,0)
if (!CurrentlyLoggedIn:isValid()) {
X++
LogInButton = X
EGP:egpRoundedBox(X,vec2(256,256),vec2(500,84))
EGP:egpColor(X,vec(75,200,75))
EGP:egpRadius(X,6)
EGP:egpUnParent(X)
X++
EGP:egpText(X,"Log in",vec2())
EGP:egpSize(X,72)
EGP:egpColor(X,vec(0))
EGP:egpParent(X,X-1)
EGP:egpAlign(X,1,1)
} else {
local Y = 19 * 24 + 16 + 5
local CenterPos = vec2(512-70,Y)
local Size = vec2(128,50)
X++
NextPageButton = X
EGP:egpRoundedBox(X,CenterPos,Size)
EGP:egpColor(X,vec(75))
EGP:egpRadius(X,6)
EGP:egpUnParent(X)
X++
EGP:egpText(X,">",vec2())
EGP:egpColor(X,vec(255))
EGP:egpSize(X,28)
EGP:egpAlign(X,1,1)
EGP:egpParent(X,X-1)
X++
PrevPageButton = X
local CenterPos = vec2(70,Y)
EGP:egpRoundedBox(X,CenterPos,Size)
EGP:egpColor(X,vec(75))
EGP:egpRadius(X,6)
EGP:egpUnParent(X)
X++
EGP:egpText(X,"<",vec2())
EGP:egpColor(X,vec(255))
EGP:egpSize(X,28)
EGP:egpAlign(X,1,1)
EGP:egpParent(X,X-1)
X++
UserMoneyLabel = X
local Money = getUserMoney(CurrentlyLoggedIn)
EGP:egpText(X,"$"+Money,vec2(256,Y))
EGP:egpSize(X,30)
EGP:egpAlign(X,1,1)
EGP:egpColor(X,vec(255))
EGP:egpUnParent(X)
X++
LogOutButton = X
EGP:egpRoundedBox(X,vec2(128,14),vec2(248,18))
EGP:egpRadius(X,6)
EGP:egpColor(X,vec(75))
EGP:egpUnParent(X)
X++
EGP:egpText(X,"["+CurrentlyLoggedIn:name()+"] Log Out",vec2())
EGP:egpAlign(X,1,1)
EGP:egpSize(X,16)
EGP:egpParent(X,X-1)
forEachShipmentOnScreen("updateScreen_ex")
}
#Cursor
X++
EGP:egpTriangle(X,vec2(0,0),vec2(10,4),vec2(4,10))
EGP:egpParentToCursor(X)
EGP:egpColor(X,vec(175,110,110))
for(I=X+1,OldX) {
EGP:egpRemove(I)
}
OldX = X
}
} elseif (~SearchShipments & SearchShipments | clk("searchShipments")) {
searchShipments()
} elseif (~EGPUser & EGPUser & EGPUser:isPlayer()) {
EGPUser:pressScreen()
} elseif (~MoneyPotStoredAmount) {
insertMoney()
} elseif (chatClk(owner())) {
local Msg = lastSaid():lower():explode(" ")
if (Msg[1,string]:sub(1,ChatPrefix:length()) == ChatPrefix) {
Msg[1,string] = Msg[1,string]:sub(ChatPrefix:length()+1)
chatCommand(Msg)
}
} elseif (clk("updateScreen")) {
updateScreen()
} elseif (clk("removeErrorPopup")) {
hideError()
} elseif (fileClk(MoneyFile)) {
local Status = fileStatus()
if (Status == _FILE_OK) {
UserAccounts = fileRead()
print_("User accounts loaded.")
} elseif (Status == _FILE_404) {
saveUserMoney()
print_("No users file found. Created new users file.")
} else {
displayError("Unable to load user file! Error code: " + Status)
print_("Unable to load user file! Error code: " + Status,1)
exit()
}
timer("loadBanned",5100)
} elseif (clk("loadBanned")) {
if (fileCanLoad()) {
fileLoad(BansFile)
} else {
timer("loadBanned",1000)
}
} elseif (fileClk(BansFile)) {
local Status = fileStatus()
if (Status == _FILE_OK) {
BannedPlayers = fileRead()
print_("Bans loaded.")
} elseif (Status == _FILE_404) {
fileWrite( BansFile, "" )
#we don't need to display errors if the bans file fails to load, it's not that important
#print_("No banned user file found. Created new file")
} else {
#we don't need to display errors if the bans file fails to load, it's not that important
#displayError("Unable to load banned users file! Error code: " + Status)
#print_("Unable to load banned users file! Error code: " + Status,1)
}
} elseif (clk("checkLoggedInDistance")) {
local Distance = CurrentlyLoggedIn:shootPos():distance(EGP:entity():boxCenterW())
if (Distance > AutoLogOutDistance) {
logOutUser()
}
if (CurrentlyLoggedIn:isValid()) {
timer("checkLoggedInDistance",1000)
}
} elseif (clk("activateuser")) {
WireUser["Fire",number] = 1
timer("deactivateuser",10)
} elseif (clk("deactivateuser")) {
WireUser["Fire",number] = 0
WireUser:entity():setPos(OriginalUserPos)
} elseif (~WireUser & WireUser) {
OriginalUserPos = WireUser:entity():pos()
} elseif (clk("runInsertMoneyExAgain")) {
if (CurrentlyLoggedIn) {
forEachShipmentOnScreen("insertMoney_ex")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment