- Katılım
- 29 Haziran 2019
- Mesajlar
- 62
- Elmaslar
- 24
- Puan
- 13.720
- Yaş
- 26
- Konum
- Ankara
- Minecraft
- ByLien
Discord:
ByLien#4140
ByLien#4140
kingOf0!#4055
function impCoin(p: player, n: number, a: text):
if {_a} is "add":
set {_v} to (yaml value "players.%{_p}%" from "players")
set (yaml value "players.%{_p}%" from "players") to {_n} + {_v}
if {_a} is "remove":
set {_v} to (yaml value "players.%{_p}%" from "players")
set (yaml value "players.%{_p}%" from "players") to {_v} - {_n}
if {_a} is "set":
set (yaml value "players.%{_p}%" from "players") to {_n}
save yaml "players"
function impCoin(p: player, n: number, a: text):
if {_a} is "add":
set {_v} to (yaml value "players.%{_p}%" from "players")
set (yaml value "players.%{_p}%" from "players") to {_n} + {_v}
else if {_a} is "remove":
set {_v} to (yaml value "players.%{_p}%" from "players")
set (yaml value "players.%{_p}%" from "players") to {_v} - {_n}
else if {_a} is "set":
set (yaml value "players.%{_p}%" from "players") to {_n}
save yaml "players"
Fhalinkz#6825
Ha yaml kullanmışsın ha variable. ikiside tamamen aynı. yaml'ı sürekli kaydedip sunucuya ani yük bindirdiğinden bunun gibi skriptlerde yaml kullanmak daha kötü.
sanırım else if nasıl çalışır bilmiyorsun. Kısaca anlatacağım:
if, parametre değeri true döndürürse body sinde bulunan kodu çalıştırır.
her if için bu kontrol sağlanır.
else if, için ise bu durum biraz daha farklıdır. eğer kontrollerden birisi true döndürmüşse kalan kontroller atlanır.
kısacası, 3 kontrol yerine 1 kontrol sağlanmış olur. Bu uzun bir kod için epey performans sağlar.
eğer ki else if karışık geldiyse, switch case de kullanabilirsin.
bu yazdığım mesajı "baltalama" veya "kötüleme" olarak algılamaman için ek bir not düşürüyorum. seni baltalamak isteyenler, kendini geliştirmene yarayacak olan kötü yanlarından bahsetmezler, kötü(l)(d)eyip geçerler.
Kod:function impCoin(p: player, n: number, a: text): if {_a} is "add": set {_v} to (yaml value "players.%{_p}%" from "players") set (yaml value "players.%{_p}%" from "players") to {_n} + {_v} if {_a} is "remove": set {_v} to (yaml value "players.%{_p}%" from "players") set (yaml value "players.%{_p}%" from "players") to {_v} - {_n} if {_a} is "set": set (yaml value "players.%{_p}%" from "players") to {_n} save yaml "players"Kod:function impCoin(p: player, n: number, a: text): if {_a} is "add": set {_v} to (yaml value "players.%{_p}%" from "players") set (yaml value "players.%{_p}%" from "players") to {_n} + {_v} else if {_a} is "remove": set {_v} to (yaml value "players.%{_p}%" from "players") set (yaml value "players.%{_p}%" from "players") to {_v} - {_n} else if {_a} is "set": set (yaml value "players.%{_p}%" from "players") to {_n} save yaml "players"
Merlin#5505
Merhaba Türkiye'nin sevgili Minecraft oyuncuları, bugün harika bir coin skripti ile karşınızdayım. Skriptimin adı fCoin.
Skript 1.8 için yapılmıştır. Eğer 1.8 kullanmayıp bu skripti kullanmak istiyorsanız bana discord adresimden ulaşın istediğiniz versiyonu yapıp atayım size.
YAML:items: item1: name: Elmas &2Kılıç coin: 20 slot: 0 ditem: Diamond Sword lore: - "&8&m----------------------" - " " - "&7Büyüler;" - "&8► &7Keskinlik: &210" - "&8► &7Kırılmazlık: &210" - " " - "&8&m----------------------" - " " - "&7Ücret: &2%price%&7 Coin" - " " - "&8&m----------------------" - " " - "&8►&2&nSatın almak için tıkla" - " " item: name: Kılıç item: diamond sword amount: 1 lore: - "Bu skript Fhalinkz tarafından yapılmıştır" - "Bu bir kılıçtır" enchant: - "sharpness 10" - "unbreaking 10" commands: player: - test1 console: - test2
Kod:on load: load yaml "plugins/fCoin/players.yml" as "players" load yaml "plugins/fCoin/market.yml" as "market" if yaml "market" is empty: set yaml value "items.item1.name" from "market" to "xD" set yaml value "items.item1.coin" from "market" to "xD" set yaml value "items.item1.slot" from "market" to 1 set yaml value "items.item1.ditem" from "market" to "xD" add "&6Fiyatı: &a50 Coin" to yaml list "items.item1.lore" from "market" add "bu bir kilic" to yaml list "items.item1.item.lore" from "market" add "sharpness 5" to yaml list "items.item1.item.enchant" from "market" add "unbreaking 5" to yaml list "items.item1.item.enchant" from "market" add "test1" to yaml list "items.item1.item.commands.player" from "market" add "test2" to yaml list "items.item1.item.commands.console" from "market" save yaml "market" loop yaml nodes with keys "items" from "market": if yaml value "items.%loop-value%.coin" from "market" isn't set: send "&8[&afCoin&8] &4Yaml Hatası! &c""plugins/fCoin/market.yml"" dosyasında hata bulundu. &6Coin&4'e değer verilmemiş." to console on inventory close: set {_n} to impGetCoin(player) if {_n} is 0: delete yaml value "players.%player%" from "players" command /coin [<text>] [<player>] [<number>]: trigger: if arg-1 isn't set: send "&6Coin Miktarın: &f%impGetCoin(player) otherwise 0%" to player if arg-1 is "gönder" or "gonder": if arg-2 is set: if arg-3 is set: if impGetCoin(player) is greater than or equal to arg-3: impCoin(player, arg-3, "remove") impCoin(arg-2, arg-3, "add") send "&6%player% &7adlı oyuncu sana &6%arg-3% &7adet coin gönderdi." to arg-2 send "&6%arg-2% &7adlı oyuncuya &6%arg-3% &7adet coin gönderdin." to player save yaml "players" if arg-1 is "market": impCoinMarket(player) command /fcoin [<text>] [<offline player>] [<number>]: permission: coin.admin trigger: if arg-1 isn't set: send "&6/fcoin &fgonder [player] [sayı]" send "&6/fcoin &fyap [player] [sayı]" send "&6/fcoin &feksilt [player] [sayı]" send "&6/fcoin &fogren [player]" if arg-1 is "gonder" or "gönder": impCoin(arg-2, arg-3, "add") send "&6%arg-2% &7adlı oyuncuya &6%arg-3% &7adet coin gönderildi." if arg-1 is "yap": impCoin(arg-2, arg-3, "set") send "&6%arg-2% &7adlı oyuncunun coini &6%arg-3% &7olarak ayarlandı." if arg-1 is "eksilt": impCoin(arg-2, arg-3, "remove") send "&6%arg-2% &7adlı oyuncudan &6%arg-3% &7adet coin silindi." if arg-1 is "ogren" or "öğren": send "&6%arg-2% &7adlı oyuncunun coin miktarı &6%impGetCoin(arg-2) otherwise 0%." function impCoin(p: player, n: number, a: text): if {_a} is "add": set {_v} to (yaml value "players.%{_p}%" from "players") set (yaml value "players.%{_p}%" from "players") to {_n} + {_v} if {_a} is "remove": set {_v} to (yaml value "players.%{_p}%" from "players") set (yaml value "players.%{_p}%" from "players") to {_v} - {_n} if {_a} is "set": set (yaml value "players.%{_p}%" from "players") to {_n} save yaml "players" function impGetCoin(p: player) :: number: set {_coin} to (yaml value "players.%{_p}%" from "players") otherwise 0 return {_coin} function impCoinMarket(player: player): open virtual chest with size 6 named "&6Coin &8>> &aMarket" to {_player} make gui slot (integers between 0 and 53) of {_player} with black stained glass pane named " " to nothing loop yaml nodes with keys "items" from "market": delete {_s::*} set {_s::slot} to yaml value "items.%loop-value%.slot" from "market" set {_s::ditem} to yaml value "items.%loop-value%.ditem" from "market" parsed as item type set {_s::lore::*} to yaml list "items.%loop-value%.lore" from "market" set {_s::name} to yaml value "items.%loop-value%.name" from "market" set {_coin} to yaml value "items.%loop-value%.coin" from "market" set {_item::name} to yaml value "items.%loop-value%.item.name" from "market" set {_item::item} to yaml value "items.%loop-value%.item.item" from "market" parsed as item type set {_item::lore::*} to yaml list "items.%loop-value%.item.lore" from "market" set {_item::amount} to yaml value "items.%loop-value%.item.amount" from "market" set {_item::enchant::*} to yaml list "items.%loop-value%.item.enchant" from "market" loop {_item::enchant::*}: set {_item::enchant::%loop-value-2%} to loop-value-2 parsed as enchantment type set {_item::player-commands::*} to yaml list "items.%loop-value%.item.commands.player" from "market" set {_item::console-commands::*} to yaml list "items.%loop-value%.item.commands.console" from "market" replace "%%price%%" with "%{_coin}%" in {_s::lore::*} replace "%%player%%" with "%{_player}%" in {_item::console-commands::*} make gui slot {_s::slot} of {_player} with ({_s::ditem} named colored {_s::name} with lore colored join {_s::lore::*} with "||") to close: if impGetCoin({_player}) is greater than or equal to {_coin}: impCoin({_player}, {_coin}, "remove") loop {_item::player-commands::*}: execute player command {_item::player-commands::*} stop loop loop {_item::console-commands::*}: execute console command {_item::console-commands::*} stop loop if {_item::enchant::*} is set: set {_item-} to ({_item::item} named colored {_item::name} with lore colored join {_item::lore::*} with "||") loop {_item::enchant::*}: enchant {_item-} with {_item::enchant::%loop-value-2%} give {_item::amount} of {_item-} to {_player} else: give {_item::amount} of ({_item::item} named colored {_item::name} with lore colored join {_item::lore::*} with "||") to {_player} save yaml "players" else: send "&7Bu eşyayı almak için yeterli miktarda &6Coin&7'e sahip değilsin." to {_player} on break: if event-block is obsidian block: impCoin(player, {_level}, "add")
Notlar:
- 1 obsidian kırmak 1 adet coin kazandırır.
- Markete maksimum 54 adet eşya koyabilirsiniz.
- Bütün oyuncuların coin bilgileri "plugins/fCoin/players.yml" içerisinde bulunur.
- Admin komutlarını kullanmak için "coin.admin" izni gerekmektedir.
Admin komutları:
- fcoin gönder [oyuncu] [miktar]
- fcoin yap [oyuncu] [miktar]
- fcoin eksilt [oyuncu] [miktar]
- fcoin öğren [oyuncu] [miktar]
Oyuncu komutları:
- coin
- coin gönder [oyuncu] [miktar]
- coin market
kingOf0!#4055
Değerli yorumun için teşekkür ederim. Else if konusunda çok haklısın. Hep kullanmayı unutuyorum daha dikkatli olacağım artık. Ayrıca yaml kullanmak variable kullanmaktan daha performanslı oluyor. Bunu @Kardan İsmail denemişti hatta. Eğer hala bilgisayarında duruyorsa ekran görüntüleri buraya atabilir.
for (String name : this.file.getAll(event)) {
if (!SkriptYaml.YAML_STORE.containsKey(name))
continue;
YAMLProcessor yaml = SkriptYaml.YAML_STORE.get(name);
if (yamlIndent != null)
yaml.setIndent(this.yamlIndent.getSingle(event).intValue());
yaml.save(this.mark == 1 ? false : true);
}
public boolean save(boolean extraLines) {
OutputStream stream = null;
File parent = file.getParentFile();
if (parent != null) {
parent.mkdirs();
}
try {
stream = getOutputStream();
if (stream == null)
return false;
OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8");
if (header != null) {
writer.append(header);
writer.append(LINE_BREAK);
if (extraHeaderLine)
writer.append(LINE_BREAK);
}
String firstKey = "";
if (!root.keySet().isEmpty())
firstKey = root.keySet().toArray(new String[root.size()])[0];
if (comments.isEmpty() || format != YAMLFormat.EXTENDED) {
if (extraLines && header != null)
writer.append(LINE_BREAK);
for (Entry<String, Object> entry : root.entrySet()) {
if (extraLines && !entry.getKey().equals(firstKey))
writer.append(LINE_BREAK);
yaml.dump(Collections.singletonMap(entry.getKey(), serialize(entry.getValue())), writer);
}
// yaml.dump(root, writer);
} else {
if (extraLines && header != null)
writer.append(LINE_BREAK);
// Iterate over each root-level property and dump
for (Entry<String, Object> entry : root.entrySet()) {
// make an extra line between nodes if true
if (extraLines && !entry.getKey().equals(firstKey))
writer.append(LINE_BREAK);
// Output comment, if present
YAMLComment comment = comments.get(entry.getKey());
if (comment != null) {
if (comment.hasExtraLine())
writer.append(LINE_BREAK);
writer.append(comment.getComment());
writer.append(LINE_BREAK);
}
// Dump property
yaml.dump(Collections.singletonMap(entry.getKey(), serialize(entry.getValue())), writer);
}
}
return true;
} catch (IOException ignored) {
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException ignored) {
}
}
return false;
Kardan İsmail#0130
krdş skript-yaml async krdşEkli dosyayı görüntüle 79503
Böyle bir dünya kaydedilirken alınan tps gerçekten çok şaşırtıcı. 1 tick içerisinde 20mb veri yazmaya çalışan sunucu bu işlem, SYNC olduğundan zorlanmakta. Yani, 1 tick içerisinde bir şeyleri **bir dosyaya yazdırmak** sunucuyu zorlamakta.
Skript yaml, save yaml kaynak:Değerli ziyaretçimiz, içeriği görebilmek için şimdi giriş yapın veya kayıt olun.
Kod:for (String name : this.file.getAll(event)) { if (!SkriptYaml.YAML_STORE.containsKey(name)) continue; YAMLProcessor yaml = SkriptYaml.YAML_STORE.get(name); if (yamlIndent != null) yaml.setIndent(this.yamlIndent.getSingle(event).intValue()); yaml.save(this.mark == 1 ? false : true); }
YamlProccessor#save
Kod:public boolean save(boolean extraLines) { OutputStream stream = null; File parent = file.getParentFile(); if (parent != null) { parent.mkdirs(); } try { stream = getOutputStream(); if (stream == null) return false; OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8"); if (header != null) { writer.append(header); writer.append(LINE_BREAK); if (extraHeaderLine) writer.append(LINE_BREAK); } String firstKey = ""; if (!root.keySet().isEmpty()) firstKey = root.keySet().toArray(new String[root.size()])[0]; if (comments.isEmpty() || format != YAMLFormat.EXTENDED) { if (extraLines && header != null) writer.append(LINE_BREAK); for (Entry<String, Object> entry : root.entrySet()) { if (extraLines && !entry.getKey().equals(firstKey)) writer.append(LINE_BREAK); yaml.dump(Collections.singletonMap(entry.getKey(), serialize(entry.getValue())), writer); } // yaml.dump(root, writer); } else { if (extraLines && header != null) writer.append(LINE_BREAK); // Iterate over each root-level property and dump for (Entry<String, Object> entry : root.entrySet()) { // make an extra line between nodes if true if (extraLines && !entry.getKey().equals(firstKey)) writer.append(LINE_BREAK); // Output comment, if present YAMLComment comment = comments.get(entry.getKey()); if (comment != null) { if (comment.hasExtraLine()) writer.append(LINE_BREAK); writer.append(comment.getComment()); writer.append(LINE_BREAK); } // Dump property yaml.dump(Collections.singletonMap(entry.getKey(), serialize(entry.getValue())), writer); } } return true; } catch (IOException ignored) { } finally { try { if (stream != null) { stream.close(); } } catch (IOException ignored) { } } return false;
bu kod, dünyanın kaydedilmesinden bile daha zahmetli şeyler yapıyor. bukkit apisi kullanılarak yazılsaydı daha sağlıklı olabilirdi lakin OutputStream kullanılmış...
böyle bir kodu her, oyuncuya coin verildiğinde, alındığında vs çalıştırmak sunucuyu zorlamaktadır.
bu yazdıklarım herhangi bir skript için geçerli, sadece bu skripte değil.
yaml kullanmak güzel ve hoş lakin her dakika save yaml kullanılmasına neden olunacak bir skript ise, kullanılması hiç iyi değildir...
nanodn#9838
Ekli dosyayı görüntüle 79503
Böyle bir dünya kaydedilirken alınan tps gerçekten çok şaşırtıcı. 1 tick içerisinde 20mb veri yazmaya çalışan sunucu bu işlem, SYNC olduğundan zorlanmakta. Yani, 1 tick içerisinde bir şeyleri **bir dosyaya yazdırmak** sunucuyu zorlamakta.
Skript yaml, save yaml kaynak:Değerli ziyaretçimiz, içeriği görebilmek için şimdi giriş yapın veya kayıt olun.
Kod:for (String name : this.file.getAll(event)) { if (!SkriptYaml.YAML_STORE.containsKey(name)) continue; YAMLProcessor yaml = SkriptYaml.YAML_STORE.get(name); if (yamlIndent != null) yaml.setIndent(this.yamlIndent.getSingle(event).intValue()); yaml.save(this.mark == 1 ? false : true); }
YamlProccessor#save
Kod:public boolean save(boolean extraLines) { OutputStream stream = null; File parent = file.getParentFile(); if (parent != null) { parent.mkdirs(); } try { stream = getOutputStream(); if (stream == null) return false; OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8"); if (header != null) { writer.append(header); writer.append(LINE_BREAK); if (extraHeaderLine) writer.append(LINE_BREAK); } String firstKey = ""; if (!root.keySet().isEmpty()) firstKey = root.keySet().toArray(new String[root.size()])[0]; if (comments.isEmpty() || format != YAMLFormat.EXTENDED) { if (extraLines && header != null) writer.append(LINE_BREAK); for (Entry<String, Object> entry : root.entrySet()) { if (extraLines && !entry.getKey().equals(firstKey)) writer.append(LINE_BREAK); yaml.dump(Collections.singletonMap(entry.getKey(), serialize(entry.getValue())), writer); } // yaml.dump(root, writer); } else { if (extraLines && header != null) writer.append(LINE_BREAK); // Iterate over each root-level property and dump for (Entry<String, Object> entry : root.entrySet()) { // make an extra line between nodes if true if (extraLines && !entry.getKey().equals(firstKey)) writer.append(LINE_BREAK); // Output comment, if present YAMLComment comment = comments.get(entry.getKey()); if (comment != null) { if (comment.hasExtraLine()) writer.append(LINE_BREAK); writer.append(comment.getComment()); writer.append(LINE_BREAK); } // Dump property yaml.dump(Collections.singletonMap(entry.getKey(), serialize(entry.getValue())), writer); } } return true; } catch (IOException ignored) { } finally { try { if (stream != null) { stream.close(); } } catch (IOException ignored) { } } return false;
bu kod, dünyanın kaydedilmesinden bile daha zahmetli şeyler yapıyor. bukkit apisi kullanılarak yazılsaydı daha sağlıklı olabilirdi lakin OutputStream kullanılmış...
böyle bir kodu her, oyuncuya coin verildiğinde, alındığında vs çalıştırmak sunucuyu zorlamaktadır.
bu yazdıklarım herhangi bir skript için geçerli, sadece bu skripte değil.
yaml kullanmak güzel ve hoş lakin her dakika save yaml kullanılmasına neden olunacak bir skript ise, kullanılması hiç iyi değildir...
for (String name : this.file.getAll(event)) {
if (!SkriptYaml.YAML_STORE.containsKey(name))
continue;
YAMLProcessor yaml = SkriptYaml.YAML_STORE.get(name);
if (yamlIndent != null)
yaml.setIndent(this.yamlIndent.getSingle(event).intValue());
yaml.save(this.mark == 1 ? false : true);
}
for loopuna alınıyor, şu an kullanılan String'e name diyoruz.SkriptYaml.YAML_STORE) name girdisi bulunmuyorsa;for loopuna devam et.name girdisinin değeri yaml değişkeninin değeri olarak belirleniyor.yamlIndent değişkeni boş değilse; (Bu değişken init method'unda ayarlanıyor.)YAMLProcessor) setIndent methoduyla YAML boşlukları yamlIndent değişkeninin tam sayı değerine atanıyor.async çalışır. Sunucunun ana işlemini etkilemez. Kasma ve donma yapmayacaktır.Yusuf Emir ~ (bicker) #3303
Fhalinkz#6825
çoğu coin sisteminin arasında en iyilerinden başarılar dilerim gelistirilebilir
Kardan İsmail#0130
UmutDmr#1930
Büyük bir topluluğun parçası ol, etkinliklere katıl ve özel hediyeler kazanma şansı yakala!