The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => Topic started by: 104251 on May 12, 2014, 08:34:41 AM

Title: [RESOLVED][VX] Efficient eventing, distance checking and massive lag
Post by: 104251 on May 12, 2014, 08:34:41 AM
Hello.

As I'm not experienced in scripting, I do most of the things by eventing, and often it causes extreme lag ingame. I know there are ways to do things more efficiently, so I came here for your advice!

So what I want to do and how I managed it to work:

Pretty large field (17 by 29), covered in very tall grass.
Spoiler for:
(https://drive.google.com/uc?export=view&id=0B46TossVzc2neFhIbE16Q0dlaG8)
(Don't mind empty tiles, it's for testing - all of the tiles will be covered)

The grass reacts to player movements (splits when stepped on).
Spoiler for:
(https://drive.google.com/uc?export=view&id=0B46TossVzc2nTF9lVDlkMGtxaUU)

Insects can attack, if player steps on the wrong tile (there is a safe path, it can be navigated by carefully observing your surroundings - if grass moves near you, don't step there). If player gets caught again and again, attacks get progressively harder.

You can (if you want to) burn the whole field, but that will summon a tough boss.
The fire should start at the center (wherever the player stands at) and go to the sides, until all of the grass is burned.

-----------------------
I've managed to do all of it, but the last part gave me some trouble. How it works:
First, the switch turns on (triggers everything else below)
Then the ticker goes off as parallel process (it adds every 5 frames and counts from 1 to 29 - that's for the distance checking)
Spoiler for:
(https://drive.google.com/uc?export=view&id=0B46TossVzc2nSlY5WGRLRGdBUWs)

As it ticks, every (!) grass event checks if it's distance from the player is equal to ticker - if yes, then grass tile burns off.
Spoiler for:
(https://drive.google.com/uc?export=view&id=0B46TossVzc2nQV8xeHpudkdXYU0)

The result looks pretty nice - fire goes off in a circle from the player to the sides of the field.
Spoiler for:
(https://drive.google.com/uc?export=view&id=0B46TossVzc2nUjBtRDU5UkdVbUU)

(https://drive.google.com/uc?export=view&id=0B46TossVzc2nMDZsTkE1S2ZXNFU)

For distance checking I used Distance script by Jet:

Spoiler for:
Code: [Select]
class Game_Interpreter

  def tiles_away?(dist, char = -1)
    ev = get_character(0)
    char = get_character(char)
    (ev.x - char.x).abs + (ev.y - char.y).abs < dist
  end
end
So when every event on the map starts to do those script calls, it lags like hell. (duh)

UPDATE: It's resolved. Redone it with no lag. Thanks all for reading)