Colin
22-09-09, 05:45 PM
here is the info and code to add multi-character switching into a game
as used in summer blast dizzy.
firstly you need to add those characters to your map!
place them all in their start positions. Dizzy's exact start location isn't as important,
as the player initial start position, is still controlled by beginx and beginy in gamedef.gs
each one is an actionable dynamic object and for the code to work with the right tiles,
you need to set them up with the right ID numbers.
1 Dizzy
2 Daisy
3 Dylan
4 Denzil
5 Dora
6 Dozy
7 Grand Dizzy
you don't need to use all of them(except for dizzy)
***BUT***
those that you do, must have the right id
once that is done, you can start adding the switching functions that will
be called by your game,into game.gs
The first function will save the existing player id and inventory, then paste the character
as an actionable object again
func OldChar()
{
i=0;
PlayerSet(P_DISABLE,1); //pause player
OldCharScuba(); //checks to see if wearing scuba
count = InventoryCount();
chrx = ObjFind(chr); //
ObjSet(ObjFind(1),O_USER+10,chr); //saves last character id
x = PlayerGet(P_X);
y = PlayerGet(P_Y); //finds player x and y location
ObjSet(chrx,O_X,x-12); //
ObjSet(chrx,O_Y,y-14); //replaces player with last character tile
ObjSet(chrx,O_DISABLE,0); //
ObjPresent(chrx); //
ObjSet(chrx,O_USER+11,count); //saves number of items in inventory
if(count>0)
{
for(i=count-1;i>=0;i--) //
{
idx = InventoryGet(i); //saves each item id to
chrx = ObjFind(chr); //that characters id
ObjSet(chr,O_USER+i,idx); //user variables
}
}
InventoryClear(); //wipes current inventory ready for new character
return;
}
The next function will load the new player inventory and set the costume to the new character
func NewChar()
{
i=0;
chrx = ObjFind(chr); //
count = ObjGet(chrx,O_USER+11); //calls up number of items new character holds
x = ObjGet(chrx,O_X); //
y = ObjGet(chrx,O_Y); //finds new character x and y location
scb = ObjFind(chr);
chrf = ObjGet(scb,O_TILE); //finds new characters idle tile
ObjSet(ObjFind(1),O_USER+10,chr);//saves new player id
PlayerSet(P_TILE,chrf); //switches player tile to new idle tile
c=PlayerGet(P_COSTUME);
if(c==330)
{
PlayerSet(P_TILE,340); //initially switches to scuba tile if previously wearing
}
PlayerSet(P_COSTUME,chrf);
PlayerSet(P_X,x+12); //
PlayerSet(P_Y,y+14); //moves to new characters location
if(count>0)
{
for(i=count-1;i>=0;i--) //loads each item id from
{
idx = ObjGet(chr,O_USER+i); //that characters id
GameSet(G_INVENTORY+i,idx); //user variables
}
}
chrx = ObjFind(chr);
ObjSet(chrx,O_DISABLE,1); //disables new characters action tile
GamePause(0);
PlayerSet(P_DISABLE,0); //re enable player control
return;
}
This next function checks if the player is carrying the scuba, if so then the actionable object will appear
still wearing it!
func OldCharScuba()
{
scuba = 0;
if(ID_SCUBA!=-1) scuba = InventoryHasItem(ID_SCUBA) ? 30 : 0;//offset tiles by 30 with scuba
if(chr==1) scuba+=10; //dizzy tile set start from 10 onwards
if(chr==2) scuba+=310; //daisy tile set start from 310 onwards
if(chr==3) scuba+=360; //dylan tile set start from 360 onwards
if(chr==4) scuba+=410; //denzil tile set start from 410 onwards
if(chr==5) scuba+=460; //dora tile set start from 460 onwards
if(chr==6) scuba+=510; //dozy tile set start from 510 onwards
if(chr==7) scuba+=560; //g dizzy tile set start from 560 onwards
scb = ObjFind(chr);
ObjSet(scb,O_TILE,scuba); //switches action tile to the right costume
}
Now in the func BeginNewGame() in game.gs
you need to add 4 lines to initialize the player start id
chr = 1; //initialises dizzy as start character
chrx = ObjFind(chr);
ObjSet(chrx,O_DISABLE,1); //disables dizzys action tile
ObjSet(ObjFind(1),O_USER+10,chr); //initialises dizzy for load/save
also in game.gs you need to add the inventory saving to the load/save game
so that you will continue with the right items on reloading.
in func SaveUserData( file ), add
func SaveUserData( file )
{
//..
return 1;
}
and func LoadUserData( file )
func LoadUserData( file )
{
chr = ObjGet(ObjFind(1),O_USER+10); //calls switch to that character
return 1;
}
that is it for the game.gs for the moment!
you now need to add some code into the handlers.gs file
this code will always make sure the player tile is set to the right character id's
look for the func HandlerPlayerUpdate()
and replace the // Player set costume section with
costume = 0;
if(chr==1)
{
if(ID_SCUBA!=-1) costume = InventoryHasItem(ID_SCUBA) ? 30 : 0;
}
if(chr==2) costume+=300;
if(chr==3) costume+=350;
if(chr==4) costume+=400;
if(chr==5) costume+=450;
if(chr==6) costume+=500;
if(chr==7) costume+=550;
PlayerSet(P_COSTUME,costume);
this is where dizzyage updates the player costume!
also important, in gamedef.gs
you will need to set a global variable for chr so all the scripts can see it
so add
#def chr 7
i added mine at the top of the list
now back to game.gs and actually switching between characters in game!
say you were another character and you wanted to switch to daisy
here is the basic code to switch.
/////////////////////////////////////////////////////////////////////
//daisy switch
func ActionObject_2()
{
OldChar(); //calls the old character save function
chr=2; //sets chr variable to the daisy id
NewChar(); //loads new character chr id as player
}
this you can expand upon, so it can display messages when switching.
you can also for instance, use status checks to disable or enable
the switching to each character as your game progresses.
have fun!
as used in summer blast dizzy.
firstly you need to add those characters to your map!
place them all in their start positions. Dizzy's exact start location isn't as important,
as the player initial start position, is still controlled by beginx and beginy in gamedef.gs
each one is an actionable dynamic object and for the code to work with the right tiles,
you need to set them up with the right ID numbers.
1 Dizzy
2 Daisy
3 Dylan
4 Denzil
5 Dora
6 Dozy
7 Grand Dizzy
you don't need to use all of them(except for dizzy)
***BUT***
those that you do, must have the right id
once that is done, you can start adding the switching functions that will
be called by your game,into game.gs
The first function will save the existing player id and inventory, then paste the character
as an actionable object again
func OldChar()
{
i=0;
PlayerSet(P_DISABLE,1); //pause player
OldCharScuba(); //checks to see if wearing scuba
count = InventoryCount();
chrx = ObjFind(chr); //
ObjSet(ObjFind(1),O_USER+10,chr); //saves last character id
x = PlayerGet(P_X);
y = PlayerGet(P_Y); //finds player x and y location
ObjSet(chrx,O_X,x-12); //
ObjSet(chrx,O_Y,y-14); //replaces player with last character tile
ObjSet(chrx,O_DISABLE,0); //
ObjPresent(chrx); //
ObjSet(chrx,O_USER+11,count); //saves number of items in inventory
if(count>0)
{
for(i=count-1;i>=0;i--) //
{
idx = InventoryGet(i); //saves each item id to
chrx = ObjFind(chr); //that characters id
ObjSet(chr,O_USER+i,idx); //user variables
}
}
InventoryClear(); //wipes current inventory ready for new character
return;
}
The next function will load the new player inventory and set the costume to the new character
func NewChar()
{
i=0;
chrx = ObjFind(chr); //
count = ObjGet(chrx,O_USER+11); //calls up number of items new character holds
x = ObjGet(chrx,O_X); //
y = ObjGet(chrx,O_Y); //finds new character x and y location
scb = ObjFind(chr);
chrf = ObjGet(scb,O_TILE); //finds new characters idle tile
ObjSet(ObjFind(1),O_USER+10,chr);//saves new player id
PlayerSet(P_TILE,chrf); //switches player tile to new idle tile
c=PlayerGet(P_COSTUME);
if(c==330)
{
PlayerSet(P_TILE,340); //initially switches to scuba tile if previously wearing
}
PlayerSet(P_COSTUME,chrf);
PlayerSet(P_X,x+12); //
PlayerSet(P_Y,y+14); //moves to new characters location
if(count>0)
{
for(i=count-1;i>=0;i--) //loads each item id from
{
idx = ObjGet(chr,O_USER+i); //that characters id
GameSet(G_INVENTORY+i,idx); //user variables
}
}
chrx = ObjFind(chr);
ObjSet(chrx,O_DISABLE,1); //disables new characters action tile
GamePause(0);
PlayerSet(P_DISABLE,0); //re enable player control
return;
}
This next function checks if the player is carrying the scuba, if so then the actionable object will appear
still wearing it!
func OldCharScuba()
{
scuba = 0;
if(ID_SCUBA!=-1) scuba = InventoryHasItem(ID_SCUBA) ? 30 : 0;//offset tiles by 30 with scuba
if(chr==1) scuba+=10; //dizzy tile set start from 10 onwards
if(chr==2) scuba+=310; //daisy tile set start from 310 onwards
if(chr==3) scuba+=360; //dylan tile set start from 360 onwards
if(chr==4) scuba+=410; //denzil tile set start from 410 onwards
if(chr==5) scuba+=460; //dora tile set start from 460 onwards
if(chr==6) scuba+=510; //dozy tile set start from 510 onwards
if(chr==7) scuba+=560; //g dizzy tile set start from 560 onwards
scb = ObjFind(chr);
ObjSet(scb,O_TILE,scuba); //switches action tile to the right costume
}
Now in the func BeginNewGame() in game.gs
you need to add 4 lines to initialize the player start id
chr = 1; //initialises dizzy as start character
chrx = ObjFind(chr);
ObjSet(chrx,O_DISABLE,1); //disables dizzys action tile
ObjSet(ObjFind(1),O_USER+10,chr); //initialises dizzy for load/save
also in game.gs you need to add the inventory saving to the load/save game
so that you will continue with the right items on reloading.
in func SaveUserData( file ), add
func SaveUserData( file )
{
//..
return 1;
}
and func LoadUserData( file )
func LoadUserData( file )
{
chr = ObjGet(ObjFind(1),O_USER+10); //calls switch to that character
return 1;
}
that is it for the game.gs for the moment!
you now need to add some code into the handlers.gs file
this code will always make sure the player tile is set to the right character id's
look for the func HandlerPlayerUpdate()
and replace the // Player set costume section with
costume = 0;
if(chr==1)
{
if(ID_SCUBA!=-1) costume = InventoryHasItem(ID_SCUBA) ? 30 : 0;
}
if(chr==2) costume+=300;
if(chr==3) costume+=350;
if(chr==4) costume+=400;
if(chr==5) costume+=450;
if(chr==6) costume+=500;
if(chr==7) costume+=550;
PlayerSet(P_COSTUME,costume);
this is where dizzyage updates the player costume!
also important, in gamedef.gs
you will need to set a global variable for chr so all the scripts can see it
so add
#def chr 7
i added mine at the top of the list
now back to game.gs and actually switching between characters in game!
say you were another character and you wanted to switch to daisy
here is the basic code to switch.
/////////////////////////////////////////////////////////////////////
//daisy switch
func ActionObject_2()
{
OldChar(); //calls the old character save function
chr=2; //sets chr variable to the daisy id
NewChar(); //loads new character chr id as player
}
this you can expand upon, so it can display messages when switching.
you can also for instance, use status checks to disable or enable
the switching to each character as your game progresses.
have fun!