Hop til indhold
Stavox

Fuldautomatisk pakkesystem


Recommended Posts

Kunne forstå at nogle godt gad have denne E2, så i stedet for at den bliver videresolgt, så kommer den bare her. 

 

Guide

Begge E2'er skal placeres før koden virker. Forstå nedenstående kode som resten af guiden - ellers skal jeg nok svare på evt. spørgsmål.. engang.

 

IKKE FÆRDIGUDVIKLET

Spoiler
@name PostNord v2.0
@inputs VehicleSensor:entity
@outputs 
@persist [Parcels, Employees, ParcelsDepot, TrackIDs, Vehicles, Blacklist, Difference, Data]:table [AwaitQueue, Queue, DepotTimes, DeliveryTimes, MailEmployees, Adverts]:array ReadyToEject:number
@trigger 

if(first()){
    runOnAllChat(1)
    
    Company = table()
    Color = vec()
    
    foreach(K, V:string = getDeliveryCompanyIDs()){
        if(V:find(owner():steamID())){
            Company = getDeliveryCompany(V)
        }
    }
    
    switch(Company["SkinID", number]){
        case 1,
            Color = vec(0, 160, 215)
            break
        
        case 2,
            Color = vec(212, 5, 17)
            break
        
        case 3,
            Color = vec(255, 181, 0)
            break
        
        case 4,
            Color = vec(6, 26, 177)
            break
            
            
        case 5,
            Color = vec(255, 102, 0)
            break
    }
    
    Data = table(
        "Name" = Company["Name", string],
        "LowerName" = Company["LowerName", string],
        "Color" = Color,
        "Company" = Company,
        "MailDepot" = Company["MailDepot", entity],
        
        "LatestVehicle" = noentity(),
        "AutoAdvert" = 0

    )
    
    Data["MailDepot", entity]:setAutoRemoval(90)
    print(owner():forward())
    Vehicles = table(
        "models/metrohd/merc_vito.mdl" = 6,
        "models/metrohd/vw_multivan.mdl" = 6,
        "models/metrohd/scania_s730.mdl" = 12
    )
    
    function string getClock(){
        UTC = dateUTC()
        
        return format("%02d.%02d", UTC["hour", number] + 1, UTC["min", number])
    }
    
    function printLayout(Text:string){
        printColor(Data["Color", vector], Data["Name", string]," Admin - ", vec(255), Text)
    }
    
    function pushQueue(Player:entity, Text:string){
        if(Blacklist:exists(Player:steamID())){
            return
        }
        
        elseif(!Queue:count()){
            timer("nextQueue", 975)
        }
        
        Queue:pushEntity(Player)
        Queue:pushString(Text)
    }
    
    timer("checkDepot", 1500)
    timer("updatePractical", 750)
    timer("checkDelivery", 950)
}

elseif(clk(clkName())){
    switch(clkName()){
        case "checkDelivery",
            foreach(K, V:entity = MailEmployees){
                AimEntity = V:aimEntity()
                
                if(V:inVehicle() | !AimEntity:isParcel() | Parcels[AimEntity:getParcelId(), table]["Status", string] == "delivered" | V:pos():distance(AimEntity:getParcelDestination():pos()) > 750){
                    continue
                }

                ParcelID = AimEntity:getParcelId()
                Parcel = Parcels[ParcelID, table]
                DeliveryTime = curtime() - Parcel["DeliveryTime", number]
                SteamID = Parcel["Driver", entity]:steamID()
                Employee = Employees[SteamID, table]
                Employees[SteamID, table]["DeliveryTimes", array]:pushNumber(DeliveryTime)
                
                if(Employee["ParcelsVehicle", table]:exists(ParcelID)){
                    Employees[SteamID, table]["ParcelsDelivered", array]:pushString(ParcelID)
                    Employees[SteamID, table]["ParcelsVehicle", table]:remove(ParcelID)
                    printLayout(format("%s leverede pakken %d til %s p%s %d sekunder.", Parcel["DriverName", string], Parcel["TrackID", number], Parcel["OwnerName", string], aa(), DeliveryTime))
                }
                
                else{
                    printLayout("Noget gik galt.")
                    print("The WRONG parcelID has been delivered.. Got vs. expected parcelID: " + ParcelID + " - " + Employees[SteamID, table]["ParcelsVehicle", array][1, string])
                }
                
                Parcels[ParcelID, table] = Parcel:merge(table(
                    "Status" = "delivered",
                    "LastSeen" = getClock(),
                    "DeliveryTime" = DeliveryTime
                ))
                
                DeliveryTimes:pushNumber(DeliveryTime)
                
                pushQueue(Parcel["Owner", entity], format("K%sre kunde\nDu kan nu gl%sde dig over, at vores chauff%sr %s netop har afleveret pakken %d til %s.\n\nTak fordi du valgte %s!", ae(), ae(), oe(), Parcel["DriverName", string], Parcel["TrackID", number], Parcel["MailboxFormat", string], Data["Name", string]))
            }
            
            timer("checkDelivery", 500)
            break
            
        case "checkDepot",
            timer("checkDepot", 2500)
        
            if(!Difference:count()){
                Depot = getParcelsInDepot()
                
                if(ParcelsDepot:toString() == Depot:toString()){
                    break
                }
                
                Difference = Depot:difference(ParcelsDepot)
                ParcelsDepot = Depot:clone()
            }
           
            for(I = 1, Difference:count() > 3 ? 3 : Difference:count()){
                Parcel = Difference[1, table]
                
                if(Parcels:exists(Parcel["ParcelID", string])){
                    continue
                }
                
                Mailbox = entity(Parcel["DeliveryID", number])
                MailboxName = Mailbox:getMailboxName()
                TrackID = int(Parcel["InitShipping", number])
                TrackIDs[TrackID, string] = Parcel["ParcelID", string]
                Parcels[Parcel["ParcelID", string], table] = table(
                    "Owner" = Parcel["Owner", entity],
                    "OwnerName" = Parcel["Owner", entity]:name(),
                    "LastSeen" = getClock(),
                    "DepotTime" = curtime(),
                    "Status" = "indepot",
                    "TrackID" = TrackID,
                    "MailboxFormat" = Mailbox:getMailboxType() == "pakkeboks" ? "pakkeboksen ved " + MailboxName : "postkassen ved " + MailboxName
                )
                
                pushQueue(Parcel["Owner", entity], format("K%sre kunde\nVi har registeret din pakkes ankomst til vores pakkecenter. Du kan forvente dens ankomst om %d min. F%slg dens rejse gennem kommandoen: '!%s %d'.\n\nMvh. %s", ae(), Data["AverageDepotTime", number] + Data["AverageDeliveryTime", number], oe(), Data["LowerName", string], TrackID, Data["Name", string]))
                Difference:remove(1)
            }

            break
        
        case "ejectParcel",
            Driver = VehicleSensor:owner()
            SteamID = Driver:steamID()
            
            if(Vehicles[VehicleSensor:model(), number] > Employees[SteamID, table]["ParcelsVehicle", table]:count() & ParcelsDepot:count()){
                ParcelID = ParcelsDepot[1, table]["ParcelID", string]
                
                
                if(Parcels:exists(ParcelID)){
                    Parcel = Parcels[ParcelID, table]
                    DepotTime = Parcel["DepotTime", number]
                    
                    if(Parcel["Status", string] == "indepot"){
                        DepotTime = curtime() - Parcel["DepotTime", number]
                        Employees[SteamID, table]["ParcelsVehicle", table][ParcelID, number] = 1
                        
                        DepotTimes:pushNumber(DepotTime)
                        AwaitQueue:pushEntity(Parcel["Owner", entity])
                        AwaitQueue:pushString(format("K%sre kunde\nDin pakke %d har netop forladt vores pakkecenter, og er nu p%s vej til %s. Du kan forvente dens ankomst om %d min.\n\nMvh. %s", ae(), Parcel["TrackID", number], aa(), Parcel["MailboxFormat", string], Employees[SteamID, table]["AverageDeliveryTime", number], Data["Name", string]))
                    }
                    
                    Parcels[ParcelID, table] = Parcel:merge(table(
                        "Status" = "intransit",
                        "LastSeen" = getClock(),
                        "DeliveryTime" = curtime(),
                        "DepotTime " = DepotTime,
                        "Driver" = Driver,
                        "DriverSteamID" = SteamID,
                        "DriverName" = Driver:name()
                    ))
                    printLAyout("Ejecting
                    ejectParcelFromDepot(ParcelID, Data["MailDepot", entity]:right())
                }
            }
            
            timer("ejectParcel", 2500)
            break
            
        case "nextQueue",
            printLayout(Queue:shiftEntity():toString() +  " - " + Queue:shiftString())
            
            if(Queue:count()){
                timer("nextQueue", 975)
            }
            
            break
            
        case "updatePractical",
            MailEmployees = getMailEmployees()
            OldEmployees = Employees:clone()
            
            foreach(K, V:entity = MailEmployees){
                SteamID = V:steamID()
                
                if(Employees:exists(SteamID)){
                    Employees[SteamID, table] = OldEmployees[SteamID, table]:clone()
                    Employees[SteamID, table]["AverageDeliveryTime", number] = ceil(Employees[SteamID, table]["DeliveryTimes", array]:average() / 60, 0)
                    continue
                }
                
                Employees[SteamID, table] = table(
                    "DeliveryTimes" = array(),
                    "ParcelsDelivered" = array(),
                    "ParcelsVehicle" = table(),
                    "AverageDeliveryTime" = 5
                )
            }
            
            Data["AverageDepotTime", number] = DepotTimes:count() ? ceil(DepotTimes:average() / 60, 0) : 5 #Using the function ceil to round it up instead of rounding it down.
            Data["AverageDeliveryTime", number] = DeliveryTimes:count() ? ceil(DeliveryTimes:average() / 60, 0) : 5
            
            if(Data["AutoAdvert", number]){
                Players = players()
                Name = Players[randint(1, Players:count()), entity]:name()
                
                Adverts = array(
                    format("%s - Fra %s: \"Jeg m%s bare indr%smme, at %s er de bedste, n%sr det ang%sr leveringstiden!\"", Data["Name", string], Name, aa(), oe(), Data["Name", string], aa(), aa()),
                    format("%s - Fra %s: \"%s har bare den bedste service. Ingen af deres konkurrenter n%srmer sig dem!\"", Data["Name", string], Name, Data["Name", string], ae()),
                    format("%s - Fra: %s: \"Jeg bestilte min pakke i g%sr aftes, og den er allerede ankommet med %s!\"", Data["Name", string], Name, aa(), Data["Name", string]),
                    format("%s - Fra: %s: \"Jeg er helt vild med %s's track and trace system! Det fungere bare super godt.\"", Data["Name", string], Name, Data["Name", string])
                )
                
                printLayout("say /advert " + Adverts[randint(1, Adverts:count()), string])
            }
            
            timer("updatePractical", 180000)
            break
    }
}

elseif(~VehicleSensor){
    if(VehicleSensor:isVehicle() & Employees:exists(VehicleSensor:owner():steamID())){
        Data["LatestVehicle", entity] = VehicleSensor
        timer("ejectParcel", 2500)
    }
    
    else{
        stoptimer("ejectParcel")
        
        for(I = 1, AwaitQueue:count() / 2){
            pushQueue(AwaitQueue:shiftEntity(), AwaitQueue:shiftString())
        } 
    }
}

elseif(chatClk()){
    LastSaid = lastSaid():lower():explode(" ")
    LastSpoke = lastSpoke()
    
    if(LastSpoke == owner() & Queue:count()){
        stoptimer("nextQueue")
        timer("nextQueue", 975)
    }
    
    if(LastSaid[1, string] == "!" + Data["LowerName", string]){
        switch(LastSaid[2, string]){
            case "stats",
                Argument = LastSaid:concat(" ", 3)
                Ent = Argument:length() ? findPlayerByName(Argument) : owner()
                SteamID = Ent:steamID()
                
                if(!Employees:exists(LastSpoke:steamID())){
                    pushQueue(LastSpoke, format("Denne kommando er kun tilg%sngelig for ansatte i %s.", ae(), Data["Name", string]))
                    break
                }
                
                elseif(!Ent:isPlayer()){
                    pushQueue(Ent, format("Ingen resultater fundet efter s%sgningen: '%s'.", oe(), Argument))
                    break
                }
                
                elseif(!Employees:exists(SteamID)){
                    pushQueue(Ent, format("%s er ikke ansat i din virksomhed.", Ent:name()))
                    break
                }
                
                Employee = Employees[SteamID, table]
                
                ## TODO : Make this cmd work
                pushQueue(Ent, format("Statistiker over %s arbejde\nPakker leveret: %d\nPakker i postbil: %d\nGns. leveringstid: %d min", Ent:name(), Employee["ParcelsDelivered", array]:count(), Employee["ParcelsVehicle", array]:count(), Employee["AverageDeliveryTime", number]))
                break
                
            case "fix",
                Ent = Argument:length() ? findPlayerByName(Argument) : owner()
                SteamID = Ent:steamID()
                Employee = Employees[SteamID, table]
                
                if(!Employees:exists(LastSpoke:steamID())){
                    pushQueue(LastSpoke, format("Denne kommando er kun tilg%sngelig for ansatte i %s.", ae(), Data["Name", string]))
                    break
                }
                
                elseif(!Ent:isPlayer()){
                    if(LastSpoke == owner()){
                        printLayout(format("Ingen resultater fundet efter s%sgningen: '%s'.", oe(), Argument))
                        break
                    }
                    
                    pushQueue(LastSpoke, format("Ingen resultater fundet efter s%sgningen: '%s'.", oe(), Argument))
                    break
                }
                
                elseif(!Employees:exists(SteamID)){
                    if(LastSpoke == owner()){
                        printLayout(format("%s er ikke ansat i virksomheden.", Ent:name()))
                        break
                    }
                    
                    pushQueue(LastSpoke, format("%s er ikke ansat i virksomheden.", Ent:name()))
                    break
                }
                
                elseif(!Employees[SteamID, table]["ParcelsVehicle", table]:count()){
                    if(LastSpoke == owner()){
                        printLayout(format("Ingen pakker blev fundet i %s's postbil.", Ent:name()))
                        break
                    }
                    
                    pushQueue(LastSpoke, format("Ingen pakker blev fundet i %s's postbil.", Ent:name()))
                    break
                }
                
                List = ""
                
                foreach(K, V:string = Employees[SteamID, table]["ParcelsVehicle", array]){
                    if(getParcelStatus(V) != "unknown"){
                        continue
                    }
                    
                    List = format("%s \n %d", List, V)
                    Employees[SteamID, table]["ParcelsVehicle", array]:remove(K)
                }
                
                if(List){
                    if(LastSpoke == owner()){
                        printLayout(format("Der blev fundet en fejl ved f%slgende pakker i %s's postbil: %s", oe(), Ent:name(), List))
                        break
                    }
                    
                    pushQueue(LastSpoke, format("Der blev fundet en fejl ved f%slgende pakker i %s's postbil: %s", oe(), Ent:name(), List))
                    break
                }
                
                if(LastSpoke == owner()){
                    printLayout(format("Der blev ingen fejl fundet. Hvis du fortsat oplever problemer, s%s Pr%sv at aflever en pakke og pr%sv samme kommando igen.", aa(), oe(), oe()))
                    break
                }
                pushQueue(LastSpoke, format("Der blev ingen fejl fundet. Hvis du fortsat oplever problemer, s%s Pr%sv at aflever en pakke og pr%sv samme kommando igen.", aa(), oe(), oe()))
                
                break
            
            case "test",
                printTable(Employees)
                break
            
            case "stop",
                SteamID = LastSpoke:steamID()
                
                if(Blacklist:exists(SteamID)){
                    Blacklist:remove(SteamID)
                    
                    pushQueue(LastSpoke, format("K%sre kunde\nDu vil nu igen modtage opdateringer p%s fremtidige bestilte pakker.\n\nMvh. %s", ae(), Data["Name", string]))
                    break   
                }
                
                Blacklist[SteamID, number] = 1
                
                pushQueue(LastSpoke, format("K%sre kunde\n Du vil ikke l%sngere modtage opdateringer p%s fremtidige bestilte pakker.\n\nMvh. %s", ae(), ae(), aa(), Data["Name", string]))
                break
                
            default,
                ParcelID = TrackIDs[LastSaid[2, string]:toNumber(), string]
                
                if(Parcels:exists(ParcelID)){
                    Parcel = Parcels[ParcelID, table]
                    
                    switch(Parcel["Status", string]){
                        case "indepot",
                            pushQueue(LastSpoke, format("K%sre kunde\nPakke %s ligger i vores depot, og afventer en ledig chauff%sr medtager den. Denne fase tager normalt blot %d min.\n\nMvh. %s", ae(), LastSaid[2, string], oe(), Data["AverageDepotTime", number], Data["Name", string]))
                            break
                        
                        case "intransit",
                        pushQueue(LastSpoke, format("K%sre kunde\nPakken %s forlod vores depot kl. %s, og er allerede p%s vej til %s. Leveringstiden tager normalt %d min. Vi gl%sder os til at levere den!\n\nMvh. %s", ae(), LastSaid[2, string], Parcel["LastSeen", string], aa(), Parcel["MailboxFormat", string], Employees[Parcel["DriverSteamID", string], table]["AverageDeliveryTime", number], ae(), Data["Name", string]))
                            
                            break
                            
                        case "delivered",
                            pushQueue(LastSpoke, format("K%sre kunde\nPakken %s blev leveret kl. %s af vores chauff%sr %s til %s.\n\nMvh. %s", ae(), LastSaid[2, string], Parcel["LastSeen", string], oe(), Parcel["DriverName", string], Parcel["MailboxFormat", string], Data["Name", string]))
                            break
                    }
                }
                
                else{
                    pushQueue(LastSpoke, format("K%sre kunde\nDet indtastede pakkenummer eksistere ikke. Tjek om du evt. skulle have tastet forkert.\n\nMvh. %s", ae(), Data["Name", string]))
                }
        }
    }
}

 

Spoiler

@name PostNord E2 - Helper
@inputs DeliveryTruck:entity
@persist [Data, Depot]:table CompanyID:string

if(first()){
    dsSetScope(0)
    dsJoinGroup("PostNord")
    
    function printLayout(Text:string){
        printColor(vec(0, 160, 214), "PostNord - ", vec(255), Text)
    }
    
    DeliveryCompanys = getDeliveryCompanyIDs()
    
    foreach(K, V:string = DeliveryCompanys){
        DeliveryCompany = getDeliveryCompany(V)

        if(DeliveryCompany["OwnerEntity", entity] == owner()){
            CompanyID = V
        }
    }

    timer("check.parcelDelivered", 50)
    timer("check.depot", 2000)
    timer("check.prices", 30000)
}

if(clk(clkName())){
    switch(clkName()){
        case "check.parcelDelivered",
            Employees = getMailEmployees()
            Parcels = array()
            Drivers = array()
            
            foreach(K, V:entity = Employees){
                if(V:inVehicle()){
                    continue
                }
                
                Ent = V:aimEntity()
                
                if(!Ent:isParcel() ?: Data:exists(Ent:getParcelId()) ?: V:pos():distance(Ent:getParcelDestination():pos()) > 750){
                    continue
                }
                
                Data[Ent:getParcelId(), number] = 1
                Drivers:pushEntity(V)
                Parcels:pushEntity(Ent)
            }
            
            if(Parcels:count()){
                dsSend("parcelDelivered", "PostNord", table(Drivers, Parcels))
            }
            
            timer("check.parcelDelivered", 500)
            break
        
        case "check.depot",
            OldDepot = Depot:clone()
            Depot = getParcelsInDepot()
            
            if(OldDepot[1, table]["ParcelID", string] == Depot[1, table]["ParcelID", string] & OldDepot[Depot:count(), table]["ParcelID", string] == Depot[OldDepot:count(), table]["ParcelID", string]){
            }
            
            else {
                print("Something has changed in the depot!")
                dsSend("newParcel", "PostNord", Depot)
            }
            
            timer("check.depot", 2500)
            break
        
        case "check.prices",
            DeliveryCompanys = getDeliveryCompanyIDs()
            Company = getDeliveryCompany(CompanyID)
            CompanyPrice = Company["Prices", table]["FromPerson", number] + Company["Prices", table]["FromWeb", number] + Company["Prices", table]["ToHouse", number] + Company["Prices", table]["ToBox", number]
            
            if(DeliveryCompanys:count() == 1 & CompanyPrice != 4000){
                printLayout("TIP: Du har i " + oe() + "jeblikket ingen konkurrenter. Overvej at h" + ae() + "ve dine priser.")
                exit()
            }
            
            BestPrice = 0
            OfferPrice = 0
            
            foreach(K, V:string = DeliveryCompanys){
                CompanyPrices = getDeliveryCompany(V)["Prices", table]
                OfferPrice = CompanyPrices["FromPerson", number] + CompanyPrices["FromWeb", number] + CompanyPrices["ToHouse", number] + CompanyPrices["ToBox", number]
                    
                if(BestPrice > OfferPrice){
                    BestPrice = OfferPrice
                }
            }
                
            if(CompanyPrice > OfferPrice){
                printLayout("TIP: En af dine konkurrenter har lavere priser end dig. Overvej at s" + ae()+ "nke dine priser.")
            }
            
            timer("check.prices", 150000)
    }
}

 

 

postnord_v2.txt postnord_e2_-_helper.txt

Redigeret af DoktorDim
  • Sejt 1
Link til kommentar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gæst
Svar på dette emne...

×   Du har kopieret indhold med formatering.   Fjern formatering

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Tøm editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.