I tried to write a plugin that will create new events in radius from an existing events, for example chopping wood will create logs around stump. What do I do wrong?
It creates a picture (and event is listed as event) but it creates event on 0,0 position. Why? Even if x and y are defined, the events pops on 0,0. Please help me. Is there a simple way to create event, or I need to define all that const pageEvent's conditions?
Code:
//=============================================================================
// Fizzly_dropItems.js
//=============================================================================
(function () {
var dropItems = {
wood1: 24,
};
/**
* Game_Interpreter
*/
var _fizzly_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
_fizzly_Game_Interpreter_pluginCommand.call(this, command, args);
var that = this;
if (command == 'dropItems') {
that.dropItems(args);
}
};
/**
* runs command action
*/
Game_Interpreter.prototype.dropItems = function (args) {
const items = args.length;
for (var i = 1; i < items; i++) {
const item = args[i].split(',');
this.dropItem(item[0], item[1])
}
};
Game_Interpreter.prototype.dropItem = function (itemId, count, radius = 1) {
const center = this.getClosestTile($gamePlayer.x, $gamePlayer.y, $gamePlayer.direction());
const event = this.createEvent();
console.log( "------------------------------------" )
console.log( $gameMap.events() )
$gameMap._events.push(event);
// $gameMap.event(event._eventId).setImage('!$log', 1);
}
Game_Interpreter.prototype.getClosestTile = function (playerX, playerY, direction) {
switch (direction) {
case 2:
return {x: playerX, y: playerY + 1};
case 4:
return {x: playerX - 1, y: playerY};
case 6:
return {x: playerX + 1, y: playerY};
case 8:
return {x: playerX, y: playerY - 1};
}
throw new Error('Unknown direction type')
}
Game_Interpreter.prototype.createEvent = function () {
const event = new Game_Event(3, $dataMap.events.length);
const pageEvent = {
conditions: {
actorId:1,
actorValid:false,
itemId:1,
itemValid:false,
selfSwitchCh:"A",
selfSwitchValid:false,
switch1Id:1,
switch1Valid:false,
switch2Id:1,
switch2Valid:false,
variableId:1,
variableValid:false,
variableValue:0
},
list: [
{ code:0, indent: 0, parameters: []}
],
customPageCondition:[],
directionFix:false,
image: { characterIndex: 0, characterName: "!$log", direction: 2, pattern:1, tileId:0 },
priorityType: 1,
moveSpeed:3,
moveType:0,
stepAnime:false,
through:false,
trigger:0,
walkAnime:true
}
event.event().pages.push(pageEvent)
// event.event().pages = [pageEvent]
event.event().x = $gamePlayer.x - 2;
event.event().y = $gamePlayer.y;
event.setPosition($gamePlayer.x - 2, $gamePlayer.y);
event.refresh();
return event;
}
})();
It creates a picture (and event is listed as event) but it creates event on 0,0 position. Why? Even if x and y are defined, the events pops on 0,0. Please help me. Is there a simple way to create event, or I need to define all that const pageEvent's conditions?