Hop til indhold
Stavox

MukhleGunshop


Michael K

Recommended Posts

E2'en udgives som den er, og jeg vil ikke hjælpe med at bruge den eller med at foretage ændringer i den.

 

Spoiler
-gunshop
	profit
		procent {procent} | Procentdel af våbnets pris som lægge oven i den originale pris.
		min {profit} | Minimumsbeløb som lægges oven i våbnets originale pris.
	blacklist
		player
			add {navn eller steamid} | Blacklist en spiller fra at benytte skærmen.
			remove {navn eller steamid} | Tillad en blacklisted spiller at benytte skærmen.
			list | Liste over blacklistede spillere.
		gang
			add {gang navn} | Blacklist et gang fra at benytte skærmen.
			remove {gang navn} | Tillad et blacklisted gang at benytte skærmen.
			list | Liste over blacklistede gangs.
	stock | Viser en liste af våben-kasser, hvor meget der er i hver kasse, og hvor meget de sægles for per styk.

 

@name MukhleGunshop
@inputs [User]:entity [Egp]:wirelink [Min Max]:vector
@outputs Door
@persist [O ActiveUser Requested]:entity 
@persist [PlayerBlacklist GangBlacklist SteamIDLookup]:gtable
@persist [MessageCooldown]:table
@persist [Players Shipments]:array
@persist [ColW ColO ColG]:vector
@persist [PlayerBlacklistMessage GangBlacklistMessage]:string
@persist MininumProfit PercentProfit CurrentScreen RequestAmount 
@persist CurrentLookupIndex TargetLookupIndex LastLookupUpdate LookupFirstPassed
@persist CurrentShipmentIndex TargetShipmentIndex FoundShipments [TempFoundShipments]:array
@persist CurrentStockIndex TargetStockIndex [TempStockShipments]:array
@persist LoadedFrame GenerateFrameIndex ReadyForUse
@persist [OnScreen OffScreen]:vector2
@persist [SavedFrames]:table
@trigger

if(dupefinished()) {
    reset()
}

if(first()) {
    if(!convarnum("wire_expression2_concmd")) {
        error("skriv \"wire_expression2_concmd 1\" i console, for at E2'en kan virke.")        
    }

    function string comma(Amount:number) {
        local Formatted = toString(Amount)
        
        while(1) {
            local New = Formatted:replaceRE("^(-?%d+)(%d%d%d)", "%1,%2")
            local Old = Formatted
            
            Formatted = New
            
            if(New == Old) {
                break
            }
        }
        
        return Formatted
    }
    
    function number entity:blacklistStatus() {
        if(GangBlacklist[This:getGang(),number]) {
            return 2
        }
        
        if(PlayerBlacklist[This:steamID(),number]) {
            return 1
        }
        
        return 0
    }
    
    function number entity:cooldownMessage(Message:string,Cooldown:number) {
        local SteamID = This:steamID()
        
        if(curtime() > MessageCooldown[SteamID,number]) {
            sendMessage(This,Message)
                
            MessageCooldown[SteamID,number] = curtime() + Cooldown
            
            return 1
        } 
        
        return 0
    }
            
    function number string:isSteamID() {
        return This:matchFirst("STEAM_[0-5]:[01]:%d+$") ? 1 : 0
    }
    
    function number wirelink:egpButton(Idx:number,Ply:entity) {
        local Cur = This:egpCursor(Ply)
        
        return This:egpObjectContainsPoint(Idx,Cur)
    }
    
    function number entity:getShipmentPrice() {
        local BasePrice = This:shipmentPrice()       
        local CalcPrice = max(BasePrice + MininumProfit,BasePrice * (1 + (PercentProfit / 100)))

        return CalcPrice - (CalcPrice % 100)
    }
    
    function string entity:getShipmentName() {
        return This:isShipment() ? This:shipmentName() : "Udsolgt"
    }        
     
    function createButton(StartIndex, Text:string, Height, Parent) {
        Egp:egpBox(StartIndex,vec2(256,Height),vec2(300,30))
        Egp:egpColor(StartIndex,vec(34,34,34))
        Egp:egpAlpha(StartIndex,204)
        Egp:egpParent(StartIndex,Parent)

        Egp:egpBoxOutline(StartIndex+1,vec2(256,Height),vec2(300,30))
        Egp:egpSize(StartIndex+1,2)
        Egp:egpColor(StartIndex+1,ColG)
        Egp:egpParent(StartIndex+1,Parent)

        Egp:egpText(StartIndex+2,Text,vec2(256,Height))
        Egp:egpSize(StartIndex+2,20)
        Egp:egpColor(StartIndex+2,ColG)
        Egp:egpAlign(StartIndex+2,1,1)
        Egp:egpParent(StartIndex+2,Parent)
    }
                
    function showLogin() {
        local Index = SavedFrames["login",number]
        
        if(LoadedFrame) {
            Egp:egpPos(LoadedFrame,vec2(512,0))
        }
        
        Egp:egpPos(Index,OnScreen)

        LoadedFrame = Index
        CurrentScreen = 1
                
        for(I=1,FoundShipments*3) {
            local StartIndex = 50+(I-1)

            Egp:egpRemove(StartIndex)
            Egp:egpRemove(StartIndex+1)
            Egp:egpRemove(StartIndex+2)                                        
        }                              
    }

    function showShop() {
        local Index = SavedFrames["shop",number]
        
        if(LoadedFrame) {
            Egp:egpPos(LoadedFrame,vec2(512,0))
        }        
        
        Egp:egpPos(Index,OnScreen)

        LoadedFrame = Index
        CurrentScreen = 2
    }
        
    O = owner()
    
    MininumProfit = 4000
    PercentProfit = 50
        
    PlayerBlacklist = gTable("Gunshop_PlayerBlacklist",0)
    GangBlacklist = gTable("Gunshop_GangBlacklist",0)
    SteamIDLookup = gTable("SteamIDLookup",0)

    PlayerBlacklistMessage = format("Du er blacklistet, og kan derfor ikke ikke benytte v%sbenbutikken.",aa())
    GangBlacklistMessage = format("Dit gang er blacklistet, og du kan derfor ikke ikke benytte v%sbenbutikken.",aa())
    
    ColW = vec(255,255,255)
    ColO = vec(255,127,0)
    ColG = vec(0,255,150)
    
    GenerateFrameIndex = 1
    
    OnScreen = vec2(0,0)
    OffScreen = vec2(512,0)
    
    Egp:egpClear()
    
    local Color = vec(34,34,34)*0.8
    
    Egp:egpBox(1,vec2(256,256),vec2(512,512))	
    Egp:egpColor(1,Color)
    
    Egp:egpPoly(2,array(vec2(193,413),vec2(0,436),vec2(0,283)))	
    Egp:egpColor(2,Color*0.9)
    
    Egp:egpPoly(3,array(vec2(96,207),vec2(192,0),vec2(0,0)))	
    Egp:egpColor(3,Color*0.75)
    
    Egp:egpPoly(4,array(vec2(96,207),vec2(512,0),vec2(192,0)))	
    Egp:egpColor(4,Color*0.8)
    
    Egp:egpPoly(5,array(vec2(302,104),vec2(193,413),vec2(96,207)))	
    Egp:egpColor(5,Color*0.9)   
    
    Egp:egpPoly(6,array(vec2(400,512),vec2(302,104),vec2(193,413)))	
    Egp:egpColor(6,Color*0.75)
    
    Egp:egpPoly(7,array(vec2(353,320),vec2(512,417),vec2(512,0)))	
    Egp:egpColor(7,Color*0.9)
    
    Egp:egpPoly(8,array(vec2(442,373),vec2(400,512),vec2(353,320)))	
    Egp:egpColor(8,Color*0.8)

    Egp:egpPoly(9,array(vec2(442,373),vec2(512,512),vec2(512,417)))	
    Egp:egpColor(9,Color*0.75)
    
    Egp:egpPoly(10,array(vec2(193,413),vec2(400,512),vec2(120,512)))	
    Egp:egpColor(10,Color*0.9)

    Egp:egpPoly(11,array(vec2(78,426),vec2(0,512),vec2(0,436)))	
    Egp:egpColor(11,Color*0.75)
    
    Egp:egpPoly(12,array(vec2(78,426),vec2(120,512),vec2(0,512)))	
    Egp:egpColor(12,Color*0.8)     
        
    findIncludeClass("cabr_shipment")
    
    timer("LookupLoop",750)
    timer("generateFrames",100)
    
    runOnChat(1)
}elseif(ReadyForUse) {
    if(clk("LookupLoop")) {
        if(cpuUsage() < 0.000080) {
            if(TargetLookupIndex & TargetLookupIndex >= CurrentLookupIndex) {
                local Player = Players[CurrentLookupIndex,entity]
                
                if(Player) {
                    local SteamID = Player:steamID()
    
                    SteamIDLookup[SteamID,entity] = Player
                    SteamIDLookup[SteamID,string] = Player:name()
                    SteamIDLookup[SteamID,number] = curtime()             
                }
                
                if(TargetLookupIndex == CurrentLookupIndex) {
                    if(!LookupFirstPassed) {
                        printColor(ColO,"Gunshop klar til brug.")   
                        
                        LookupFirstPassed = 1 
                    }                
                }
                    
                CurrentLookupIndex++
            }else {
                if(curtime() - LastLookupUpdate > 10) {                
                    Players = players():clone()
                    TargetLookupIndex = Players:count()
                    CurrentLookupIndex = 1
    
                    LastLookupUpdate = curtime()    
                }
            } 
        }
               
        timer("LookupLoop",750)
    }elseif(clk("ShipmentLoop")) {    
        if(CurrentScreen == 2 & FoundShipments < 10 & TargetShipmentIndex >= CurrentShipmentIndex) {
            if(cpuUsage() < 0.000080) {
                local Shipment = TempFoundShipments[CurrentShipmentIndex,entity]
    
                if(Shipment & Shipment:owner() == O) {
                    Shipments:pushEntity(Shipment)
    
                    createButton(50+3*FoundShipments,format("%s - %s kr",Shipment:getShipmentName(),comma(Shipment:getShipmentPrice())),56+40*(FoundShipments),40)       
                    
                    FoundShipments++             
                }
    
                CurrentShipmentIndex++
            }  
            
            timer("ShipmentLoop",150)    
        }        
    }elseif(clk("StockLoop")) {
        if(TargetStockIndex >= CurrentStockIndex) {
            if(cpuUsage() < 0.000080) {
                local Shipment = TempStockShipments[CurrentStockIndex,entity]
    
                if(Shipment) {
                    if(Shipment:owner() == O) {
                        printColor(ColW,"Kasse af ",ColO,Shipment:getShipmentName(),ColW,", indeholder ",ColO,Shipment:shipmentAmount(),ColW,format(" v%sben. Koster ",aa()),ColO,format("%s kr",comma(Shipment:getShipmentPrice())),ColW,".")    
                    }else {
                        printColor(ColW,"Kasse af ",ColO,Shipment:getShipmentName(),ColW,", indeholder ",ColO,Shipment:shipmentAmount(),ColW,format(" v%sben. Koster ",aa()),ColO,format("%s kr",comma(Shipment:getShipmentPrice())),ColW,". Du ejer ikke denne kasse.")
                    }           
                }
    
                CurrentStockIndex++
            }  
    
            timer("StockLoop",150)    
        }    
    }elseif(inputClk()) {
        local Input = inputClkName()
    
        if(Input == "User") {
            if(User & cpuUsage() < 0.000050 & ops() < 200) {
                if(CurrentScreen == 1) {
                    local Blacklist = User:blacklistStatus() 
                                  
                    if(Blacklist == 0) {
                        if(Egp:egpButton(21,User)) {
                            if(findCanQuery()) {
                                showShop()
                                
                                Shipments:clear()
                                
                                findByClass("cabr_shipment")
                                findInBox(Min,Max)   
                                
                                TempFoundShipments = findToArray()
                                TargetShipmentIndex = TempFoundShipments:count()
                                CurrentShipmentIndex = 1
                                FoundShipments = 0
           
                                ActiveUser = User
                                
                                timer("ShipmentLoop",250)
                            }
                        }                    
                    }elseif(Blacklist == 1) {
                        User:cooldownMessage(PlayerBlacklistMessage,15) 
                    }elseif(Blacklist == 2) {
                        User:cooldownMessage(GangBlacklistMessage,15) 
                    }
                }elseif(CurrentScreen == 2) {
                    if(User == ActiveUser & RequestAmount == 0) {
                        local Cursor = Egp:egpCursor(User)               
                        local Count = Shipments:count()
                        local Offset = 41
                        
                        if(Count & inrange(Cursor,vec2(106,Offset),vec2(406,Offset+40*Count-(Count > 1 ? 10 : 0)))) {   
                            local Y = Cursor:y()
                            local Index = floor((Y-Offset)/40)
                            local ButtonStart = Offset+40*Index
                            
                            if(inrange(Y,ButtonStart,ButtonStart+30)) {
                                local Shipment = Shipments[Index+1,entity]
    
                                if(Shipment) {     
                                    local Price = Shipment:getShipmentPrice()
                                    local Name = Shipment:getShipmentName()
                                    
                                    moneyRequest(User,Price,Name)
                                    
                                    Requested = Shipment
                                    RequestAmount = Price
                                }   
                            }               
                        }elseif(Egp:egpButton(41,User)) {    
                            ActiveUser = noentity()
 
                            showLogin()
                        }
                    }
                }
            }
        }elseif(Input == "Egp") {
            if(->Egp) {
                reset()    
            }
        }
    }elseif(clk("CheckDistance")) {
        if(ActiveUser) {
            if(Egp:entity():pos():distance2(ActiveUser:pos()) > 65536) {
                ActiveUser = noentity()
                
                showLogin()
            }
        }else{
            if(CurrentScreen > 1) {
                showLogin()    
            }
        }
        
        timer("CheckDistance",2000)
    }elseif(chatClk()) {
        local LastSaid = lastSaid():explode(" ")
    
        if(LastSaid[1,string] == "-gunshop") {
            if(LastSaid[2,string] == "profit") {
                if(LastSaid[3,string] == "min") {
                    local Amount = LastSaid[4,string]:toNumber()
                    
                    if(Amount) {
                        if(Amount >= 0) {
                            MininumProfit = Amount 
                            
                            printColor(ColW,"Minimums-profit sat til ",ColO,format("%s kr",comma(Amount)))
                        }else {
                            printColor(ColO,format("Minimums-profit skal v%sre over eller lig med 0.",ae()))       
                        }  
                    }else {
                        printColor(ColW,"Minimums-profit er sat til ",ColO,format("%s kr",comma(MininumProfit)))            
                    }
                }elseif(LastSaid[3,string] == "procent") {
                    local Amount = LastSaid[4,string]:toNumber()
                    
                    if(Amount) {
                        if(Amount >= 0) {
                            PercentProfit = Amount 
                            
                            printColor(ColW,"Procent-profit sat til ",ColO,format("%s%%",Amount))
                        }else {
                            printColor(ColO,format("Procent-profit skal v%sre over eller lig med 0.",ae()))       
                        }  
                    }else {
                        printColor(ColW,"Procent-profit er sat til ",ColO,format("%s%%",PercentProfit))            
                    }
                }
            }elseif(LastSaid[2,string] == "blacklist") {
                if(LastSaid[3,string] == "player") {
                    if(LastSaid[4,string] == "add") {
                        local Find = LastSaid:concat(" ",5)
           
                        if(Find:isSteamID()) {
                            local Player = SteamIDLookup[Find,entity]
                            
                            if(Player) {
                                local Name = Player:name()
                                
                                if(Name) {
                                    PlayerBlacklist[Find,number] = 1
                                    
                                    printColor(vec(255,127,0),Name,vec(0,200,0)," blacklisted.") 
                                }
                            }else {   
                                PlayerBlacklist[Find,number] = 1
                                
                                printColor(vec(255,127,0),Find,vec(0,200,0)," blacklisted.") 
                            }            
                        }else {
                            local Player = findPlayerByName(Find)
                        
                            if(Player) {
                                local Name = Player:name()
                                local SteamID = Player:steamID()
                                
                                PlayerBlacklist[SteamID,number] = 1
        
                                printColor(vec(255,127,0),Name,vec(0,200,0)," blacklisted.")    
                            }else {
                                printColor(vec(255,255,255),"Spiller \"",vec(255,127,0),Find,vec(255,255,255),"\" ikke fundet.")
                            } 
                        }                 
                    }elseif(LastSaid[4,string] == "remove") {
                        local Find = LastSaid:concat(" ",5)
           
                        if(Find:isSteamID()) {
                            local Player = SteamIDLookup[Find,entity]
                            
                            if(Player) {
                                local Name = Player:name()
                                
                                if(Name) {
                                    PlayerBlacklist[Find,number] = 0
                                    
                                    printColor(vec(255,127,0),Name,vec(200,0,0)," unblacklisted.") 
                                }
                            }else {   
                                PlayerBlacklist[Find,number] = 0
                                
                                printColor(vec(255,127,0),Find,vec(200,0,0)," unblacklisted.") 
                            }            
                        }else {
                            local Player = findPlayerByName(Find)
                        
                            if(Player) {
                                local Name = Player:name()
                                local SteamID = Player:steamID()
                                
                                PlayerBlacklist[SteamID,number] = 0
        
                                printColor(vec(255,127,0),Name,vec(200,0,0)," unblacklisted.")    
                            }else {
                                printColor(vec(255,255,255),"Spiller \"",vec(255,127,0),Find,vec(255,255,255),"\" ikke fundet.")
                            } 
                        }            
                    }elseif(LastSaid[4,string] == "list") {
                        foreach(SteamID,Licens:number=PlayerBlacklist) {
                            if(Licens) {
                                local Target = SteamIDLookup[SteamID,entity]
                            
                                if(Target) {
                                    local Name = Target:name()
                                    
                                    printColor(vec(255,127,0),Name,vec(0,200,0)," ONLINE")
                                }else {
                                    local Name = SteamIDLookup[SteamID,string]
                                    
                                    if(Name) {
                                        printColor(vec(255,127,0),Name,"(",SteamID,")",vec(200,0,0)," OFFLINE")
                                    }else {
                                        printColor(vec(255,127,0),SteamID,vec(200,0,0)," OFFLINE")
                                    }
                                }
                            } 
                        }  
                    }             
                }elseif(LastSaid[3,string] == "gang") {
                    if(LastSaid[4,string] == "add") {
                        local Gang = LastSaid:concat(" ",5)
        
                        GangBlacklist[Gang,number] = 1
                                
                        printColor(vec(255,127,0),Gang,vec(0,200,0)," blacklisted.")                 
                    }elseif(LastSaid[4,string] == "remove") {
                        local Gang = LastSaid:concat(" ",5)
        
                        GangBlacklist[Gang,number] = 0
                        
                        printColor(vec(255,127,0),Gang,vec(200,0,0)," unblacklisted.")            
                    }elseif(LastSaid[4,string] == "list") {
                        foreach(Gang,Licens:number=GangBlacklist) {
                            if(Licens) {                        
                                printColor(vec(255,127,0),Gang)
                            } 
                        }  
                    }           
                }
            }elseif(LastSaid[2,string] == "stock") {
                findByClass("cabr_shipment")
                findInBox(Min,Max)   
                
                TempStockShipments = findToArray()
                TargetStockIndex = TempStockShipments:count()
                CurrentStockIndex = 1
    
                timer("StockLoop",250)
            }elseif(LastSaid[2,string] == "forcelogout") {
                Requested = noentity()
                RequestAmount = 0  
                 
                ActiveUser = noentity()
                
                showLogin()  
            }
            
            hideChat(1)
        }
    }elseif(moneyClk()) {
        local Payer = moneyClkPlayer()
        
        if(Requested:isValid()) {
            Requested:ejectWeapon() 
            
            local Remaining = Requested:shipmentAmount()
            
            if(Remaining > 0) {
                printColor(ColO,Payer:name(),ColW,format(" k%sbte en ",oe()),ColO,Requested:getShipmentName(),ColW," til ",ColO,format("%s kr",comma(Requested:getShipmentPrice())),ColW,". Der er ",ColO,Remaining,ColW," tilbage.")        
            }else {
                printColor(ColO,Payer:name(),ColW,format(" k%sbte en ",oe()),ColO,Requested:getShipmentName(),ColW," til ",ColO,format("%s kr",comma(Requested:getShipmentPrice())),ColW,". Der er ikke flere tilbage.")        
            }               
        }else {
            sendMessage(Payer,format("V%sbnet du bestilte er ikke l%sngere tilg%sngeligt.",aa(),ae(),ae()))
            moneyGive(Payer,RequestAmount)        
        }  
          
        Requested = noentity()
        RequestAmount = 0
        
        ActiveUser = noentity()
        
        showLogin()
    }elseif(moneyNoClk()) {
        Requested = noentity()
        RequestAmount = 0   
    }elseif(moneyTimeout()) {
        Requested = noentity()
        RequestAmount = 0  
    }
}elseif(clk("generateFrames")) {
    timer("generateFrames",100)

    if(cpuUsage() < 0.000070) {
        switch(GenerateFrameIndex) {
            case 1,
                Egp:egpBox(20,vec2(0,0),vec2(0,0))

                createButton(21,"Login",456,20)
       
                Egp:egpText(24,"B.I.C.",vec2(256,130))
                Egp:egpSize(24,100)
                Egp:egpColor(24,ColG)
                Egp:egpAlpha(24,204)
                Egp:egpAlign(24,1,1)
                Egp:egpParent(24,20)
                
                Egp:egpText(25,"Gunshop",vec2(256,232))
                Egp:egpSize(25,80)
                Egp:egpColor(25,ColG)
                Egp:egpAlpha(25,204)
                Egp:egpAlign(25,1,1)
                Egp:egpParent(25,20)
        
                Egp:egpPos(20,OffScreen)

                SavedFrames["login",number] = 20

                GenerateFrameIndex++

                break
            case 2,
                Egp:egpBox(40,vec2(0,0),vec2(0,0))
 
                createButton(41,"Log ud",456,40)        

                Egp:egpPos(40,OffScreen)

                SavedFrames["shop",number] = 40

                GenerateFrameIndex++

                break
            case 3,
                stoptimer("generateFrames")

                ReadyForUse = 1

                Egp:egpPoly(200,vec2(0,0),vec2(12,12),vec2(7,12),vec2(10,17),vec2(9,18),vec2(8,18),vec2(7,17),vec2(5,13),vec2(0,16))
                Egp:egpColor(200,ColG)
                Egp:egpAlpha(200,204)
                Egp:egpParentToCursor(200)
                
                timer("CheckDistance",2000)

                showLogin()
        }
    }
}

Door = !ActiveUser:isValid()

 

 

  • Sjovt 1
Link til kommentar
×
×
  • Tilføj...

COOKIE- OG PRIVATLIVSPOLITIK PÅ STAVOX.DK

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privatlivspolitik - Vilkår for brug.