Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
dolarmak

get event location/check around event

Question

Okay, i've started working on this plugin that will check around the event that activates it for a specific event name. I'm using this for a scarecrow event that when the day starts the filed/plant events evaluate if the scare crow is around them and if not there is a chance the plant get destroyed.

now the problem i have is with the script getting the events location. When checking a specific coordinate, the script works fine, but when if asks for the events location I get crazy errors. I was told a line $gameMap.events()[this._eventId].x; should get the x coord for the event, but it doesn't seem to. same code switch x for y to get the Y coord. 

anyway, here is what I have so far. On lines 25 and 26 i set static numbers and commented out the dynamic xy. if any one knows whats wrong let me know.

/*:
* @author Dolarmak
* @plugindesc Checks if a scarecrow event is within 3 tiles of the event
*
* @help
* =============================================================================
* What does it do?
* =============================================================================
*
* Checks if a scarecrow event is within 3 tiles of the event
*
* =============================================================================
*/

var aliasPluginCommand = Game_Interpreter.prototype.pluginCommand;

Game_Interpreter.prototype.pluginCommand = function(command, args)
{
	aliasPluginCommand.call(this, command, args);
	
	if(command == "scarecrow")
	{
		//----- Check if Scarecrow Event is in range -----//
		//$gameMessage.add("checking");
		var sc_event_x = 4; //$gameMap.events()[this._eventId].x;
		var sc_event_y = 4; //$gameMap.events()[this._eventId].y;
		var sc_event_true = false;
		
		for(var sc_event_y_check = (sc_event_y - 3); sc_event_y_check < (sc_event_y + 4); sc_event_y_check = (sc_event_y_check + 1))
		{
			for(var sc_event_x_check = (sc_event_x - 3); sc_event_x_check < (sc_event_x + 4); sc_event_x_check = (sc_event_x_check + 1))
			{
				if ($gameMap.isXyHasEventName(/scarecrow/i,sc_event_x_check,sc_event_y_check) == 1)
				{
					var sc_event_true = true;
				}
				
			}
		}
		
		//----- End Result ----//	
		if (sc_event_true == true)
		{
			//----Scarecrow is in Range ----//
			//$gameMessage.add("Scarecrow detected");
			$gameSelfSwitches.setValue([this._mapId, this._eventId, 'A'], false);
			$gameSelfSwitches.setValue([this._mapId, this._eventId, 'B'], true);
		}
		else
		{
			//----Scarecrow is not in Range ----//
			//$gameMessage.add("No scarecrow detected");
			$gameSelfSwitches.setValue([this._mapId, this._eventId, 'A'], true);
			$gameSelfSwitches.setValue([this._mapId, this._eventId, 'B'], false);
		}
		
	}
	
}

	
	

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

What you need to do is use RMMV's built-in console. I only used it once, but you push a button or whatever. The really awesome thing about RMMV is that js is reasonably easy to debug because with the console you can evalute the whole object: all it's variables, all its functions. 

 

To make something come up in the console you use console.log, eg 

console.log($gameMap._events);

Since I'm building an MMO I just use the browser's console. Exact same thing :)

 

918ae4a95585f9678828b06c9ed89ff8.png

 

 

EDIT: Also not sure about your syntax. Try

$gameMap._events[this._eventId]._x;

I'm not that good with JS, but if you call .events(), then that's a function. Events contains a list of event objects, which you access via an index, so its .events[#] to access a specific event, then you can access that event's properties and functions. 

Share this post


Link to post
Share on other sites
  • 0

Thank you Marked! you were right i was the syntax and you have the right command! works perfect now! 

 

Apparently it's f8 for the debug btw lol

Edited by dolarmak

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...