DouglasJordao
Villager
- Xy$
- 0.00
Well... I'm writing a plugin that checks for weapons in inventory and for equipped weapons, store them in an array,
take a random weapon and remove it from player (even if it's equipped). So far so good. The problem is, when I try to store the ID of the chosen weapon in a variable I got some messed numbers like 3001, 3010, The code works but the ID part don't.
Here it is. Don't mind this strange words, some of them are in Portuguese.
take a random weapon and remove it from player (even if it's equipped). So far so good. The problem is, when I try to store the ID of the chosen weapon in a variable I got some messed numbers like 3001, 3010, The code works but the ID part don't.
Here it is. Don't mind this strange words, some of them are in Portuguese.
JavaScript:
DataManager.roubarArma = function(variable){
var armaPool = [];
var armaEqpPool = [];
var partySize = $gameParty.size();
var total = $gameParty.weapons().length;
for (var i = 1; i <= partySize; i++) {
var actor = $gameActors.actor(i);
if(!actor.hasNoWeapons()){
if(actor.weapons()[0]){
armaEqpPool.push(actor.weapons()[0]);
}
if (actor.weapons()[1]){
armaEqpPool.push(actor.weapons()[1]);
}
}
}
if (total > 0){
for (var i = 0; i < total; i++) {
var arma = $gameParty.weapons()[i];
armaPool.push(arma);
}
}
if (armaEqpPool.length > 0){
for (var i = 0; i < armaEqpPool.length; i++) {
var arma = armaEqpPool[i];
armaPool.push(arma);
}
}
if (armaPool.length > 0){
var random = Math.floor(Math.random() * armaPool.length);
$gameParty.loseItem(armaPool[random], 1, true);
$gameVariables.setValue(variable, armaPool[random].id);
$gameMessage.add("Fulano roubou " + String(armaPool[random].name));
}
};