If Else/ Gain Item... via script call?

hello, can someone help me to write proper scripts for those below:
x = random(1-10)
if x == 5
gain item x
else if x == 10
remove 2 item x

n = item x's name
w = weapon x's name
for(x=1;x<=10;++x)
{
if x mod 2 == 0 {show message "abc"}
}
play bgm "Airship"
stop bgm

array = [1,3,4,5]
if array.contains(x) {set selfswitches A = true; set switch 111 = true;}

Thank you very much
Code:
x = rand(10) + 1
if x == 5
  $game_party.gain_item($data_library[x], amount)
elsif x == 10
  $game_party.lose_item($data_library[x], 2)
end

n = $data_items[x].name
w = $data_weapons[x].name
(1..10).each do |loop|
 if loop % 2 == 0
  $game_message.add("text")
 end
end
Audio.bgm_play('path/file', volume, pitch)
Audio.bgm_fade(0)

array = [1,2,3,4,5]
if array.include?(x)
  $game_selfswitches[[$game_map.map_id, event_id, "A"]] = true
  $game_switches[111] = true
end

.........ish.
give or take an instruction.
self switches are event-based, event_id refers to the map event (current map, or other map) which self-switch is being changed.
if the event is in another map, "$game_map.map_id" would be that other id.

$data_library refers to either _items[], _weapons[] or _armors[], they are separate databases.
@gstv87 thank you very much 🙂 that help me a lots

Original thread: https://forums.rpgmakerweb.com/threads/if-else-gain-item-via-script-call.92436/