General Thread for OM Code

dhelmise

banend doosre
is a Site Content Manageris a Battle Simulator Administratoris a Top Social Media Contributoris a Community Leaderis a Programmeris a Community Contributoris a Top Contributoris a Top Smogon Media Contributoris a Top Dedicated Tournament Hostis a Smogon Discord Contributor Alumnus
Social Media Head
The Negative Metagame Code

config/formats.js
Code:
    {
        name: "The Negative Metagame",
        section: "Other Metagames",

        mod: 'thenegativemetagame',
        ruleset: ['Pokemon', 'Swagger Clause', 'Team Preview', 'Evasion Moves Clause', 'Sleep Clause Mod', 'Species Clause', 'Nickname Clause', 'Moody Clause', 'OHKO Clause', 'Endless Battle Clause', 'HP Percentage Mod', 'Cancel Mod'],
        banlist: ['DeepSeaTooth', 'DeepSeaScale', 'Eviolite', 'Huge Power', 'Light Ball', 'Pure Power', 'Smeargle', 'Thick Club', 'Illegal']
    },
mods/thenegativemetagame/scripts.js
Code:
exports.BattleScripts = {
    init: function () {
        for (var species in this.data.Pokedex) {
            for (var stat in this.data.Pokedex[species].baseStats) {
                var baseStat = this.data.Pokedex[species].baseStats[stat];
                if (baseStat >= 146) {
                    baseStat = 145;
                }
                this.modData('Pokedex', species).baseStats[stat] = 150 - baseStat;
            }
        }

        for (var i in this.data.FormatsData) {
            this.modData('FormatsData', i).unreleasedHidden = false;
        }
    }
};
 
Last edited:

Pikachuun

the entire waruda machine
config/formats.js
Code:
    {
        name: "Hawluchange",
        section: "Other Metagames",
     
        ruleset: ['Pokemon', 'Standard', 'Team Preview'],
        banlist: ['Uber', 'Soul Dew', 'Gengarite', 'Kangaskhanite', 'Lucarionite', 'Mawilite', 'Salamencite'],
        mod: "hawluchange",
        onModifyMove: function (move, pokemon) {
            if (move.id === 'flyingpress') {
                move.type = pokemon.types[0];
                if (pokemon.types[1]) {
                    move.onEffectiveness = function(typeMod, type, move) {
                        return typeMod + this.getEffectiveness(pokemon.types[1], type);
                    }
                } else {
                    move.onEffectiveness = function(typeMod, type, move) {
                        return typeMod;
                    }
                }
            }
        }
    },
mods/hawluchange/scripts.js
Code:
exports.BattleScripts = {
    init: function () {
        for (var i in this.data.Learnsets) {
            this.modData('Learnsets', i).learnset.flyingpress = ['6L1'];
        }
    }
};
 
Last edited:

Snaquaza

KACAW
is a Community Contributor Alumnusis a Smogon Media Contributor Alumnusis a Battle Simulator Moderator Alumnus
Fixed owo and updated the link: http://pastebin.com/DARQdU7x
(Also the illegality messages will (sometimes) be more useful).
I get these errors with the new script:
- Latios has an illegal set (incompatibility) inherited from Lucario-Mega
- Latios is banned by Inheritance.

With this team:
Diancie @ Diancite
Ability: Levitate
EVs: 252 HP / 4 Def / 252 Spe
Timid Nature
- Calm Mind
- Moonblast
- Earth Power
- Moonlight

Snorlax @ Toxic Orb
Ability: Poison Heal
EVs: 248 HP / 8 Atk / 252 SpD
Careful Nature
- Stealth Rock
- Facade
- Knock Off
- Roost

Latios (M) @ Choice Scarf
Ability: Adaptability
EVs: 252 SpA / 4 SpD / 252 Spe
Timid Nature
- Psychic
- Dragon Pulse
- Aura Sphere
- Dark Pulse

Landorus (M) @ Life Orb
Ability: Magnet Pull
EVs: 252 SpA / 4 SpD / 252 Spe
Timid Nature
- Earth Power
- Taunt
- Volt Switch
- Hidden Power [Ice]

Skarmory @ Rocky Helmet
Ability: Gale Wings
EVs: 248 HP / 236 SpD / 24 Spe
Careful Nature
- Swords Dance
- Roost
- Will-O-Wisp
- Brave Bird

Azelf @ Life Orb
Ability: Protean
EVs: 252 Atk / 4 SpA / 252 Spe
Hasty Nature
- Sucker Punch
- Fire Blast
- Drain Punch
- Grass Knot
 
I get these errors with the new script:
- Latios has an illegal set (incompatibility) inherited from Lucario-Mega
- Latios is banned by Inheritance.

With this team:
Diancie @ Diancite
Ability: Levitate
EVs: 252 HP / 4 Def / 252 Spe
Timid Nature
- Calm Mind
- Moonblast
- Earth Power
- Moonlight

Snorlax @ Toxic Orb
Ability: Poison Heal
EVs: 248 HP / 8 Atk / 252 SpD
Careful Nature
- Stealth Rock
- Facade
- Knock Off
- Roost

Latios (M) @ Choice Scarf
Ability: Adaptability
EVs: 252 SpA / 4 SpD / 252 Spe
Timid Nature
- Psychic
- Dragon Pulse
- Aura Sphere
- Dark Pulse

Landorus (M) @ Life Orb
Ability: Magnet Pull
EVs: 252 SpA / 4 SpD / 252 Spe
Timid Nature
- Earth Power
- Taunt
- Volt Switch
- Hidden Power [Ice]

Skarmory @ Rocky Helmet
Ability: Gale Wings
EVs: 248 HP / 236 SpD / 24 Spe
Careful Nature
- Swords Dance
- Roost
- Will-O-Wisp
- Brave Bird

Azelf @ Life Orb
Ability: Protean
EVs: 252 Atk / 4 SpA / 252 Spe
Hasty Nature
- Sucker Punch
- Fire Blast
- Drain Punch
- Grass Knot
I suspect that there is still an issue regarding megas with HA event abilities, but I couldn't really confirm it.
Anyway, your team now passes: http://pastebin.com/WUpEJmxw
 

Pikachuun

the entire waruda machine
config/formats.js
Code:
   {
        name: "Powered Up!",
        section: "Other Metagames",
    
        ruleset: ['Pokemon', 'Standard', 'Team Preview'],
        banlist: ['Uber', 'Soul Dew', 'Gengarite', 'Kangaskhanite', 'Lucarionite', 'Mawilite', 'Salamencite', 'Huge Power', 'Pure Power', 'Medichamite', 'Serene Grace'], //Medichamite is banned by extension of Huge Power + Pure Power being banned
        mod: "poweredup"
    },
mods/poweredup/abilities.js
mods/poweredup/statuses.js
Code:
exports.BattleStatuses = {
    slp: {
        inherit: true,
        onBeforeMove: function (pokemon, target, move) {
            if (pokemon.getAbility().isHalfSleep) {
                (pokemon.statusData.time--)--;
            }
            pokemon.statusData.time--;
            if (pokemon.statusData.time <= 0) {
                pokemon.cureStatus();
                return;
            }
            this.add('cant', pokemon, 'slp');
            if (move.sleepUsable) {
                return;
            }
            return false;
        }
    },
    aura: {
        inherit: true,
        onBasePower: function (basePower, user, target, move) {
            var modifier = 5 / 3;
            this.debug('Aura Boost');
            if (user.volatiles['aurabreak']) {
                modifier = 0.6;
                this.debug('Aura Boost reverted by Aura Break');
            }
            return this.chainModify(modifier);
        }
    },
    raindance: {
        inherit: true,
        onStart: function (battle, source, effect) {
            if (effect && effect.effectType === 'Ability' && this.gen <= 5) {
                this.effectData.duration = 0;
                this.add('-weather', 'RainDance', '[from] ability: ' + effect, '[of] ' + source);
            } else if (effect && effect.effectType === 'Ability') {
                this.effectData.duration *= 2;
                this.add('-weather', 'RainDance', '[from] ability: ' + effect, '[of] ' + source);
            } else {
                this.add('-weather', 'RainDance');
            }
        }
    },
    sunnyday: {
        inherit: true,
        onStart: function (battle, source, effect) {
            if (effect && effect.effectType === 'Ability' && this.gen <= 5) {
                this.effectData.duration = 0;
                this.add('-weather', 'SunnyDay', '[from] ability: ' + effect, '[of] ' + source);
            } else if (effect && effect.effectType === 'Ability') {
                this.effectData.duration *= 2;
                this.add('-weather', 'SunnyDay', '[from] ability: ' + effect, '[of] ' + source);
            } else {
                this.add('-weather', 'SunnyDay');
            }
        }
    },
    sandstorm: {
        inherit: true,
        onStart: function (battle, source, effect) {
            if (effect && effect.effectType === 'Ability' && this.gen <= 5) {
                this.effectData.duration = 0;
                this.add('-weather', 'Sandstorm', '[from] ability: ' + effect, '[of] ' + source);
            } else if (effect && effect.effectType === 'Ability') {
                this.effectData.duration *= 2;
                this.add('-weather', 'Sandstorm', '[from] ability: ' + effect, '[of] ' + source);
            } else {
                this.add('-weather', 'Sandstorm');
            }
        }
    },
    hail: {
        inherit: true,
        onStart: function (battle, source, effect) {
            if (effect && effect.effectType === 'Ability' && this.gen <= 5) {
                this.effectData.duration = 0;
                this.add('-weather', 'Hail', '[from] ability: ' + effect, '[of] ' + source);
            } else if (effect && effect.effectType === 'Ability') {
                this.effectData.duration *= 2;
                this.add('-weather', 'Hail', '[from] ability: ' + effect, '[of] ' + source);
            } else {
                this.add('-weather', 'Hail');
            }
        }
    }
};
config/formats.js
Code:
{
        name: "Offensification",
        section: "Other Metagames",
      
        ruleset: ['Pokemon', 'Standard', 'Team Preview'],
        banlist: ['Uber', 'Soul Dew', 'Gengarite', 'Kangaskhanite', 'Lucarionite', 'Mawilite', 'Salamencite', 'Flatter', 'Kyurem-Black'],
        onModifyMove: function (move, pokemon) {
            if (pokemon.stats.atk > pokemon.stats.spa) {
                move.category = (move.category === "Status") ? "Status" : "Physical";
            } else if (pokemon.stats.spa > pokemon.stats.atk) {
                move.category = (move.category === "Status") ? "Status" : "Special";
            }
          
            if (move.id === 'bellydrum') {
                move.onHit = function (target) {
                    if (target.hp <= target.maxhp / 2 || target.boosts.atk >= 6 || target.maxhp === 1) { // Shedinja clause
                        return false;
                    }
                    this.directDamage(target.maxhp / 2);
                    if (target.stats.atk >= target.stats.spa) {
                        target.setBoost({atk: 6});
                        this.add('-setboost', target, 'atk', '6', '[from] move: Belly Drum');
                    } else {
                        target.setBoost({spa: 6});
                        this.add('-setboost', target, 'spa', '6', '[from] move: Belly Drum'); //Note: This is bugged in that the message says Attack is boosted, but the Special Attack is still boosted.
                    }  
                }
            }
        },
        onBoost: function (boost, target, source, effect) {
            var boostee = target;
            if (source && target === source) boostee = source;
            var phys = false;
            if (boostee.stats.atk > boostee.stats.spa) phys = true;
            var spec = false;
            if (boostee.stats.atk < boostee.stats.spa) spec = true;
            if (phys || spec) {
                for (var i in boost) {
                    if (phys && i === 'spa') {
                        if (boost['atk']) boost['atk'] += boost[i];
                        else boost['atk'] = boost[i];
                        boost[i] = 0;
                    } else if (phys && i === 'spd') {
                        if (boost['def']) boost['def'] += boost[i];
                        else boost['def'] = boost[i];
                        boost[i] = 0;
                    } else if (spec && i === 'atk') {
                        if (boost['spa']) boost['spa'] += boost[i];
                        else boost['spa'] = boost[i];
                        boost[i] = 0;
                    } else if (spec && i === 'def') {
                        if (boost['spd']) boost['spd'] += boost[i];
                        else boost['spd'] = boost[i];
                        boost[i] = 0;
                    }
                }
            }
        }
    },
 
Last edited:
Hey something I should've posted ages ago, specifically Chart Shift's code.

Code:
/* config/formats.js */
{
        name: "Chart Shift",
        section: "Other Metagames",
        mod: 'chartshift',
        ruleset: ['OU']
}

/* mods/chartshift/scripts.js */

exports.BattleTypeChart = {
    "Bug": {
        inherit: true,
        damageTaken: {
            "Bug": 1,
            "Dark": 1,
            "Dragon": 0,
            "Electric": 0,
            "Fairy": 0,
            "Fighting": 2,
            "Fire": 0,
            "Flying": 2,
            "Ghost": 1,
            "Grass": 0,
            "Ground": 0,
            "Ice": 0,
            "Normal": 0,
            "Poison": 0,
            "Psychic": 2,
            "Rock": 0,
            "Steel": 0,
            "Water": 0
        }
    },
    "Dark": {
        inherit: true,
        damageTaken: {
            "Bug": 0,
            "Dark": 0,
            "Dragon": 1,
            "Electric": 2,
            "Fairy": 1,
            "Fighting": 0,
            "Fire": 2,
            "Flying": 0,
            "Ghost": 0,
            "Grass": 2,
            "Ground": 0,
            "Ice": 1,
            "Normal": 0,
            "Poison": 0,
            "Psychic": 0,
            "Rock": 0,
            "Steel": 0,
            "Water": 2
        }
    },
    "Dragon": {
        inherit: true,
        damageTaken: {
            "Bug": 2,
            "Dark": 1,
            "Dragon": 0,
            "Electric": 0,
            "Fairy": 0,
            "Fighting": 3,
            "Fire": 0,
            "Flying": 0,
            "Ghost": 1,
            "Grass": 0,
            "Ground": 0,
            "Ice": 2,
            "Normal": 3,
            "Poison": 2,
            "Psychic": 0,
            "Rock": 0,
            "Steel": 0,
            "Water": 0
        }
    },
    "Electric": {
        inherit: true,
        damageTaken: {
            par: 3,
            "Bug": 0,
            "Dark": 0,
            "Dragon": 0,
            "Electric": 1,
            "Fairy": 0,
            "Fighting": 0,
            "Fire": 2,
            "Flying": 0,
            "Ghost": 0,
            "Grass": 1,
            "Ground": 0,
            "Ice": 2,
            "Normal": 0,
            "Poison": 0,
            "Psychic": 0,
            "Rock": 0,
            "Steel": 2,
            "Water": 2
        }
    },
    "Fairy": {
        inherit: true,
        damageTaken: {
            "Bug": 2,
            "Dark": 0,
            "Dragon": 2,
            "Electric": 0,
            "Fairy": 2,
            "Fighting": 1,
            "Fire": 1,
            "Flying": 2,
            "Ghost": 0,
            "Grass": 2,
            "Ground": 1,
            "Ice": 2,
            "Normal": 2,
            "Poison": 3,
            "Psychic": 2,
            "Rock": 2,
            "Steel": 2,
            "Water": 0
        }
    },
    "Fighting": {
        inherit: true,
        "damageTaken": {
            "Bug": 0,
            "Dark": 0,
            "Dragon": 0,
            "Electric": 0,
            "Fairy": 0,
            "Fighting": 1,
            "Fire": 1,
            "Flying": 0,
            "Ghost": 0,
            "Grass": 0,
            "Ground": 0,
            "Ice": 2,
            "Normal": 0,
            "Poison": 0,
            "Psychic": 0,
            "Rock": 1,
            "Steel": 1,
            "Water": 0
        }
    },
    "Fire": {
        inherit: true,
        damageTaken: {
            brn: 3,
            "Bug": 0,
            "Dark": 0,
            "Dragon": 0,
            "Electric": 0,
            "Fairy": 0,
            "Fighting": 1,
            "Fire": 0,
            "Flying": 0,
            "Ghost": 3,
            "Grass": 0,
            "Ground": 0,
            "Ice": 0,
            "Normal": 0,
            "Poison": 0,
            "Psychic": 0,
            "Rock": 0,
            "Steel": 0,
            "Water": 0
        }
    },
    "Flying": {
        inherit: true,
        damageTaken: {
            "Bug": 0,
            "Dark": 0,
            "Dragon": 0,
            "Electric": 3,
            "Fairy": 0,
            "Fighting": 0,
            "Fire": 0,
            "Flying": 0,
            "Ghost": 0,
            "Grass": 1,
            "Ground": 0,
            "Ice": 1,
            "Normal": 0,
            "Poison": 2,
            "Psychic": 0,
            "Rock": 2,
            "Steel": 0,
            "Water": 1
        }
    },
    "Ghost": {
        inherit: true,
        damageTaken: {
            trapping: 3,
            "Bug": 0,
            "Dark": 0,
            "Dragon": 0,
            "Electric": 0,
            "Fairy": 0,
            "Fighting": 1,
            "Fire": 2,
            "Flying": 2,
            "Ghost": 0,
            "Grass": 1,
            "Ground": 1,
            "Ice": 0,
            "Normal": 2,
            "Poison": 0,
            "Psychic": 0,
            "Rock": 0,
            "Steel": 1,
            "Water": 1
        }
    },
    "Grass": {
        inherit: true,
        damageTaken: {
            powder: 3,
            "Bug": 0,
            "Dark": 0,
            "Dragon": 0,
            "Electric": 2,
            "Fairy": 0,
            "Fighting": 0,
            "Fire": 0,
            "Flying": 2,
            "Ghost": 0,
            "Grass": 0,
            "Ground": 1,
            "Ice": 0,
            "Normal": 0,
            "Poison": 0,
            "Psychic": 0,
            "Rock": 0,
            "Steel": 2,
            "Water": 0
        }
    },
    "Ground": {
        inherit: true,
        damageTaken: {
            sandstorm: 3,
            "Bug": 2,
            "Dark": 0,
            "Dragon": 0,
            "Electric": 0,
            "Fairy": 0,
            "Fighting": 2,
            "Fire": 0,
            "Flying": 0,
            "Ghost": 0,
            "Grass": 2,
            "Ground": 1,
            "Ice": 0,
            "Normal": 0,
            "Poison": 2,
            "Psychic": 1,
            "Rock": 0,
            "Steel": 0,
            "Water": 0
        }
    },
    "Ice": {
        inherit: true,
        damageTaken: {
            hail: 3,
            frz: 3,
            "Bug": 1,
            "Dark": 0,
            "Dragon": 0,
            "Electric": 2,
            "Fairy": 0,
            "Fighting": 0,
            "Fire": 1,
            "Flying": 1,
            "Ghost": 0,
            "Grass": 2,
            "Ground": 2,
            "Ice": 1,
            "Normal": 0,
            "Poison": 1,
            "Psychic": 0,
            "Rock": 0,
            "Steel": 0,
            "Water": 2
        }
    },
    "Normal": {
        inherit: true,
        damageTaken: {
            "Bug": 2,
            "Dark": 2,
            "Dragon": 3,
            "Electric": 0,
            "Fairy": 0,
            "Fighting": 2,
            "Fire": 0,
            "Flying": 0,
            "Ghost": 0,
            "Grass": 0,
            "Ground": 0,
            "Ice": 0,
            "Normal": 0,
            "Poison": 1,
            "Psychic": 0,
            "Rock": 0,
            "Steel": 1,
            "Water": 0
        }
    },
    "Poison": {
        inherit: true,
        damageTaken: {
            psn: 3,
            tox: 3,
            "Bug": 2,
            "Dark": 2,
            "Dragon": 0,
            "Electric": 0,
            "Fairy": 1,
            "Fighting": 0,
            "Fire": 0,
            "Flying": 1,
            "Ghost": 0,
            "Grass": 0,
            "Ground": 0,
            "Ice": 0,
            "Normal": 0,
            "Poison": 0,
            "Psychic": 1,
            "Rock": 2,
            "Steel": 0,
            "Water": 0
        }
    },
    "Psychic": {
        inherit: true,
        damageTaken: {
            "Bug": 2,
            "Dark": 0,
            "Dragon": 0,
            "Electric": 1,
            "Fairy": 0,
            "Fighting": 2,
            "Fire": 0,
            "Flying": 0,
            "Ghost": 0,
            "Grass": 2,
            "Ground": 3,
            "Ice": `,
            "Normal": 0,
            "Poison": 0,
            "Psychic": 0,
            "Rock": 1,
            "Steel": 0,
            "Water": 0
        }
    },
    "Rock": {
        inherit: true,
        damageTaken: {
            sandstorm: 3,
            "Bug": 0,
            "Dark": 0,
            "Dragon": 0,
            "Electric": 0,
            "Fairy": 0,
            "Fighting": 2,
            "Fire": 1,
            "Flying": 1,
            "Ghost": 0,
            "Grass": 2,
            "Ground": 2,
            "Ice": 0,
            "Normal": 0,
            "Poison": 0,
            "Psychic": 0,
            "Rock": 1,
            "Steel": 0,
            "Water": 0
        }
    },
    "Steel": {
        inherit: true,
        damageTaken: {
            psn: 3,
            tox: 3,
            sandstorm: 3,
            "Bug": 1,
            "Dark": 2,
            "Dragon": 0,
            "Electric": 0,
            "Fairy": 1,
            "Fighting": 1,
            "Fire": 0,
            "Flying": 0,
            "Ghost": 2,
            "Grass": 0,
            "Ground": 0,
            "Ice": 0,
            "Normal": 0,
            "Poison": 0,
            "Psychic": 3,
            "Rock": 0,
            "Steel": 0,
            "Water": 0
        }
    },
    "Water": {
        inherit: true,
        damageTaken: {
            "Bug": 2,
            "Dark": 0,
            "Dragon": 0,
            "Electric": 0,
            "Fairy": 0,
            "Fighting": 0,
            "Fire": 2,
            "Flying": 0,
            "Ghost": 0,
            "Grass": 2,
            "Ground": 1,
            "Ice": 2,
            "Normal": 0,
            "Poison": 0,
            "Psychic": 0,
            "Rock": 1,
            "Steel": 2,
            "Water": 1
        }
    }
};
I'll post Basic Element's code once I have a higher degree of confidence that it actually works.
 

dhelmise

banend doosre
is a Site Content Manageris a Battle Simulator Administratoris a Top Social Media Contributoris a Community Leaderis a Programmeris a Community Contributoris a Top Contributoris a Top Smogon Media Contributoris a Top Dedicated Tournament Hostis a Smogon Discord Contributor Alumnus
Social Media Head
Sorry for necrobump, but im going to keep all of my code saved in this post.

Code:
    {
        name: "Itemize",
        desc: ["&bullet; <a href=\"http://www.smogon.com/forums/threads/3544277/\">Itemize</a>"],
        section: "Other Metagames",

        mod: 'itemize',
        ruleset: ['Pokemon', 'Standard', 'Team Preview', 'Swagger Clause', 'Baton Pass Clause'],
        banlist: ['Uber', 'Gengarite', 'Kangaskhanite', 'Lucarionite', 'Mawilite', 'Salamencite']
    }
Code:
exports.BattleItems = {
    "adamantorb": {
        inherit: true,
        onBasePower: function (basePower, user, target, move) {
            if (move.type === 'Steel' || move.type === 'Dragon') {
                return this.chainModify(1.2);
            }
        }
    },
    "deepseatooth": {
        inherit: true,
        onModifySpD: function (spd) {
            return this.chainModify(2);
        }
    },
    "deepseatooth": {
        inherit: true,
        onModifySpA: function (spa) {
            return this.chainModify(2);
        }
    },
    "eviolite": {
        inherit: true,
        onModifyDef: function (def) {
            return this.chainModify(1.5);
        },
        onModifySpD: function (spd) {
            return this.chainModify(1.5);
        }
    },
    "griseousorb": {
        inherit: true,
        onBasePower: function (basePower, user, target, move) {
            if (move.type === 'Ghost' || move.type === 'Dragon') {
                return this.chainModify(1.2);
            }
        }
    },
    "lightball": {
        inherit: true,
        onModifyAtk: function (atk) {
            return this.chainModify(2);
        },
        onModifySpA: function (spa) {
            return this.chainModify(2);
        }
    },
    "luckypunch": {
        inherit: true,
        onModifyMove: function (move) {
            move.critRatio += 2;
        }
    },
    "lustrousorb": {
        inherit: true,
        onBasePower: function (basePower, user, target, move) {
            if (move.type === 'Water' || move.type === 'Dragon') {
                return this.chainModify(1.2);
            }
        }
    },
    "metalpowder": {
        inherit: true,
        onModifyDef: function (def) {
            return this.chainModify(2);
        }
    },
    "quickpowder": {
        inherit: true,
        onModifySpe: function (speMod) {
            return this.chain(speMod, 2);
        }
    },
    "souldew": {
        inherit: true,
        onModifySpA: function (spa) {
            return this.chainModify(1.5);
        },
        onModifySpD: function (spd) {
            return this.chainModify(1.5);
        }
    },
    "stick": {
        inherit: true,
        onModifyMove: function (move) {
            move.critRatio += 2;
        }
    },
    "thickclub": {
        inherit: true,
        onModifyAtk: function (atk) {
            return this.chainModify(2);
        }
    }
};
Code:
    {
        name: "Accessorize",
        desc: ["&bullet; <a href=\"http://www.smogon.com/forums/threads/3546902/\">Accessorize</a>"],
        section: "Other Metagames",

        mod: 'accessorize',
        ruleset: ['OU'],
        onValidateSet: function (set) {
            var template = this.getTemplate(set.species || set.name);
            var item = this.getItem(set.item);
            switch (item.id) {
            case 'charcoal': case 'spelltag': case 'magnet': case 'sharpbeak': case 'dragonfang': case 'nevermeltice':
                if (template.baseStats.def <= 5 || template.baseStats.spd <= 5) return ["" + template.species + " does not have enough Def. or Sp. Def. to hold " + item.name + "."];
                break;
            case 'mysticwater': case 'hardstone': case 'cherishball': case 'metalcoat': case 'miracleseed': case 'poisonbarb':
                if (template.baseStats.spe <= 10) return ["" + template.species + " does not have enough Speed to hold " + item.name + "."];
                break;
            case 'twistedspoon': case 'silkscarf': case 'blackglasses':
                if (template.baseStats.def <= 10) return ["" + template.species + " does not have enough Defense to hold " + item.name + "."];
                break;
            case 'silverpowder': case 'softsand': case 'blackbelt':
                if (template.baseStats.spd <= 10) return ["" + template.species + " does not have enough Special Defense to hold " + item.name + "."];
                break;
            }
        }
    }
Code:
exports.BattleScripts = {
    mixTemplate: function (pokemon, type, deltas) {
        if (!type || !(type in Tools.data.TypeChart)) throw TypeError("Must specify valid type!");
        if (!deltas) throw TypeError("Must specify deltas!");
        if (pokemon.types.indexOf(type) < 0) {
            this.add('-start', pokemon, 'typechange', pokemon.types[0] + '/' + type);
            pokemon.typesData[1] = {type: type, suppressed: false, isAdded: false};
        }
        var template = Object.clone(this.getTemplate(pokemon.species));
        for (var stat in template.baseStats) {
            template.baseStats[stat] += deltas[stat] || 0;
        }
        pokemon.formeChange(template);
    }
};
Code:
exports.BattleItems = {
    "blackbelt": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Black Belt');
            this.mixTemplate(pokemon, 'Fighting', {atk: 30, def: 15, spd: -10, spe: 5});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Fighting', {atk: 30, def: 15, spd: -10, spe: 5});
            }
        }
    },
    "blackglasses": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Black Glasses');
            this.mixTemplate(pokemon, 'Dark', {def: -10, spa: 30, spd: 15, spe: 5});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Dark', {def: -10, spa: 30, spd: 15, spe: 5});
            }
        }
    },
    "charcoal": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Charcoal');
            this.mixTemplate(pokemon, 'Fire', {atk: 25, def: -5, spa: 25, spd: -5});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Fire', {atk: 25, def: -5, spa: 25, spd: -5});
            }
        }
    },
    "cherishball": {
        inherit: true,
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Cherish Ball');
            this.mixTemplate(pokemon, 'Fairy', {def: 25, spd: 25, spe: -10});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Fairy', {def: 25, spd: 25, spe: -10});
            }
        }
    },
    "dragonfang": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Dragon Fang');
            this.mixTemplate(pokemon, 'Dragon', {atk: 20, def: -5, spa: 20, spd: -5, spe: 10});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Dragon', {atk: 20, def: -5, spa: 20, spd: -5, spe: 10});
            }
        }
    },
    "hardstone": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Hard Stone');
            this.mixTemplate(pokemon, 'Rock', {atk: 20, def: 30, spe: -10});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Water', {atk: 20, def: 30, spe: -10});
            }
        }
    },
    "magnet": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Magnet');
            this.mixTemplate(pokemon, 'Electric', {def: -5, spa: 20, spd: -5, spe: 30});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Electric', {def: -5, spa: 20, spd: -5, spe: 30});
            }
        }
    },
    "metalcoat": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Metal Coat');
            this.mixTemplate(pokemon, 'Steel', {def: 25, spd: 25, spe: -10});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Steel', {def: 25, spd: 25, spe: -10});
            }
        }
    },
    "miracleseed": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Miracle Seed');
            this.mixTemplate(pokemon, 'Grass', {def: 15, spa: 20, spd: 15, spe: -10});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Grass', {def: 15, spa: 20, spd: 15, spe: -10});
            }
        }
    },
    "mysticwater": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Mystic Water');
            this.mixTemplate(pokemon, 'Water', {spa: 20, spd: 30, spe: -10});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Water', {spa: 20, spd: 30, spe: -10});
            }
        }
    },
    "nevermeltice": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Never-Melt Ice');
            this.mixTemplate(pokemon, 'Ice', {atk: 20, def: -5, spa: 20, spd: -5, spe: 10});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Ice', {atk: 20, def: -5, spa: 20, spd: -5, spe: 10});
            }
        }
    },
    "poisonbarb": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Poison Barb');
            this.mixTemplate(pokemon, 'Poison', {atk: 20, def: 15, spd: 15, spe: -10});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Poison', {atk: 20, def: 15, spd: 15, spe: -10});
            }
        }
    },
    "sharpbeak": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Sharp Beak');
            this.mixTemplate(pokemon, 'Flying', {atk: 20, def: -5, spd: -5, spe: 30});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Flying', {atk: 20, def: -5, spd: -5, spe: 30});
            }
        }
    },
    "silkscarf": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Silk Scarf');
            this.mixTemplate(pokemon, 'Normal', {atk: 10, def: -10, spa: 30, spd: 10});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Normal', {atk: 10, def: -10, spa: 30, spd: 10});
            }
        }
    },
    "silverpowder": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Silver Powder');
            this.mixTemplate(pokemon, 'Bug', {atk: 25, def: 10, spd: -10, spe: 15});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Bug', {atk: 25, def: 10, spd: -10, spe: 15});
            }
        }
    },
    "softsand": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Soft Sand');
            this.mixTemplate(pokemon, 'Ground', {atk: 30, def: 10, spa: 10, spd: -10});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Ground', {atk: 30, def: 10, spa: 10, spd: -10});
            }
        }
    },
    "spelltag": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Spell Tag');
            this.mixTemplate(pokemon, 'Ghost', {atk: 25, def: -5, spa: 25, spd: -5});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Ghost', {atk: 25, def: -5, spa: 25, spd: -5});
            }
        }
    },
    "twistedspoon": {
        inherit: true,
        onBasePower: function () {},
        onTakeItem: false,
        onSwitchIn: function (pokemon) {
            if (!pokemon.currentSpecies) pokemon.currentSpecies = pokemon.template.speciesid;
            this.add('-item', pokemon, 'Twisted Spoon');
            this.mixTemplate(pokemon, 'Psychic', {def: -10, spa: 25, spd: 10, spe: 15});
        },
        onUpdate: function (pokemon) {
            if (pokemon.currentSpecies !== pokemon.template.speciesid) {
                this.mixTemplate(pokemon, 'Psychic', {def: -10, spa: 25, spd: 10, spe: 15});
            }
        }
    }
};
Code:
    {
        name: "Field Plating",
        desc: ["&bullet; <a href=\"http://www.smogon.com/forums/threads/3548351/\">Field Plating</a>"],
        section: "Other Metagames",

        mod: 'fieldplating',
        ruleset: ['OU']
    }
Code:
exports.BattleItems = {
    "dreadplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            if (this.pseudoWeather['magicroom']) {
                this.removePseudoWeather('magicroom', source);
            } else {
                this.addPseudoWeather('magicroom', source);
            }
        }
    },
    "dracoplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            if (this.pseudoWeather['wonderroom']) {
                this.removePseudoWeather('wonderroom', source);
            } else {
                this.addPseudoWeather('wonderroom', source);
            }
        }
    },
    "earthplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.addPseudoWeather('mudsport', source);
        }
    },
    "flameplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.setWeather('sunnyday');
        }
    },
    "icicleplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.setWeather('hail');
        }
    },
    "ironplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.addPseudoWeather('gravity', source);
        }
    },
    "meadowplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.setTerrain('grassyterrain');
        }
    },
    "mindplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            if (this.pseudoWeather['trickroom']) {
                this.removePseudoWeather('trickroom', source);
            } else {
                this.addPseudoWeather('trickroom', source);
            }
        }
    },
    "pixieplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.setTerrain('mistyterrain');
        }
    },
    "skyplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.addPseudoWeather('watersport', source);
        }
    },
    "splashplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.setWeather('raindance');
        }
    },
    "stoneplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.setWeather('sandstorm');
        }
    },
    "spookyplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.addPseudoWeather('fairylock');
        }
    },
    "toxicplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.useMove('haze', source);
        }
    },
    "zapplate": {
        inherit: true,
        onBasePower: function () {},
        onStart: function (source) {
            this.setTerrain('electricterrain');
        }
    }
};
 
  • Like
Reactions: Mq
Apologies if this is not the place to ask, but I'm curious: How, exactly, do you code for OMs? Are all these changes just manipulations of attributes of PS? And is there somewhere to learn to?
 
AbNormal's code, since the project seems to be done with. It's not strictly complete -I never figured out how to set Roost to convert pure Flying to pure Normal and NotACoolName never dealt with it either- but it should be playable, at least, and it may not ever get more completed than this.

http://pastebin.com/0LarLVtE

I'm kind of surprised this thread was never stickied, though.
 
That is what's normally done yes, but it's useful to aspiring coders to have a single place they can reference a bunch of functioning code for ideas on how to make things work. Having to trawl through a dozen or more threads to do so is... really inconvenient, and sometimes the thing that solves your problem is going to be in a metagame you've entirely forgotten about (I've taken inspiration from GenNEXT entirely by virtue of it being in the main Showdown code -I wouldn't have even known it existed if it wasn't part of the main download) or never even considered might be coded in a way relevant to the problem you're trying to solve.

OMs suffer a bit from how few people have even marginal skill at manipulating Showdown's code. Having it easier for people get started/get competent helps take some of the workload off the main coders. (eg you and Zarel and whoever else is involved without my awareness)

... on a semi-related note, is onMoveFail something that can even function when called from Formats, or does it only function when called from within a move? Because I've tried using it from Format and gotten nil, no idea why.
 
It's convenient for me. When something wins OMotM a second time, I don't have to go searching the GitHub history for it. I can just go to the metagame thread and get my code from the first time. Similarly, if someone else codes something I can get it from the metagame thread.

This thread doesn't work because only one person can update the OP, who isn't active on the forums these days.
 
Turnmons

PHP:
{
        name: "Turnmons",
        section: "Other Metagames",
   
        mod: ['turnmons'],
        ruleset: ['OU'],
        banlist: ['Taunt'],
   
        validateSet: function (set) {
            var hasAtkMove = false;
            var hasDefMove = false;
            for (var i = 0; i < set.moves.length; i++)
            {
                var move = this.getMove(set.moves[i]);
                if (move.category === 'Status') {
                    hasDefMove = true;
                }
                else {
                    hasAtkMove = true;
                }
            }
            // Check if it has at least one of each
            if (!hasAtkMove) {
                return set.species + " doesn't know any offensive moves.";
            }
            if (!hasDefMove) {
                return set.species + " doesn't know any defensive moves.";
            }
       
            // Complex ban: Klutz + AV + Trick/Switcheroo
            if (set.ability === "Klutz" && set.item === "Assault Vest")
            {
                for (var i = 0; i < set.moves.length; i++)
                {
                    var move = this.getMove(set.moves[i]);
                    if (move.id === "trick" || move.id === "switcheroo") {
                        return "The combination of Klutz + Assault Vest + " + move.name + " is banned by Turnmons.";
                    }
                }
            }
        }
    }

PHP:
exports.BattleStatuses =
{
    pokemon:
    {
        onModifyPokemon: function (pokemon)
        {
            var atkTurns = [0, 6, 7, 8, 9];
            var defTurns = [1, 2, 3, 4, 5];
            var moves = pokemon.moveset;
            for (var i = 0; i < moves.length; i++) {
                    var move = this.getMove(moves[i].move);
                    // Exceptions: Assist, Metronome, Sleep Talk
                    if (move.id === "assist" || move.id === "metronome" || move.id === "sleeptalk") {
                        continue;
                    }
                    // Attacking turns
                    if (atkTurns.indexOf(this.turn % 10) > -1)
                    {
                        if (move.category === 'Status')
                        {
                            pokemon.disableMove(moves[i].id);
                        }
                    }
                    // Defending turns
                    else
                    {
                        if (move.category !== 'Status')
                        {
                            pokemon.disableMove(moves[i].id);
                        }
                    }
                }
        }
    }

}
PHP:
exports.BattleMovedex =
{
    assist:
    {
        inherit: true,
        onHit: function (target) {
            var moves = [];
            for (var j = 0; j < target.side.pokemon.length; j++) {
                var pokemon = target.side.pokemon[j];
                if (pokemon === target) continue;
                for (var i = 0; i < pokemon.moveset.length; i++) {
                    var move = this.getMove(pokemon.moveset[i].id);
                    var noAssist = {
                        assist:1, belch:1, bestow:1, bounce:1, chatter:1, circlethrow:1, copycat:1, counter:1, covet:1, destinybond:1, detect:1, dig:1, dive:1, dragontail:1, endure:1, feint:1, fly:1, focuspunch:1, followme:1, helpinghand:1, kingsshield:1, matblock:1, mefirst:1, metronome:1, mimic:1, mirrorcoat:1, mirrormove:1, naturepower:1, phantomforce:1, protect:1, ragepowder:1, roar:1, shadowforce:1, sketch:1, sleeptalk:1, snatch:1, spikyshield:1, struggle:1, switcheroo:1, thief:1, transform:1, trick:1, whirlwind:1
                    };
                    // Can only call defensive moves in defensive turns, and vice-versa
                    var atkTurns = [0, 6, 7, 8, 9];
                    var turnIndex = this.turn % 10;
                    if (!noAssist[move.id] && ((move.category === "Status" && atkTurns.indexOf(turnIndex) === -1) || (move.category !== "Status" && atkTurns.indexOf(turnIndex) > -1))) {
                        moves.push(move);
                    }
                }
            }
            var move = '';
            if (moves.length) move = moves[this.random(moves.length)];
            if (!move) {
                return false;
            }
            this.useMove(move, target);
        }
    },
    metronome:
    {
        inherit: true,
        onHit: function (target) {
            var moves = [];
            for (var i in exports.BattleMovedex) {
                var move = exports.BattleMovedex[i];
                if (i !== move.id) continue;
                if (move.isNonstandard) continue;
                var noMetronome = {
                    afteryou:1, assist:1, belch:1, bestow:1, celebrate:1, chatter:1, copycat:1, counter:1, covet:1, craftyshield:1, destinybond:1, detect:1, diamondstorm:1, dragonascent:1, endure:1, feint:1, focuspunch:1, followme:1, freezeshock:1, happyhour:1, helpinghand:1, holdhands:1, hyperspacefury:1, hyperspacehole:1, iceburn:1, kingsshield:1, lightofruin:1, matblock:1, mefirst:1, metronome:1, mimic:1, mirrorcoat:1, mirrormove:1, naturepower:1, originpulse:1, precipiceblades:1, protect:1, quash:1, quickguard:1, ragepowder:1, relicsong:1, secretsword:1, sketch:1, sleeptalk:1, snarl:1, snatch:1, snore:1, spikyshield:1, steameruption:1, struggle:1, switcheroo:1, technoblast:1, thief:1, thousandarrows:1, thousandwaves:1, transform:1, trick:1, vcreate:1, wideguard:1
                };
                // Can only call defensive moves in defensive turns, and vice-versa
                var atkTurns = [0, 6, 7, 8, 9];
                var turnIndex = this.turn % 10;
                if (!noMetronome[move.id] && ((move.category === "Status" && atkTurns.indexOf(turnIndex) === -1) || (move.category !== "Status" && atkTurns.indexOf(turnIndex) > -1))) {
                    moves.push(move);
                }
            }
            var move = '';
            if (moves.length) {
                moves.sort(function (a, b) {return a.num - b.num;});
                move = moves[this.random(moves.length)].id;
            }
            if (!move) {
                return false;
            }
            this.useMove(move, target);
        }
    },
    naturepower:
    {
        inherit: true,
        category: "Special"
    },
    sleeptalk:
    {
        inherit: true,
        onHit: function (pokemon) {
            var moves = [];
            for (var i = 0; i < pokemon.moveset.length; i++) {
                var move = this.getMove(pokemon.moveset[i].id);
                var NoSleepTalk = {
                    assist:1, bide:1, chatter:1, copycat:1, focuspunch:1, mefirst:1, metronome:1, mimic:1, mirrormove:1, naturepower:1, sketch:1, sleeptalk:1, uproar:1
                };
                // Can only call defensive moves in defensive turns, and vice-versa
                var atkTurns = [0, 6, 7, 8, 9];
                var turnIndex = this.turn % 10;
                if (move && !(NoSleepTalk[move.id] || move.isTwoTurnMove) && ((move.category === "Status" && atkTurns.indexOf(turnIndex) === -1) || (move.category !== "Status" && atkTurns.indexOf(turnIndex) > -1))) {
                    moves.push(move);
                }
            }
            var move = '';
            if (moves.length) move = moves[this.random(moves.length)];
            if (!move) {
                return false;
            }
            this.useMove(move, pokemon);
        }
    },
    struggle:
    {
        inherit: true,
        basePower: 0
    }
}
I try to run this but it crash my team validator and TYPE ERROR: this.getMove is not a function. Can u help me?
 
This is the list of OMs that I'm currently running on rom.psim.us:
  • 0v0
  • AbNormal
  • Ability Unity
  • Accessorize
  • Acid Rain
  • Alphabet Cup
  • Alphability
  • Atk-Def Equality
  • Averagemons
  • Balanced Hackmons Plus
  • BasePowerMons
  • Burning 'Mon
  • Camomons
  • Cross Evolution
  • Custom Power
  • Enchanted Items
  • Field Control
  • Follow the Leader
  • Genmons
  • Gods and Followers
  • Got Talent?
  • Head Start
  • Immunimons
  • Inaccuratemons
  • Inheritance
  • Inverse Battle
  • Itemize
  • Mediocremons
  • Megamons
  • Mix and Mega
  • Monogen
  • Monotype
  • Move Pass LC
  • Multitype Mansion
  • NOSTABmons
  • Nature's Blessing
  • Noobmons
  • Pacifistmons
  • Pikachu Cup
  • Powered Up
  • Priority Cup
  • Protean Palace
  • Protect: The Metagame
  • Reliablemons
  • Return'd
  • Setupmons
  • Sketchmons
  • SlowMons
  • Stat Switch
  • Suicide Cup
  • Super-Effectivemons
  • The Power Within
  • Tiermons
  • Tormenting Spirits
  • Type Control
  • Type Reflectors
Anyone want code for any of them?
 
Last edited:
Someone mentioned Enchanted Items for some reason. Now, Soul Dew is normally banned by OU, so you'll either need to switch it for some other item, or implement PR #2547, or write out all the bans longhand (bwahaha!).
Code:
	{
		name: "Enchanted Items",
		desc: [
			"Enchanted Items is a metagame where you sacrifice your item slot for a secondary ability.",
			"&bullet; <a href=\"https://www.smogon.com/forums/threads/3570431/\">Enchanted Items</a>",
		],
		section: "Other Metagames",

		searchShow: false,
		mod: 'enchanteditems',
		ruleset: ['OU', 'Ability Clause'],
		banlist: ['Shedinja', 'Kyurem-Black', 'Bug Gem', 'Dark Gem', 'Dragon Gem', 'Electric Gem', 'Fairy Gem', 'Fire Gem', 'Ice Gem', 'Poison Gem', 'Psychic Gem', 'Steel Gem', 'Poke Ball', 'Chatter'],
		overrides: ['Soul Dew'],
		onValidateSet: function (set) {
			let ability = this.getAbility(set.ability);
			let item = this.getItem(set.item);
			if (ability.item && ability.item == item.id) return ["You are not allowed to have " + ability.name +  " and " + item.name + " on the same Pokemon."];
		},
		onFaint: function (pokemon) {
			this.singleEvent('End', this.getItem(pokemon.item), pokemon.itemData, pokemon);
		},
		onSwitchOut: function (pokemon) {
			this.singleEvent('End', this.getItem(pokemon.item), pokemon.itemData, pokemon);
		},
	},
Code:
'use strict';

exports.BattleFormats = {
	abilityclause: {
		effectType: 'Rule',
		onStart: function () {
			this.add('rule', 'Ability Clause: Limit two of each ability');
		},
		onValidateTeam: function (team, format) {
			let abilityTable = {};
			for (let i = 0; i < team.length; i++) {
				let ability = this.getAbility(team[i].ability);
				if (!abilityTable[ability.id]) abilityTable[ability.id] = 0;
				if (++abilityTable[ability.id] > 2) {
					return ["You are limited to two of each ability by Ability Clause.", "(You have more than two of " + ability.name + " or " + this.getItem(ability.item).name + ")"];
				}
				let item = toId(team[i].item);
				if (!item) continue;
				item = this.getItem(item);
				ability = item.ability;
				if (!ability) continue;
				if (!abilityTable[ability]) abilityTable[ability] = 0;
				if (++abilityTable[ability] > 2) {
					return ["You are limited to two of each ability by Ability Clause.", "(You have more than two of " + this.getAbility(ability).name + " or " + item.name + ")"];
				}
			}
		},
	},
	batonpassclause: {
		effectType: 'Banlist',
		name: 'Baton Pass Clause',
		onStart: function () {
			this.add('rule', 'Baton Pass Clause: Limit one Baton Passer, can\'t pass Spe and other stats simultaneously');
		},
		onValidateTeam: function (team, format) {
			let BPcount = 0;
			for (let i = 0; i < team.length; i++) {
				if (team[i].moves.indexOf('Baton Pass') >= 0) {
					BPcount++;
				}
				if (BPcount > 1) {
					return [(team[i].name || team[i].species) + " has Baton Pass, but you are limited to one Baton Pass user by Baton Pass Clause."];
				}
			}
		},
		onValidateSet: function (set, format, setHas) {
			if (!('batonpass' in setHas)) return;

			// check if Speed is boosted
			let speedBoosted = false;
			for (let i = 0; i < set.moves.length; i++) {
				let move = this.getMove(set.moves[i]);
				if (move.boosts && move.boosts.spe > 0) {
					speedBoosted = true;
					break;
				}
			}
			let boostSpeed = ['flamecharge', 'geomancy', 'motordrive', 'rattled', 'speedboost', 'steadfast', 'weakarmor', 'cheriberry', 'duskball', 'friendball', 'skullfossil', 'weaknesspolicy'];
			if (!speedBoosted) {
				for (let i = 0; i < boostSpeed.length; i++) {
					if (boostSpeed[i] in setHas) {
						speedBoosted = true;
						break;
					}
				}
			}
			if (!speedBoosted) return;

			// check if non-Speed boosted
			let nonSpeedBoosted = false;
			for (let i = 0; i < set.moves.length; i++) {
				let move = this.getMove(set.moves[i]);
				if (move.boosts && (move.boosts.atk > 0 || move.boosts.def > 0 || move.boosts.spa > 0 || move.boosts.spd > 0)) {
					nonSpeedBoosted = true;
					break;
				}
			}
			let boostNonSpeed = ['acupressure', 'curse', 'metalclaw', 'meteormash', 'poweruppunch', 'rage', 'rototiller', 'fellstinger', 'bellydrum', 'download', 'justified', 'moxie', 'sapsipper', 'defiant', 'angerpoint', 'diamondstorm', 'flowershield', 'skullbash', 'steelwing', 'stockpile', 'cottonguard', 'chargebeam', 'fierydance', 'geomancy', 'lightningrod', 'stormdrain', 'competitive', 'charge', 'habanberry', 'salacberry', 'whiteherb', 'rawstberry', 'ganlonberry', 'shucaberry', 'heavyball', 'damprock'];
			if (!nonSpeedBoosted) {
				for (let i = 0; i < boostNonSpeed.length; i++) {
					if (boostNonSpeed[i] in setHas) {
						nonSpeedBoosted = true;
						break;
					}
				}
			}
			if (!nonSpeedBoosted) return;

			return [(set.name || set.species) + " can Baton Pass both Speed and a different stat, which is banned by Baton Pass Clause."];
		},
	},
	evasionabilitiesclause: {
		effectType: 'Banlist',
		name: 'Evasion Abilities Clause',
		banlist: ['Sand Veil', 'Snow Cloak', 'Persim Berry', 'Cover Fossil'],
		onStart: function () {
			this.add('rule', 'Evasion Abilities Clause: Evasion abilities are banned');
		},
	},
	moodyclause: {
		effectType: 'Banlist',
		name: 'Moody Clause',
		banlist: ['Moody', 'Wave Incense'],
		onStart: function () {
			this.add('rule', 'Moody Clause: Moody is banned');
		},
	},
};
Code:
'use strict';

exports.BattleScripts = {
	init: function() {
		let abilityToItem = {
			aerilate: 'airballoon',
			adaptability: 'apicotberry',
			anticipation: 'blackbelt',
			arenatrap: 'buggem',
			aromaveil: 'blackglasses',
			aurabreak: 'blacksludge',
			baddreams: 'brightpowder',
			battlearmor: 'cellbattery',
			bigpecks: 'charcoal',
			blaze: 'chartiberry',
			bulletproof: 'chestoberry',
			cheekpouch: 'chilanberry',
			chlorophyll: 'chopleberry',
			clearbody: 'cobaberry',
			cloudnine: 'colburberry',
			colorchange: 'custapberry',
			competitive: 'damprock',
			compoundeyes: 'dragonfang',
			contrary: 'darkgem',
			cursedbody: 'ejectbutton',
			cutecharm: 'expertbelt',
			damp: 'flameorb',
			darkaura: 'focusband',
			defeatist: 'fullincense',
			defiant: 'ganlonberry',
			deltastream: 'grepaberry',
			desolateland: 'gripclaw',
			download: 'habanberry',
			drizzle: 'hardstone',
			drought: 'heatrock',
			dryskin: 'iapapaberry',
			earlybird: 'icyrock',
			effectspore: 'kasibberry',
			fairyaura: 'kebiaberry',
			filter: 'keeberry',
			flamebody: 'kelpsyberry',
			flareboost: 'kingsrock',
			flashfire: 'laggingtail',
			flowergift: 'lansatberry',
			flowerveil: 'laxincense',
			forecast: 'leppaberry',
			forewarn: 'liechiberry',
			friendguard: 'luminousmoss',
			frisk: 'magnet',
			furcoat: 'dragongem',
			galewings: 'marangaberry',
			gluttony: 'metalcoat',
			gooey: 'metronome',
			grasspelt: 'micleberry',
			guts: 'miracleseed',
			harvest: 'muscleband',
			healer: 'mysticwater',
			heatproof: 'nevermeltice',
			heavymetal: 'occaberry',
			honeygather: 'oddincense',
			hugepower: 'electricgem',
			hustle: 'passhoberry',
			hydration: 'payapaberry',
			hypercutter: 'petayaberry',
			icebody: 'poisonbarb',
			illuminate: 'quickclaw',
			illusion: 'razorclaw',
			immunity: 'razorfang',
			imposter: 'fairygem',
			infiltrator: 'rindoberry',
			innerfocus: 'rockincense',
			insomnia: 'roseincense',
			intimidate: 'redcard',
			ironbarbs: 'roseliberry',
			ironfist: 'safetygoggles',
			justified: 'salacberry',
			keeneye: 'scopelens',
			klutz: 'seaincense',
			leafguard: 'sharpbeak',
			levitate: 'shedshell',
			lightmetal: 'shellbell',
			lightningrod: 'shucaberry',
			limber: 'silkscarf',
			liquidooze: 'silverpowder',
			magicbounce: 'smoothrock',
			magicguard: 'snowball',
			magician: 'softsand',
			magmaarmor: 'spelltag',
			magnetpull: 'starfberry',
			marvelscale: 'stickybarb',
			megalauncher: 'tangaberry',
			minus: 'twistedspoon',
			moldbreaker: 'wacanberry',
			moody: 'waveincense',
			motordrive: 'weaknesspolicy',
			moxie: 'whiteherb',
			multiscale: 'widelens',
			multitype: 'wiseglasses',
			mummy: 'yacheberry',
			naturalcure: 'zoomlens',
			noguard: 'adamantorb',
			normalize: 'burndrive',
			oblivious: 'chilldrive',
			overcoat: 'deepseascale',
			overgrow: 'deepseatooth',
			owntempo: 'dousedrive',
			parentalbond: 'firegem',
			pickpocket: 'lightball',
			pickup: 'luckypunch',
			pixilate: 'griseousorb',
			plus: 'lustrousorb',
			poisonheal: 'metalpowder',
			poisonpoint: 'quickpowder',
			poisontouch: 'shockdrive',
			prankster: 'souldew',
			pressure: 'stick',
			primordialsea: 'thickclub',
			protean: 'aguavberry',
			purepower: 'icegem',
			quickfeet: 'aspearberry',
			raindish: 'bindingband',
			rattled: 'cheriberry',
			reckless: 'destinyknot',
			refrigerate: 'enigmaberry',
			regenerator: 'figyberry',
			rivalry: 'floatstone',
			rockhead: 'ironball',
			roughskin: 'jabocaberry',
			runaway: 'machobrace',
			sandforce: 'magoberry',
			sandrush: 'oranberry',
			sandstream: 'pechaberry',
			sandveil: 'persimberry',
			sapsipper: 'rawstberry',
			scrappy: 'ringtarget',
			serenegrace: 'rowapberry',
			shadowtag: 'poisongem',
			shedskin: 'wikiberry',
			sheerforce: 'armorfossil',
			shellarmor: 'belueberry',
			shielddust: 'blukberry',
			simple: 'psychicgem',
			skilllink: 'cherishball',
			slowstart: 'clawfossil',
			sniper: 'cornnberry',
			snowcloak: 'coverfossil',
			snowwarning: 'diveball',
			solarpower: 'domefossil',
			solidrock: 'dreamball',
			soundproof: 'durinberry',
			speedboost: 'duskball',
			stall: 'electirizer',
			stancechange: 'energypowder',
			static: 'fastball',
			steadfast: 'friendball',
			stench: 'greatball',
			stickyhold: 'healball',
			stormdrain: 'heavyball',
			strongjaw: 'helixfossil',
			sturdy: 'hondewberry',
			suctioncups: 'levelball',
			superluck: 'loveball',
			swarm: 'lureball',
			sweetveil: 'luxuryball',
			swiftswim: 'magostberry',
			symbiosis: 'masterball',
			synchronize: 'moonball',
			tangledfeet: 'nanabberry',
			technician: 'nestball',
			telepathy: 'netball',
			teravolt: 'nomelberry',
			thickfat: 'oldamber',
			tintedlens: 'pamtreberry',
			torrent: 'parkball',
			toughclaws: 'pinapberry',
			toxicboost: 'plumefossil',
			trace: 'pokeball',
			truant: 'pomegberry',
			turboblaze: 'premierball',
			unaware: 'qualotberry',
			unburden: 'quickball',
			unnerve: 'rabutaberry',
			victorystar: 'rarebone',
			vitalspirit: 'razzberry',
			voltabsorb: 'repeatball',
			waterabsorb: 'rootfossil',
			waterveil: 'safariball',
			weakarmor: 'skullfossil',
			whitesmoke: 'spelonberry',
			wonderguard: 'steelgem',
			wonderskin: 'sportball',
			zenmode: 'tamatoberry',
		}
		Object.keys(abilityToItem).map(ability => {
			this.modData("Abilities", ability).item = abilityToItem[ability];
			let item = this.data.Items[abilityToItem[ability]];
			this.data.Items[abilityToItem[ability]] = Object.assign({}, this.getAbility(ability), {
				id: item.id,
				name: item.name,
				spritenum: item.spritenum,
				num: item.num,
				gen: item.gen,
				desc: item.desc,
				onTakeItem: false,
				ability: ability,
			});
		});
	},
	suppressingAttackEvents: function () {
		return (this.activePokemon && this.activePokemon.isActive && (!this.activePokemon.ignoringAbility() && this.activePokemon.getAbility().stopAttackEvents || !this.activePokemon.ignoringItem() && this.activePokemon.getItem().stopAttackEvents));
	},
	pokemon: {
		hasItem: function (item) {
			if (Tools.getItem(this.item).ability) return false;
			if (this.ignoringItem()) return false;
			if (!Array.isArray(item)) return this.item == toId(item);
			return item.map(toId).contains(this.item);
		},
		hasAbility: function (ability) {
			if (this.ignoringAbility()) return false;
			if (!Array.isArray(ability)) {
				ability = toId(ability);
				if (this.ability === ability) return true;
			} else {
				ability = ability.map(toId);
				if (ability.includes(this.ability)) return true;
			}
			if (ability === "klutz") return false;
			if (!this.item || this.ignoringItem()) return false;
			let item = this.battle.getItem(this.item);
			if (!Array.isArray(ability)) return ability === item.ability;
			return ability.includes(item.ability);
		},
		isGrounded: function (negateImmunity) {
			if ('gravity' in this.battle.pseudoWeather) return true;
			if ('ingrain' in this.volatiles) return true;
			if ('smackdown' in this.volatiles) return true;
			// if (this.hasItem('ironball')) return true;
			if (!negateImmunity && this.hasType('Flying')) return false;
			if (this.hasAbility('levitate') && !this.battle.suppressingAttackEvents()) return null;
			if ('magnetrise' in this.volatiles) return false;
			if ('telekinesis' in this.volatiles) return false;
			return true; // !this.hasItem('airballoon');
		},
	},
};
 
Slayer95 pointed out that I lazily used Object.keys(abilityToItem).map instead of forEach in scripts.js, but unfortunately due to the way editing works it would be a pain for me to fix my post. Sorry about that.
 
This is the list of OMs that I'm currently running on rom.psim.us:
  • 0v0
  • AbNormal
  • Ability Unity
  • Accessorize
  • Acid Rain
  • Alphabet Cup
  • Alphability
  • Atk-Def Equality
  • Averagemons
  • Balanced Hackmons Plus
  • BasePowerMons
  • Burning 'Mon
  • Camomons
  • Cross Evolution
  • Custom Power
  • Enchanted Items
  • Field Control
  • Follow the Leader
  • Genmons
  • Gods and Followers
  • Got Talent?
  • Head Start
  • Immunimons
  • Inaccuratemons
  • Inheritance
  • Inverse Battle
  • Itemize
  • Mediocremons
  • Megamons
  • Mix and Mega
  • Mix and Mega Anything Goes
  • Monogen
  • Monotype
  • Move Pass LC
  • Multitype Mansion
  • NOSTABmons
  • Nature's Blessing
  • Noobmons
  • Pacifistmons
  • Powered Up
  • Priority Cup
  • Protean Palace
  • Protect: The Metagame
  • Reliablemons
  • Return'd
  • Setupmons
  • Sketchmons
  • SlowMons
  • Stat Switch
  • Suicide Cup
  • Super-Effectivemons
  • The Power Within
  • Tiermons
  • Tormenting Spirits
  • Type Control
  • Type Reflectors
Anyone want code for any of them?
Could you share the codes for Mix and Mega, Mix and Mega Anything Goes and Megamons?
 
Could you share the codes for Mix and Mega, Mix and Mega Anything Goes and Megamons?
Oops, Mix and Mega Anything Goes isn't an official metagame so I shouldn't have listed it, but it's basically the same as Mix and Mega but with a ruleset of ['Pokemon', 'Endless Battle Clause', 'HP Percentage Mod, 'Cancel Mod', 'Team Preview'] and a banlist of ['Unreleased', 'Illegal'].
Code:
	{
		name: "Mix and Mega",
		desc: ["&bullet; <a href=\"https://www.smogon.com/forums/threads/3540979/\">Mix and Mega</a>"],
		section: "Random Metagames",

		searchShow: false,
		mod: 'mixandmega',
		ruleset: ['Ubers', 'Baton Pass Clause'],
		banlist: ['Gengarite', 'Shadow Tag', 'Dynamic Punch', 'Electrify', 'Zap Cannon'],
		onValidateTeam: function (team, format) {
			let itemTable = [];
			for (let i = 0; i < team.length; i++) {
				let item = this.getItem(team[i].item);
				if (!item) continue;
				if (itemTable[item] && item.megaStone) return ["You are limited to one of each Mega Stone.", "(You have more than one " + item.name + ".)"];
				if (itemTable[item] && (item.id === 'redorb' || item.id === 'blueorb')) return ["You are limited to one of each Primal Orb.", "(You have more than one " + item.name + ".)"];
				itemTable[item] = true;
			}
		},
		onValidateSet: function (set) {
			let template = this.getTemplate(set.species || set.name);
			let item = this.getItem(set.item);
			if (!item.megaEvolves && item.id !== 'blueorb' && item.id !== 'redorb') return;
			if (template.baseSpecies === item.megaEvolves || (item.id === 'redorb' && template.baseSpecies === 'Groudon') || (item.id === 'blueorb' && template.baseSpecies === 'Kyogre')) return;
			if (template.evos.length) return [template.species + " is not allowed to hold " + item.name + " because it isn't fully evolved."];
			if (template.tier === 'Uber' || ['Cresselia', 'Dragonite', 'Kyurem-Black', 'Lucario', 'Slaking', 'Smeargle', 'Regigigas'].indexOf(template.species) >= 0) {
				return [template.species + " is not allowed to hold a Mega Stone."];
			}
			if (template.species === "Shuckle" && ['aggronite', 'audinite', 'charizarditex', 'charizarditey', 'galladeite', 'gyaradosite', 'houndoominite', 'latiasite', 'salamencite', 'scizorite', 'sharpedonite', 'tyranitarite', 'venusaurite'].indexOf(item.id) >= 0) {
				return ["Shuckle is not allowed to hold " + item.name + "."];
			}
			switch (item.id) {
			case 'beedrillite': case 'kangaskhanite':
				return [item.name + " is only allowed to be held by " + item.megaEvolves + "."];
			case 'blazikenite':
				if (set.ability === 'Speed Boost') break;
				return ["You are only allowed to hold Blazikenite if your Ability is Speed Boost."];
			case 'mawilite': case 'medichamite':
				if (set.ability === 'Huge Power' || set.ability === 'Pure Power') break;
				if (template.species === "Mawile" || template.species === "Medicham") break;
				return ["You are only allowed to hold " + item.name + " if your Ability is Huge Power or Pure Power."];
			case 'slowbronite':
				if (template.baseStats.def <= 185) break;
				return [template.species + " is not allowed to hold Slowbronite."];
			case 'mewtwonitey':
				if (template.baseStats.def > 20) break;
				return [template.species + " does not have enough Defense to hold Mewtwonite Y"];
			case 'diancite':
				if (template.baseStats.def > 40 && template.baseStats.spd > 40) break;
				return [template.species + " does not have enough Defense or Special Defense to hold Diancite."]
			case 'ampharosite': case 'garchompitem': case 'heracronite':
				if (template.baseStats.spe > 10) break;
			case "cameruptite":
				if (template.baseStats.spe > 20) break;
			case "abomasite": case "sablenite":
				if (template.baseStats.spe > 30) break;
				return [template.species + " does not have enough Speed to hold " + item.name + "."];
			}
		},
		onBegin: function () {
			let allPokemon = this.p1.pokemon.concat(this.p2.pokemon);
			for (let i = 0, len = allPokemon.length; i < len; i++) {
				let pokemon = allPokemon[i];
				pokemon.originalSpecies = pokemon.baseTemplate.species;
			}
		},
		onSwitchInPriority: -6,
		onSwitchIn: function (pokemon) {
			let item = pokemon.getItem();
			if (pokemon.isActive && !pokemon.template.isMega && !pokemon.template.isPrimal && (item.id === 'redorb' || item.id === 'blueorb') && pokemon.baseTemplate.tier !== 'Uber' && !pokemon.template.evos.length) {
				if (['Cresselia', 'Dragonite', 'Kyurem-Black', 'Lucario', 'Regigigas', 'Manaphy', 'Slaking', 'Smeargle'].indexOf(pokemon.baseTemplate.baseSpecies) < 0) {
					let template = this.getMixedTemplate(pokemon.originalSpecies, item.id === 'redorb' ? 'Groudon-Primal' : 'Kyogre-Primal');
					pokemon.formeChange(template);
					pokemon.baseTemplate = template;
					if (pokemon.originalSpecies === (item.id === 'redorb' ? 'Groudon' : 'Kyogre')) {
						pokemon.details = template.species + (pokemon.level === 100 ? '' : ', L' + pokemon.level) + (pokemon.gender === '' ? '' : ', ' + pokemon.gender) + (pokemon.set.shiny ? ', shiny' : '');
						this.add('detailschange', pokemon, pokemon.details);
					} else {
						let oTemplate = this.getTemplate(pokemon.originalSpecies);
						this.add('-formechange', pokemon, oTemplate.species, template.requiredItem);
						this.add('-start', pokemon, this.getTemplate(template.originalMega).requiredItem, '[silent]');
						if (oTemplate.types.length !== pokemon.types.length || oTemplate.types[1] !== pokemon.template.types[1]) {
							this.add('-start', pokemon, 'typechange', pokemon.template.types.join('/'), '[silent]');
						}
					}
					this.add('message', pokemon.name + "'s " + pokemon.getItem().name + "a activated!");
					this.add('message', pokemon.name + "'s Primal Reversion! It reverted to its primal form!");
					pokemon.setAbility(template.abilities['0']);
					pokemon.baseAbility = pokemon.ability;
					pokemon.canMegaEvo = false;
				}
			} else {
				let oMegaTemplate = this.getTemplate(pokemon.template.originalMega);
				if (oMegaTemplate.exists && pokemon.originalSpecies !== oMegaTemplate.baseSpecies) {
					this.add('-start', pokemon, oMegaTemplate.requiredItem || oMegaTemplate.requiredMove, '[silent]');
					let oTemplate = this.getTemplate(pokemon.originalSpecies);
					if (oTemplate.types.length !== pokemon.template.types.length || oTemplate.types[1] !== pokemon.template.types[1]) {
						this.add('-start', pokemon, 'typechange', pokemon.template.types.join('/'), '[silent]');
					}
				}
			}
		},
		onSwitchOut: function (pokemon) {
			let oMegaTemplate = this.getTemplate(pokemon.template.originalMega);
			if (oMegaTemplate.exists && pokemon.originalSpecies !== oMegaTemplate.baseSpecies) {
				this.add('-end', pokemon, oMegaTemplate.requiredItem || oMegaTemplate.requiredMove, '[silent]');
			}
		},
	},
Code:
'use strict';

exports.BattleScripts = {
	init: function () {
		let onTakeMegaStone = function (item, source) {
			return false;
		};
		for (let id in this.data.Items) {
			if (id !== 'redorb' && id !== 'blueorb' && !this.data.Items[id].megaStone) continue;
			this.modData('Items', id).onTakeItem = onTakeMegaStone;
		}
	},
	canMegaEvo: function (pokemon) {
		if (pokemon.template.isMega || pokemon.template.isPrimal) return false;

		let item = pokemon.getItem();
		if (item.megaStone) {
			if (item.megaStone === pokemon.species) return false;
			return item.megaStone;
		} else if (pokemon.set.moves.indexOf('dragonascent') >= 0) {
			return 'Rayquaza-Mega';
		} else {
			return false;
		}
	},
	runMegaEvo: function (pokemon) {
		if (pokemon.template.isMega || pokemon.template.isPrimal) return false;
		let template = this.getMixedTemplate(pokemon.originalSpecies, pokemon.canMegaEvo);
		let side = pokemon.side;

		// Pokémon affected by Sky Drop cannot mega evolve. Enforce it here for now.
		let foeActive = side.foe.active;
		for (let i = 0; i < foeActive.length; i++) {
			if (foeActive[i].volatiles['skydrop'] && foeActive[i].volatiles['skydrop'].source === pokemon) {
				return false;
			}
		}

		pokemon.formeChange(template);
		pokemon.baseTemplate = template; // mega evolution is permanent

		// Do we have a proper sprite for it?
		if (this.getTemplate(pokemon.canMegaEvo).baseSpecies === pokemon.originalSpecies) {
			pokemon.details = template.species + (pokemon.level === 100 ? '' : ', L' + pokemon.level) + (pokemon.gender === '' ? '' : ', ' + pokemon.gender) + (pokemon.set.shiny ? ', shiny' : '');
			this.add('detailschange', pokemon, pokemon.details);
			this.add('-mega', pokemon, template.baseSpecies, template.requiredItem);
		} else {
			let oTemplate = this.getTemplate(pokemon.originalSpecies);
			let oMegaTemplate = this.getTemplate(template.originalMega);
			if (template.originalMega === 'Rayquaza-Mega') {
				this.add('message', "" + pokemon.side.name + "'s fervent wish has reached " + pokemon.species + "!");
			} else {
				this.add('message', "" + pokemon.species + "'s " + pokemon.getItem().name + " is reacting to " + pokemon.side.name + "'s Mega Bracelet!");
			}
			this.add('-formechange', pokemon, oTemplate.species, template.requiredItem);
			this.add('message', template.baseSpecies + " has Mega Evolved into Mega " + template.baseSpecies + "!");
			this.add('-start', pokemon, oMegaTemplate.requiredItem || oMegaTemplate.requiredMove, '[silent]');
			if (oTemplate.types.length !== pokemon.template.types.length || oTemplate.types[1] !== pokemon.template.types[1]) {
				this.add('-start', pokemon, 'typechange', pokemon.template.types.join('/'), '[silent]');
			}
		}

		pokemon.setAbility(template.abilities['0']);
		pokemon.baseAbility = pokemon.ability;
		pokemon.canMegaEvo = false;
		return true;
	},
	doGetMixedTemplate: function (template, deltas) {
		if (!deltas) throw new TypeError("Must specify deltas!");
		if (!template || typeof template === 'string') template = this.getTemplate(template);
		template = Object.assign({}, template); // shallow is enough
		template.abilities = {'0': deltas.ability};
		if (template.types[0] === deltas.type) template.types = [deltas.type];
		else if (deltas.type) template.types = [template.types[0], deltas.type];
		let baseStats = template.baseStats;
		template.baseStats = {};
		for (let statName in baseStats) template.baseStats[statName] = baseStats[statName] + deltas.baseStats[statName];
		template.weightkg = Math.max(0.1, template.weightkg + deltas.weightkg);
		template.originalMega = deltas.originalMega;
		template.requiredItem = deltas.requiredItem;
		if (deltas.isMega) template.isMega = true;
		if (deltas.isPrimal) template.isPrimal = true;
		return template;
	},
	getMixedTemplate: function (originalSpecies, megaSpecies) {
		let originalTemplate = this.getTemplate(originalSpecies);
		let megaTemplate = this.getTemplate(megaSpecies);
		if (originalTemplate.baseSpecies === megaTemplate.baseSpecies) return megaTemplate;
		let deltas = this.getMegaDeltas(megaTemplate);
		let template = this.doGetMixedTemplate(originalTemplate, deltas);
		return template;
	},
	getMegaDeltas: function (megaTemplate) {
		let baseTemplate = this.getTemplate(megaTemplate.baseSpecies);
		let deltas = {
			ability: megaTemplate.abilities['0'],
			baseStats: {},
			weightkg: megaTemplate.weightkg - baseTemplate.weightkg,
			originalMega: megaTemplate.species,
			requiredItem: megaTemplate.requiredItem,
		};
		for (let statId in megaTemplate.baseStats) deltas.baseStats[statId] = megaTemplate.baseStats[statId] - baseTemplate.baseStats[statId];
		if (megaTemplate.types.length > baseTemplate.types.length) {
			deltas.type = megaTemplate.types[1];
		} else if (megaTemplate.types.length < baseTemplate.types.length) {
			deltas.type = baseTemplate.types[0];
		} else if (megaTemplate.types[1] !== baseTemplate.types[1]) {
			deltas.type = megaTemplate.types[1];
		}
		if (megaTemplate.isMega) deltas.isMega = true;
		if (megaTemplate.isPrimal) deltas.isPrimal = true;
		return deltas;
	},
};
 
Megamons?
There's a way of implementing Megamons without using a mod, but it's quite long, as it involves copying parts of the validator into the format, so I prefer this version:
Code:
	{
		name: "Megamons",
		desc: ["&bullet; <a href=\"https://www.smogon.com/forums/threads/3566648/\">Megamons</a>"],
		section: "Other Metagames",

		searchShow: false,
		mod: 'megamons',
		ruleset: ['Ubers'],
	},
Code:
'use strict';

exports.BattleScripts = {
	init: function () {
		for (let i in this.data.Pokedex) {
			let pokemon = this.data.Pokedex[i];
			switch (pokemon.species) {
			case 'Gengar-Mega':
			case 'Mewtwo-Mega-X':
			case 'Mewtwo-Mega-Y':
			case 'Rayquaza-Mega':
				break;
			default:
				switch (pokemon.forme) {
				case 'Mega':
				case 'Mega-X':
				case 'Mega-Y':
					this.modData('Pokedex', i).gen = 6;
					this.modData('Pokedex', i).isMega = true;
					this.modData('Pokedex', i).battleOnly = false;
					delete this.modData('FormatsData', i).requiredItem;
				}
			}
		}
	},
};
 

Users Who Are Viewing This Thread (Users: 1, Guests: 0)

Top