Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------
- // GB_stepPuzzle.js
- // Copyright (c) 2024 GBison. All rights reserved.
- // Released under the MIT license.
- // http://opensource.org/licenses/mit-license.php
- //=========================================================
- /*:
- * @plugindesc Combo System By Checking the Switch.
- * @author Gbison
- * @version 1
- *
- * @param Plugin Version
- * @desc Version for the Plugins
- *
- * @param Version
- * @type number
- * @default 0
- * @parent Plugin Version
- *
- * @param Position
- * @desc Variable To position
- *
- * @param Last Player Stand X
- * @desc Last Chara Position
- * @type variable
- * @default 11
- * @parent Position
- *
- * @param Last Player Stand Y
- * @desc Last Chara Position
- * @type variable
- * @default 12
- * @parent Position
- *
- * @param Default Parameter
- * @desc Parameter To Use
- *
- * @param Max Step
- * @desc Max Step Player can Move
- * @type Number
- * @default 6
- * @parent Default Parameter
- *
- * @param Switch Parameter
- * @desc Switch for Puzzle
- *
- * @param Warning Switch
- * @desc must turn OFF. Turn On if the step is more than Max Step
- * @type Switch
- * @default 11
- * @parent Switch Parameter
- *
- * @help
- * Copyright (c) 2024 GBison. All rights reserved.
- * Released under the MIT license.
- * ===================================================================
- * The Idea from JoeBumpster
- * https://forums.rpgmakerweb.com/index.php?threads/no-idea-why-this-switch-wont-flip.168634/
- * To use this, just run plugin
- * GB_stepPuzzle Example : to run example
- * GB_stepPuzzle LastPosition : save player last position
- * GB_stepPuzzle StepPuzzle 6 : to run the Step. If the step more than 6!! The switch
- * will ON. turn Off using event
- */
- (function() {
- // parameters
- var _thisPluginName = 'GB_stepPuzzle'; //change with your filename.
- var parameters = PluginManager.parameters(_thisPluginName);
- var _ver_gb = {
- "switch": Number(parameters['Plugin Version'] || 10),
- "variable": Number(parameters['Version'] || 10)
- };
- var _maxStep = Number(parameters['Max Step'] || 6);
- var _lastPosX = Number(parameters['Last Player Stand X'] || 11);
- var _lastPosY = Number(parameters['Last Player Stand Y'] || 12);
- var _warningSwitch = Number(parameters['Warning Switch'] || 11);
- var _playerBefore = {
- "x": 0,
- "y": 0,
- "dir":0
- }
- var _playerLast = {
- "x": 0,
- "y": 0,
- "dir":0
- }
- var cek=0;
- var isMoveVertical = [2, 8];
- var isMoveHorizontal = [4, 6];
- var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
- Game_Interpreter.prototype.pluginCommand = function(command, args) {
- _Game_Interpreter_pluginCommand.call(this, command, args);
- runPlugins = false;
- if (command === 'GB_stepPuzzle') {
- switch (args[0]) {
- case 'Example':
- $gameSystem.GB_example();
- runPlugins = [command, args];
- break;
- case 'LastPosition':
- player = $gamePlayer;
- console.log('last pos');
- $gameVariables.setValue( _lastPosX, player._x );
- $gameVariables.setValue( _lastPosY, player._y );
- $gameSystem.GB_saveBeforePosition( player._x, player._y, 0 );
- console.log('GB_saveLastPosition');
- $gameSystem.GB_saveLastPosition( player._x, player._y, 0 );
- runPlugins = [command, args];
- break;
- case 'StepPuzzle':
- player = $gamePlayer;
- $gameSystem.GB_StepPuzzle( args[1] );
- runPlugins = [command, args];
- $gameSystem.GB_saveBeforePosition( player._x, player._y, player._direction );
- $gameSystem.GB_debug(runPlugins, true);
- break;
- }
- }
- //$gameSystem.GB_debug( runPlugins );
- };
- Game_System.prototype.GB_StepPuzzle = function( step=0 ) {
- if( step > 0 ){
- _maxStep = step;
- $gameSystem.GB_debug( ['step', _maxStep ]);
- }
- if( _playerLast.dir != 0){
- if( _playerLast.x != player._x && _playerLast.y != player._y){
- //new position
- player = $gamePlayer;
- $gameSystem.GB_debug( 'newPos1');
- $gameSystem.GB_saveLastPosition( player._x, player._y, player._direction );
- $gameSystem.GB_debug( 'newPos2');
- }
- else{
- var posNow = 0;
- var posLast = 0;
- var updatePosition = false;
- player = $gamePlayer;
- if( isMoveVertical.includes( player._direction ) ){
- posNow = player._y;
- posLast = $gameVariables.value( _lastPosY);
- $gameSystem.GB_debug('ver');
- updatePosition = player._x != $gameVariables.value( _lastPosX );
- }
- else if( isMoveHorizontal.includes( player._direction ) ){
- posNow = player._x;
- posLast = $gameVariables.value( _lastPosX );
- $gameSystem.GB_debug('hor');
- updatePosition = player._y != $gameVariables.value( _lastPosY );
- }else{
- $gameSystem.GB_debug( ['else', isMoveHorizontal, isMoveVertical, _playerLast.dir] );
- }
- if( !updatePosition ){
- $gameSystem.GB_debug('beda dir ' + _playerLast.dir);
- updatePosition = _playerLast.dir != player._direction;
- }
- if( updatePosition ){
- $gameSystem.GB_debug('update pos');
- $gameSystem.GB_saveLastPosition( _playerBefore.x, _playerBefore.y, _playerBefore.direction );
- }
- distance = Math.abs( posNow - posLast );
- if( distance >= _maxStep ){
- $gameSwitches.setValue(_warningSwitch, true);
- }
- $gameSystem.GB_debug( ['update' ,posNow, posLast, distance, _maxStep ]);
- }
- }else{
- _playerLast.dir = player._direction;
- //console.log('save', player);
- }
- };
- Game_System.prototype.GB_saveBeforePosition = function( x=0, y=0, dir=0 ) {
- _playerBefore = {
- "x": x,
- "y": y,
- "dir": dir
- };
- $gameSystem.GB_debug(['before',_playerBefore]);
- };
- Game_System.prototype.GB_saveLastPosition = function( x=0, y=0, dir=0 ) {
- $gameVariables.setValue( _lastPosX, x );
- $gameVariables.setValue( _lastPosY, y );
- _playerLast.dir = dir;
- $gameSystem.GB_debug('saveLastPosition');
- $gameSystem.GB_debug(['save', x, y, dir]);
- };
- Game_System.prototype.GB_example = function() {
- let ev = $gameMap;
- let actor = $gameActors;
- let party = $gameParty;
- let player = $gamePlayer;
- //console.log('event', _thisPluginName, ev);
- //console.log('actor', actor, party, player);
- if( _playerLast.x != player._x || _playerLast.y != player._y){
- console.log(player._x, player._y, player._direction, cek);
- _playerLast.x = player._x;
- _playerLast.y = player._y;
- _playerLast.dir = player._direction;
- //down:2; up:8; left:4; right:6;
- }
- };
- //$gameSystem.GB_debug();
- Game_System.prototype.GB_debug = function( status="-", save=false ) {
- let player = $gamePlayer;
- if( _playerLast.x != player._x || _playerLast.y != player._y){
- let savePos =[ posLast = $gameVariables.value( _lastPosX ), posLast = $gameVariables.value( _lastPosY ) ];
- console.log([status, player, _playerLast, savePos, cek]);
- cek ++;
- if( save || _playerLast.x == 0 || _playerLast.y == 0 ){
- _playerLast.x = player._x;
- _playerLast.y = player._y;
- console.log(_playerLast, player);
- }
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement