PDA

View Full Version : Warps(Sphere)


Booda Sack
May 29th, 2005, 01:12 PM
Hey everyone here are some more sphere scripts for you.
Theese are essential for any rpg and indeed most games.

First include some system scripts:

EvaluateSystemScript("time.js");
EvaluateSystemScript("screen.js");



Then your basic warp:

function Warp(x, y, layer, map,retain,person) {
//note layer is the layer number not name,eg 0 is first layer,1 is second etc
if (map) ChangeMap(map);
SetPersonLayer(person, layer);
SetPersonX(person, x);//Pixel not tile;
SetPersonY(person, y);//Pixel not tile;
SetPersonDirection(person,retain);
/*To warp to a tile you would enter the tile x and y and then multiply that by your tile size ,you might have to add or take away a few pixels depending on your sprites obstruction base*/

}



Usage:

Warp(169,375, 1, "Route1.rmp","south","hero");


More usefull warp:

function FancyWarp(x, y, layer, map,retain,person) {

//Detach input so the person doesn't walk while you are warping
DetachInput();


FadeOut(1000);//Fade screen to black
// 1000 milliseconds = 1 second.
Warp(x, y, layer, map,retain,person); // use the original warp function
UpdateMapEngine();
RenderMap();
FadeIn(1000);
AttachInput("hero");

}




Usage:
FancyWarp(169,375, 1, "Route1.rmp","south","hero");

Here is an extra function that is handy when you want test maps,and dont want keep turning off the game and reseting your start position.

BindKey (KEY_M, "typemap()", "t()"); //Bind the M key to this function

function typemap()
{

var gotomap;

if (IsMapEngineRunning()) // Check if the map engine is running
RenderMap(); //If yes then display the map

//Different text function to the one I posted yesterday check below
NText("Which Map : ",16,214);

//Type the map filename name,it is case sensitive
//This is getting the filename so remember to type the map file extension
// for sphere which is .rmp
gotomap = GetString(16,214,LoadFont("epokefont.rfn"));

if (IsMapEngineRunning())
RenderMap();

NText("X value : ",16,214)
//Type the x value
var x = GetString(16,214,LoadFont("epokefont.rfn"));

if (IsMapEngineRunning())
RenderMap();

NText("Y value : ",16,214)
//Type the Y value
var y = GetString(16,214,LoadFont("epokefont.rfn"));

//Warp to the map
FancyWarp(x, y, 1, gotomap,"north","hero")

//You could mod this to get the direction too.
//Also you may want to change the x and y in each of the GetStrings()
//To suit where your text box is displayed.

}

Text function:

function NText(str,x,y)
{
/*Similar to the text function the previous tutorial but adapted so it displays right when getting input*/

var myfont = LoadFont("epokefont.rfn");
var windowstyle = LoadWindowStyle("grey2.rws");

var width = GetScreenWidth() - 32;
var height = myfont.getStringHeight(str, width);
windowstyle.drawWindow(x, y, width, height);
myfont.drawTextBox(x, y, width, height, 0, str);

/*not ther is no FlipScreen() wait for Ctrl key like the last one because this is taken care of by the GetString() function*/

}

BlackCharizard
May 31st, 2005, 06:10 AM
I dont understand this at all. What does this help with?

Booda Sack
May 31st, 2005, 07:32 AM
Read the title of the topic,warps.
I don't mean this offensively but if you don't understand this,you should maybe regress and try something easier.

sphereslayer
June 4th, 2005, 01:34 AM
I couldnt get the "FancyWarp" to work how it was so I had to add together the Warp and FancyWarp. If anyones having troubles with this, this is what i changed it to and it worked: function Warp(x, y, layer, map,retain,person)
{

DetachInput();
FadeOut(1000);
if (map) ChangeMap(map);
SetPersonLayer(person, layer);
SetPersonX(person, x);//Pixel not tile;
SetPersonY(person, y);//Pixel not tile;
SetPersonDirection(person,retain);
UpdateMapEngine();
RenderMap();
FadeIn(500);
AttachInput("Player");

}

and the usage code was just the Warp one:

Warp(169,375, 1, "Route1.rmp","south","hero");

Thanks Booda this would've takin me ages to figure out.

Booda Sack
June 4th, 2005, 08:00 AM
What was the error?
You must have been using it wrong because that's the exact function I've used in my game since the beginning and it works fine for me.

sphereslayer
June 4th, 2005, 09:40 AM
it just continuously looped like the screen would fade but then it would take me back to the same point wher my warp was and then fade again n then bring me back ontop of the warp again . . . . . .. . . . .

Booda Sack
June 4th, 2005, 04:17 PM
Oh ok,you were probably just warping onto the warp trigger on the next map which would then warp onto the warp trigger of the previous map which would then warp onto the warp trigger of the next map which would then warp onto the warp trigger of the previous map which would then warp onto the warp trigger of the next map ....
etc.

sphereslayer
June 5th, 2005, 12:05 AM
meh i wouldnt have a clue what i was doing . . something stupid no doubt. . . im new to sphere so yeh lol soz my bad

Booda Sack
June 5th, 2005, 06:57 AM
Nah thats ok,thats the whole point of this is to help people.