Sign in to follow this  
raptorstrike

how would you go about doing this?

Recommended Posts

LONG WINDED SKIP TO BOTTOM FOR CONDESED VERSION ok im making an rpg and im doing pretty good in fact the only part of the machanics i have left to do is the Events and the Battle system (i know its a big part but i havnt even attempted it yet, im not putting it off i just think that it build off the other stuff) any way my real question lies in my Events. Eveny rpg has trigger events and things you have to do in a certin order but im not quite sure how to set this up. should i even have an event class or should i have a bunch of bools, it would be easyer to have an oop aproch but each bool will change baised on varying cercumstances like (Health > 2) or what ever but (as i found out with a thread yesterday) there isnt a way to give an expression as a paramater or store it in a variable in such a way so that it can be read back and used for comparisson. So now i dont know how im going to do this. ever event is going to be unique, i cant possible overload a ton of functions for them, i would have an an external array of expressions but you cant treat an expression as a single entite. any way as you can see i have a bunch of thoughts racing around in my mind but the good ones are dead ends and the ones that work just arnt practical for a game of the size this one will end up being. if any one has had previous experience making an rpg and how they did it. CONDENSED VERSION: im having trouble comming up with a good event system for my RPG what did you do or do you have any ideas? thanks[grin]

Share this post


Link to post
Share on other sites
I'd recommend an event/listener pair system. Set up a list of entities in the world that can generate events: characters, traps, animated props, etc. and list all the events they might trigger (dying, getting set off, etc.). Give each entity and event an ID; methods like "character.attacked" and "character.death" are good and flexible, while ID numbers like 488582 are evil.

Now set up a "listener" table on each object. Track the event that the listener is interested in, and a method of notifying that listener. For example, your listener might want to know when "trap.activated" happens, and ask that the value 42 be sent to CSomeObject::SomeFunction() when the event occurs. This is great if you have a scripting engine built into your game, because you can have specific scripts called for different events.

The final step is to notify your listeners when an event occurs. For example, when you detect that the character BigHugeBalrog has been struck by the player's +1 Stick of Beating, check the listener table on the BigHugeBalrog. For each listener, trigger the notification mechanism and move on; you might call "pMonster->TakeDamageFromWeapon(STICK_OF_BEATING)" for example, or if you have a scripting engine, call "MonsterAttacked(Balrog, stick-o-beating)"

This way is very easy on the processor - things that want to know when events occur don't have to continually check to see if those events have happened. It's also very, very flexible, as you can have multiple listeners that are all notified dynamically of certain events.

Share this post


Link to post
Share on other sites
also for the method you were explaining above how would you go about activating for example trap.activate would you use an if statement and if so isnt that ALOT of if statemets if you do one for every event?? would that have to have its own condition for being activated and if so this kind of leads me back to my origonal problem. i guess i could write a long tedious array of if statements if there was no alternative

Share this post


Link to post
Share on other sites
Not really. Research function pointers. Store the information about your listeners as in a class (or struct) that contains a string with the event name and a function pointer. Then you can have a function like this:



void CSomeObject::EventHappens(string EventName)
{
int i;
for(i = 0; i < NumberOfListeners; i++)
{
if(ListenerInfo[i].ListenEventName == EventName)
*(ListenerInfo[i].FunctionPointer)(this, EventName);
}
}


// Somewhere else
void CSomeThing::SomeListenerFunction(CSomeObject *pObject, string EventName)
{
if(EventName == "death")
{
pObject->SayToPlayer("Blargh! I am dead!");
}
else if(EventName == "attacked")
{
pObject->TakeAwayHealth(15);
if(pObject->GetHealth() < 0)
pObject->EventHappens("death");
}
}





That way you can handle a lot of different events without needing if statements for all of them. If you have a script engine, you can just call the scripts instead of using function pointers, but the concept is the same. This site has a pretty good collection of tutorials and Q&As about function pointers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this