銃skの改善点指摘してほしい

初心者のぼくが初めてまともに書いたskということで30発入りSMGを3発ずつ撃ててリロードもできるskです。一応動きます。 変数の使い方とかマジで色々汚いと思いますが「こう書いたらいいよ」とか温かく教えてください🥲
28 Replies
月猫ch
月猫ch2y ago
こーどいずこ…
ふぁたおくん
on rightclick with wooden hoe:
if name of player's tool is "&8&lSMG &7- &f&l30":
set {ammo.%uuid of player%::smg} to 30
set name of player's tool to "&8&lSMG &7- &f&l%{ammo.%uuid of player%::smg}%"
if name of player's tool is "&8&lSMG &7- &f&l%{ammo.%uuid of player%::smg}%":
if {ammo.%uuid of player%::smg} is more than 2:
loop 3 times:
shoot an arrow at speed 4
execute player command "/playsound minecraft:entity.firework.blast master @p ~ ~ ~ 1 2"
add -1 to {ammo.%uuid of player%::smg}
set name of player's tool to "&8&lSMG &7- &f&l%{ammo.%uuid of player%::smg}%"
wait 2 ticks
else:
shoot an arrow at speed 4
on drop:
if event-item is a wooden hoe:
cancel event
if {ammo.%uuid of player%::smg} is less than 30:
if {reload.%uuid of player%::smg} is not true:
set {reload.%uuid of player%::smg} to true
execute player command "/playsound minecraft:block.iron_door.open master @p ~ ~ ~ 1 2"
wait 3 seconds
set {ammo.%uuid of player%::smg} to 30
set name of player's tool to "&8&lSMG &7- &f&l%{ammo.%uuid of player%::smg}%"
execute player command "/playsound minecraft:block.iron_door.close master @p ~ ~ ~ 1 2"
set {reload.%uuid of player%::smg} to false
on rightclick with gunpowder:
execute player command "/say %{ammo.%uuid of player%::smg}%"
on rightclick with wooden hoe:
if name of player's tool is "&8&lSMG &7- &f&l30":
set {ammo.%uuid of player%::smg} to 30
set name of player's tool to "&8&lSMG &7- &f&l%{ammo.%uuid of player%::smg}%"
if name of player's tool is "&8&lSMG &7- &f&l%{ammo.%uuid of player%::smg}%":
if {ammo.%uuid of player%::smg} is more than 2:
loop 3 times:
shoot an arrow at speed 4
execute player command "/playsound minecraft:entity.firework.blast master @p ~ ~ ~ 1 2"
add -1 to {ammo.%uuid of player%::smg}
set name of player's tool to "&8&lSMG &7- &f&l%{ammo.%uuid of player%::smg}%"
wait 2 ticks
else:
shoot an arrow at speed 4
on drop:
if event-item is a wooden hoe:
cancel event
if {ammo.%uuid of player%::smg} is less than 30:
if {reload.%uuid of player%::smg} is not true:
set {reload.%uuid of player%::smg} to true
execute player command "/playsound minecraft:block.iron_door.open master @p ~ ~ ~ 1 2"
wait 3 seconds
set {ammo.%uuid of player%::smg} to 30
set name of player's tool to "&8&lSMG &7- &f&l%{ammo.%uuid of player%::smg}%"
execute player command "/playsound minecraft:block.iron_door.close master @p ~ ~ ~ 1 2"
set {reload.%uuid of player%::smg} to false
on rightclick with gunpowder:
execute player command "/say %{ammo.%uuid of player%::smg}%"
質問書くだけ書いてコード出すの忘れてたことにベッドの中で気づいてPCつけました😅 おやすみ💤
yukkina
yukkina2y ago
playsoundも構文あるよ 最後のsayのくだりは、全員に弾数表示されるくない? 自分に弾数表示させたいなら send "%{ammo以下略}%"がよき
ふぁたおくん
sayのやつはその場で適当に確認したいだけだった playみたいな構文があったけどskRayFallのやつで、入れようと思ったんだけどなんかなかったからとりあえすexecuteにした 余裕でplay soundあったわ使います
月猫ch
月猫ch2y ago
ちなこれ右クリ連打するとどうなります?
yukkina
yukkina2y ago
その場で確認は基本sendでやろう
月猫ch
月猫ch2y ago
broadcastわい憤死
yukkina
yukkina2y ago
on pickupとか、sendだとモニターできないのもあるから broadcastはあり
chinatukano
chinatukano2y ago
on rightclick with wooden hoe:
if name of player's tool contain "&8&lSMG":
if {ammo.%uuid of player%::smg} is >= 2:
loop 3 times:
shoot an arrow at speed 4
play sound "entity.firework.blast" with volume 1 and pitch 2 at player
remove 1 from {ammo.%uuid of player%::smg}
wait 2 ticks
else:
reload(player, "smg")
set name of player's tool to "&8&lSMG &7- &f&l%{ammo.%uuid of player%::smg}%"
else:
shoot an arrow at speed 4

on rightclick with gunpowder:
send "%{ammo.%uuid of player%::smg}"

on drop:
if event-item is a wooden hoe:
cancel event
if name of event-item contain "&8&lSMG":
if {ammo.%uuid of player%::smg} < 30:
reload(player, "smg")


function reload(p: player, t: text):
if {reload.%{_uuid}%::%{_t}%} is true:
send "&cReloading!"
else:
set {_uuid} to uuid of {_p}
send "&cReloading..." to {_p}
play sound "block.iron_door.open" with volume 1 and pitch 2 at player
set {reload.%{_uuid}%::%{_t}%} to true
wait 3 seconds
if {_t} is "smg":
set {ammo.%{_uuid}%::smg} to 30
set name of {_p}'s tool to "&8&lSMG &7- &f&l%{ammo.%{_uuid}%::smg}%"
send "&aReloaded!" to {_p}
play sound "block.iron_door.close" with volume 1 and pitch 2 at player
set {reload.%{_uuid}%::%{_t}%} to false
on rightclick with wooden hoe:
if name of player's tool contain "&8&lSMG":
if {ammo.%uuid of player%::smg} is >= 2:
loop 3 times:
shoot an arrow at speed 4
play sound "entity.firework.blast" with volume 1 and pitch 2 at player
remove 1 from {ammo.%uuid of player%::smg}
wait 2 ticks
else:
reload(player, "smg")
set name of player's tool to "&8&lSMG &7- &f&l%{ammo.%uuid of player%::smg}%"
else:
shoot an arrow at speed 4

on rightclick with gunpowder:
send "%{ammo.%uuid of player%::smg}"

on drop:
if event-item is a wooden hoe:
cancel event
if name of event-item contain "&8&lSMG":
if {ammo.%uuid of player%::smg} < 30:
reload(player, "smg")


function reload(p: player, t: text):
if {reload.%{_uuid}%::%{_t}%} is true:
send "&cReloading!"
else:
set {_uuid} to uuid of {_p}
send "&cReloading..." to {_p}
play sound "block.iron_door.open" with volume 1 and pitch 2 at player
set {reload.%{_uuid}%::%{_t}%} to true
wait 3 seconds
if {_t} is "smg":
set {ammo.%{_uuid}%::smg} to 30
set name of {_p}'s tool to "&8&lSMG &7- &f&l%{ammo.%{_uuid}%::smg}%"
send "&aReloaded!" to {_p}
play sound "block.iron_door.close" with volume 1 and pitch 2 at player
set {reload.%{_uuid}%::%{_t}%} to false
yukkina
yukkina2y ago
ただ、PR民にありがちな、稼働中実環境でやる時に全員に表示されるから……
月猫ch
月猫ch2y ago
あぁー… やっぱ気にするのか…
chinatukano
chinatukano2y ago
思ったけどreloadの時にset name of player's toolだと持ち替えしたら別のアイテムに名前ついちゃうから変数にアイテム入れてからのほうがいいかもね
月猫ch
月猫ch2y ago
あと話戻るけど 1番最初のコード SMGとか各銃を関数にした方が間違い起きなくていいかも function gunSMG() :: item: みたいな感じで
chinatukano
chinatukano2y ago
particle使った銃のskript落としておきます ヘッドショット胴体とかも判定してくれるのでご参考に
月猫ch
月猫ch2y ago
正直銃作るならCS CSPとskRageのセットで良くね
chinatukano
chinatukano2y ago
skriptは大体自己満じゃない?
月猫ch
月猫ch2y ago
否めん ただ最終的に鯖で使うことを視野に入れてるなら ほかPLの利用も考えた方がいいかなって そうじゃないなら俺の言うたことは蛇足なりけり
ふぁたおくん
しょうみCSとかに勝てることはないと思うけど、sk勉強するってことで作るもの考えたら銃しか思いつかなかった functionがまだあんまり理解できてないかも
月猫ch
月猫ch2y ago
function もとい『関数』は 複数処理や計算にまとめて名前をつけたもの 同じ処理を色んなところで繰り返す時に 自分で決めた関数の名前を指定するだけでその処理を行える
ふぁたおくん
function reload(p: player, t: text):
if {reload.%{_uuid}%::%{_t}%} is true:
send "&cReloading!"
function reload(p: player, t: text):
if {reload.%{_uuid}%::%{_t}%} is true:
send "&cReloading!"
リスト変数を{_t}にすることで各武器にも対応できるようになってるってことかな?
chinatukano
chinatukano2y ago
reload(player, "smg") {_t}の中には"smg"が入ってる 武器を追加するとき
on drop:
if event-item is a wooden hoe:
cancel event
if name of event-item contain "&8&lSMG":
if {ammo.%uuid of player%::smg} < 30:
reload(player, "smg")
if name of event-item contain "&8&lAK":
if {ammo.%uuid of player%::ak} < 30:
reload(player, "ak")
on drop:
if event-item is a wooden hoe:
cancel event
if name of event-item contain "&8&lSMG":
if {ammo.%uuid of player%::smg} < 30:
reload(player, "smg")
if name of event-item contain "&8&lAK":
if {ammo.%uuid of player%::ak} < 30:
reload(player, "ak")
みたいにすればやりやすい
ふぁたおくん
理解できた ありがとうございます😁 function内でsendするときにプレイヤーが検出できませんみたいなエラー出るんですけど、どうしたらいいですか? to {_p}つければええか
mirageeeeeeeeeeeeeeeeeeeeeeeeeee
Skriptに限らずプログラムを組む時は、できるだけ抽象化する事を考えるといい 例えば銃の弾をリロードする関数を作る時、reloadSMGってのを作っちゃうと、今後reloadARとかreloadSGとかも作る必要が出てきちゃう そこでこれみたいに種類問わず銃なら何でもリロード出来る関数を作って、関数を使う時に「因みにこの銃の種類はSMGです」っていう情報を後付けするようにすると、無駄な関数が増えないしコードも綺麗になるのでオススメ
tanoKun
tanoKun2y ago
なるべくコードを共通にするのもいい
chinatukano
chinatukano2y ago
きれいにするなら武器情報を変数に全部入れちゃうのが一番
{guns::*}
{gun::smg::ammo}
{guns::*}
{gun::smg::ammo}
tanoKun
tanoKun2y ago
ymlでまとめれるようにするのもありだよ
月猫ch
月猫ch2y ago
ってかymlで作れるほうが便利じゃね
tanoKun
tanoKun2y ago
まぁ PRだったらむりだけど 普通のサバでyml skript 使うぐらいなら ぐちゃぐちゃになる気がする
Want results from more Discord servers?
Add your server