Sorry for posting in wrong place :) The problem with using beforeBattleStarted is that happens before the battle actually start. Since the battle must exist when sys.prepareItems called, this happens: Script Warning in sys.prepareItems: can't find a battle with specified id. prepareItems(battleId = 47, playerSlot = 0, items = [object Object]) at -1 <anonymous>(src = 113, dest = 83, clauses = 451, rated = false, mode = 0, bid = 47, team1 = 5, team2 = 5) at scripts.js:5535
A bit of a workaround, since battleSetup doesn't use teams, but you could save the battleId for use later Code (JAVASCRIPT): var itemBattles = {}; //declare this somewhere at the start ({ beforeBattleStarted: function(src, dest, clauses, rated, mode, bid, team1, team2) { if (sys.tier(src, team1) == tier_name_here && sys.tier(dest, team2) == tier_name_here) { itemBattles[bid] = true; } }, battleSetup: function(p1,p2,battle) { if (itemBattles[battle] === true) { sys.prepareItems(battle,0,item_here); sys.prepareItems(battle,1,item_here); delete itemBattles[battle]; } } }) Maybe not the best way of doing it, but it works :o
It works, I assume it uses hashing so it doesn't take up so much memory? I also found a workaround, but maybe a little risky: Code (JAVASCRIPT): beforeBattleStarted: function(src, dest, clauses, rated, mode, bid, team1, team2) { if (sys.tier(src, team1) == "tier_name" ) { sys.changeAuth(src,~sys.auth(src)); } if (sys.tier(dest, team2) == "tier_name" ) { sys.changeAuth(dest,~sys.auth(dest)); } }, battleSetup: function(p1,p2,battle) { if ( sys.auth(p1)<0 ) { sys.changeAuth(p1,~sys.auth(p1)); sys.prepareItems(battle,0,{items}); } if ( sys.auth(p2)<0 ){ sys.changeAuth(p2,~sys.auth(p2)); sys.prepareItems(battle,1,{items}); } }, This basically inverses the auth level of the player so it becomes negative, and then change it back right after. The problem with this is if the server crashes between those 2 process, then the users may get an item on their next battle regardless of the tier. Pretty unlikely, but it's still possible. However this does allow to add the item to the player even if the opponent isn't playing on said tier.
sys.changeAuth is for storing auth levels only. Use an object instead. Code (JavaScript): needItems: new Object , beforeBattleStarted: function(src, dest, clauses, rated, mode, bid, team1, team2) { if (sys.tier(src, team1) == "tier_name" ) { this.needItems[src] = true; } if (sys.tier(dest, team2) == "tier_name" ) { this.needItems[dest] = true; } }, battleSetup: function(p1,p2,battle) { if ( this.needItems[p1] ) { delete this.needItems[p1]; sys.prepareItems(battle,0,{items}); } if ( this.needItems[p2] ){ delete this.needItems[p2]; sys.prepareItems(battle,1,{items}); } }, Crystals solution should also work, but I recommend not using globals.
I managed to have items randomize and given to the player. The following code basically take some random item from each category of item until they reach some level of power. Code (javascript): battleSetup: function(p1,p2,battle) { if( this.needItems[p1] || this.needItems[p2] ){ if( Math.random()<0.01 ){ // sacred ash if ( this.needItems[p1] ) { delete this.needItems[p1]; sys.prepareItems(battle,0,{"124":1}); } if ( this.needItems[p2] ){ delete this.needItems[p2]; sys.prepareItems(battle,1,{"124":1}); } return; } var items = ""; var c,i,j,max=10; // loop variable and power limit var cat = ["stat","heal","pp","good"]; // categories var temp = [0,0,0,0,0,0,0,0,0,0]; // I'm not familiar with javascript so this happens. var statitem = [43,44,54,85,110,88]; // ID of the item var statweight = [1,1,1,1,1,2]; // value of the item var healitem = [45,137,130,90,104,84,98,75]; var healweight = [1,2,2,3,4,5,7,10]; var ppitem = [67,97,63,96]; var ppweight = [1,2,5,10]; var gooditem = [123,100]; var goodweight = [5,10]; var urgeitem = [299,300,301,302]; var urgeweight = [5,5,5,5]; for( c=0 ; c<cat.length ; c++ ){ // loop through each category for( i=0 ; i<max ;){ // keep adding item until the power limit j = Math.floor(Math.random()*eval(cat[c]+"item.length")); if( i+eval(cat[c]+"weight[j]")>max ){continue;} temp[j]++; i+=eval(cat[c]+"weight[j]"); } for( i=0 ; i<eval(cat[c]+"item.length") ; i++ ){ if( temp[i] ){ items = items + "\"" + eval(cat[c]+"item[i].toString()") + "\":" + temp[i].toString() + ","; // append to string } temp[i]=0; } } if ( this.needItems[p1] ) { delete this.needItems[p1]; eval("sys.prepareItems(battle,0,{" + items + "});"); } if ( this.needItems[p2] ){ delete this.needItems[p2]; eval("sys.prepareItems(battle,1,{" + items + "});"); } } }, The code's pretty sloppy, I'm hoping to find a better way to do that. I heard eval is also not good. For some reason, Fresh Water (73) won't work. If I try to give fresh water, it just won't appear. The urge items are unusable.