JeroenoBoy / Grow-Scripts

The Skript files for the populair farming playerserver from 2020
1 stars 1 forks source link

If else chain can be used to reduce lag #1

Open DebitCardz opened 3 years ago

DebitCardz commented 3 years ago

In the following code you can use an "if else" chain to reduce lag on the server, it would be more efficient than checking that massive if block each time.

Another optimization is putting the item's lore into a variable so the server doesn't have to read the tools lore 10 times, this can be improved upon very easily.

on block place:
    if player's tool = wheat seeds:
        if lore of player's tool = "&f&oPlant your very own Daisy||||%{-ccrops::prefix}%&fDaisy":
            set {ccrop::placedCrops::%location of event-block%::crop} to "Daisy"
            set block at event-block to melon stem
        if lore of player's tool = "&f&oA nice red flower||||%{-ccrops::prefix}%&fPoppy":
            set {ccrop::placedCrops::%location of event-block%::crop} to "red_flower"
            set block at event-block to melon stem
        if lore of player's tool = "&f&oMake a wish||||%{-ccrops::prefix}%&fDandelion":
            set {ccrop::placedCrops::%location of event-block%::crop} to "dandelion"
            set block at event-block to melon stem
        if lore of player's tool = "&f&oThe Beutiful blue flower||||%{-ccrops::prefix}%&fBlue Orchid":
            set {ccrop::placedCrops::%location of event-block%::crop} to "blue_orchid"
            set block at event-block to melon stem
        if lore of player's tool = "&f&oA purple flower for patience||||%{-ccrops::prefix}%&fAllium":
            set {ccrop::placedCrops::%location of event-block%::crop} to "allium"
            set block at event-block to melon stem
        if lore of player's tool = "&f&oPlant your very own Daisy||||%{-ccrops::prefix}%&fAzure Bluet":
            set {ccrop::placedCrops::%location of event-block%::crop} to "azure_bluet"
            set block at event-block to melon stem
        if lore of player's tool = "&f&oThe flower of Love||||%{-ccrops::prefix}%&fRed Tulip":
            set {ccrop::placedCrops::%location of event-block%::crop} to "red_tulip"
            set block at event-block to melon stem
        if lore of player's tool = "&f&oA reminder of The Netherlands||||%{-ccrops::prefix}%&fOrange Tulip":
            set {ccrop::placedCrops::%location of event-block%::crop} to "orange_tulip"
            set block at event-block to melon stem
        if lore of player's tool = "&f&oA tulip that symnolizes||&f&oyour Purity||||%{-ccrops::prefix}%&fWhite Tulip":
            set {ccrop::placedCrops::%location of event-block%::crop} to "white_tulip"
            set block at event-block to melon stem
        if lore of player's tool = "&f&oA beutiful Pink Tulip||||%{-ccrops::prefix}%&fPink Tulip":
            set {ccrop::placedCrops::%location of event-block%::crop} to "pink_tulip"
            set block at event-block to melon stem
iOussama commented 2 years ago

yes