I'm making an RPG, and I need to make a character dissapear when it dies. But I can't figure how to make a character dissapear depending of who I'm fighting with. For example: if I'm fighting John Doe I want John Doe to go to room 0 (die); if I'm fighting Mike Doe, I want him to go to room 0. What's the code for that?
My code so far is this:
Quotefunction winbattle ()
{
if (enemyHP<=0)
{
locname = Game.GetLocationName(mouse.x,mouse.y);
Display ("%d dies.", locname);
//here I want John or Mike to die, depending of who I'm fighting with.
}
}
How do I do??
That depends on how you're handling the fighting code. For example when you initiate a fight how does that code look? Are you storing any type of global variable (Character* or int ID or otherwise) to indicate which character you're currently fighting?
The general code for this would be something like (based on what you said):
cDie.ChangeRoom(0, -100000, -100000);
Knowing which character to send though appears to be your problem...which is why we need more information regarding your code to help with that specifically. ;)
There're lots of ways, depending on how you want to identify which character you're fighting with.
According to your codes it seems that you did this by checking the location names, so one possible way is:
function winbattle ()
{
if (enemyHP<=0)
{
locname = Game.GetLocationName(mouse.x,mouse.y);
Display ("%s dies.", locname);
//here I want John or Mike to die, depending of who I'm fighting with.
if (locname=="Mike") cMike.ChangeRoom(0); //Change the strings and character handles to match your own
else if (locname=="John") cJohn.ChangeRoom(0);
}
}
(locname is a String, not an integer, right? You need to use %s, not %d in the Display() line.)
You can also let the character dissapear by using the Transparency command:
http://www.americangirlscouts.org/agswiki/Character_functions_and_properties#Character.Transparency
Gilbet 'sidea worked. But it would be annoying if my character needed to fight 100 enemies. It would be easier to keep track of who I'm fighting with, with some sort of ID, or variable, or I don't know. :P THAT's what I need...
As to
monkey's question, I have the cursor "usermode 8" modyfied into "fight". Then on the section "unhandled event", whenever I click with the fight cursor on a character, it runs the "fight" function, which looks like this:
Quotefunction fight ()
{
locname = Game.GetLocationName(mouse.x,mouse.y);
Display ("You start to fight with %s.", locname);
dBattle.Start();
}
As you can see, that pops up a dialog, in which options are "fight", "pass", "run away" and "death". Death starts inactive.
Quote@S
return
@1
if ((life>0)&&(enemyslife>0))
{
attack();
}
if ((life>0)&&(enemyslife>0))
{
enemyattacks();
}
death();
return
@2
if ((life>0)&&(enemyslife>0))
{
rogerataca();
}
death();
return
@3
Display("You run like a coward piece of crap.");
stop
@4
stop
The "Death" function disables option 1, 2 and 3, and enables 4. So if you or your enemy dies, the dialog stops and then comes the starting code (winbattle and all that crap). That's all, I hope you can help me! Or make a new code, whatever... it isn't a game yet, it's just a demo game to test how to make and RPG and then make something good.
P.d: I had too translate all the functions and names and stuff from spanish... what a job.
So how many enemies are there in your game?
Well, I don't know yet... but they could be a thousand. That's why I need something handy.
Then maybe their dead could trigger the entrance of a new enemy?
In that case you can just use the same characters over and over again and just change their location when they die?
In unhandled_event, store the character under the mouse in a global pointer.
To do that, put
import Character*cFight;
in Global.ash and this above unhandled_event:
Character*cFight; export cFight;
In unhandled_event itself, add
cFight = Character.GetAtScreenXY(mouse.x, mouse.y);
Now all you need to do is call
cFight.ChangeRoom(0);
You can also use all the other properties, such as cFight.Name in messages.
You are a genius, Khris. That worked perfectly. Thanks a lot everyone!