Game Development Community

Hard Coding Player Stats/skills

by Joseph Call · in Technical Issues · 05/06/2008 (8:24 pm) · 6 replies

Greetings Torque Community,

I'm relatively new to Torque, having had my license for about four months. Like many others I've seen, I'm interested in implementing a RPG style system for attributes, and skills/classes. Pretty much everything I've read up to this point indicates that in order to maximize efficiency, this segment should be hard coded into the engine, typically through a sub-class of Player.

I'm looking for any resources, and/or tips on how this might be accomplished in TGE 1.5.x

My steps (at this point) will involve creating a class PlayerCharacter to inherit from Player, and then add the traditional attributes. The format that I've seen thus far is:

S32 value;

Would I create an empty class for instantiation, and then expose the attribue variables to the console with

ConsoleMethod(className,scriptname,returnType,minArgs,maxArgs,usage)?

I was thinking that get/set methods could be implemented within the class for alterations, and applications throughout the rest of the system, as well as in scripts.

I've read through the excellent resource on adding this all in through scripting from here:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13020

And tinkered a bit with the information from Daniel Neilsen here:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2698

However scripting this system is not really my goal for now, and I haven't gotten functionality from Daniel Neilsen's tutorial.

My eventual goal is probably going to involve turn based combat, perhaps in a strategic environment. My main concerns right now are implementing attributes, and a system to utilize them instead of the datablock. This system will also expose me to the networking elements of Torque including updating the client through the ghost.

Thanks in advance for any pointers, help, advice, resources, etc.

About the author

Recent Threads


#1
05/06/2008 (9:24 pm)
You're on the right track. I recommend reading the C++ source documentation for NetObject and ConsoleObject as it pretty much contains all the relevant information for you.

Basically, what you need is your set of fields, your ConsoleMethods and the packUpdate and unpackUpdate methods. Again, all the info is in the source code docs.

//EDIT: Correction. Rather than just pointing someone to the docs, I should have read them more closely myself...
#2
05/06/2008 (9:55 pm)
Thanks for the starter information, I'll start with ConsoleObjects and move on down the hierarchy to NetObjects. I should be able to put together a skeleton subclass here in a few days... hopefully.

Thanks again.
#3
05/07/2008 (2:21 pm)
Im keeping all of the player attributes on the script side, i have about 30 of them. Is this the wrong way to go? How much would it improve performance to implent the attributes in the engine code instead of strictly script side? I fetch my data from an external mySql database(sorta like battle.net), so i would have to modify the players attributes from script side anyways, but would it be smarter to do so with console method calls?(i got the feeling that console methods calls actually took more cream than just manually asigning a field to the object on script side). I dont have much C++ experience, but i dare say that im at least an intermediate imperative programmer.

If i got it right i would have to do the following:

Modify the playerClass to hold extra fields, one field for each one of my attributes(pretty obvious)
Make a bunch of consoleMethods to set/get the attributes(also one for each of the attributes i guess)
Update the packUpdate/unpackUpdate so that the server knows whats going on.

Is this for me?

Edit: My combat/world interaction/persistent data modification implentations is in script, and i am 100% sure that i would not be able to code thosse into pure "code", is this also a factor?

Edit2: Totaly non related: My laptop has a better processor and more ram than my stationary, but lacks openGL(if you manage to find openGL routines to a ATI mobility Radeon X2300 card, then please please tell me), and it seems that this affects the framerate of Torque, drastically lowering it. Could this be because i have to run direct3d?
#4
05/07/2008 (2:55 pm)
Ted, try ati.amd.com/support/driver.html for the ATI mobility Radeon X2300 card ?
#5
05/07/2008 (7:45 pm)
I've pre-emptively started scraping together some code for the humble beginnings of my class header file. I've basically just taken the player.h file, and commented out most everything, and started the base of my own. Things are commented out for a reference, or because I'm not certain if I'm going to override any of the specific featues.

#ifndef _PLAYERCHARACTER_H_
#define _PLAYERCHARACTER_H_

#ifndef _SHAPEBASE_H_
#include "game/shapeBase.h"
#endif
#ifndef _BOXCONVEX_H_
#include "collision/boxConvex.h"
#endif

//I don't know why these class declarations are here.
//class ParticleEmitter;
//class ParticleEmitterData;
//class DecalData;
//class SplashData;

//----------------------------------------------------------------------------


class PlayerCharacter: public Player
{
	typedef Player Parent;
/*	
	Commented out till I figure out whether I need it yet... also for reference
	
	enum Constants {
      RecoverDelayBits = 7,
      JumpDelayBits = 7,
      NumSpineNodes = 6,
      ImpactBits = 3,
      NUM_SPLASH_EMITTERS = 3,
      BUBBLE_EMITTER = 2,
   };

*/

	//Attributes... for now.
	S32 lvl;	//Level
	S32 str;	//Strength
	S32 con;	//Constitution
	S32 dex;	//Dexterity
	S32 mnd;	//Intelligence
	S32 wis;	//Wisdom
	S32 lck;	//Luck

	string name;

	//This attribute is in place as a demonstration for class project
	//in order for an attribute to have an immediate effect upon gameplay.
	S32 playerSpeed;

	//Called by receiveExp when requirements are met.
	void levelUp(S32 curLvl);	//Parameters to be expanded upon as races/skills are introduced
	
public:
	DECLARE_CONOBJECT(PlayerCharacter);
	PlayerCharacter();		//Future developments for initializing specific character class/race
	~PlayerCharacter();		//Any extraneous resource management

	//Variable get/set methods
	//To be exposed with ConsoleMethod(PlayerCharacter, methodName, minArg, maxArg, "Description.")
	S32 getStr();
	void setStr(S32 strValue);

	S32 getCon();
	void setCon(S32 conValue);

	S32 getMnd();
	void setMnd(S32 mndValue);

	S32 getWis();
	void setWis(S32 wisValue);

	S32 getLck();
	void setLck(S32 lckValue);

	void receiveExp(int amount);

	//This is where I will initialize my attributes and various custom fields
	//with addField(fieldName, class, type, Offset(fieldName, class));
	//I don't really understand Offset as of yet.
	static void initPersistFields();


	//...to be understood.
	virtual void packData(BitStream* stream);
	virtual void unpackData(BitStream* stream);
	U32  packUpdate  (NetConnection *conn, U32 mask, BitStream *stream);
	void unpackUpdate(NetConnection *conn,           BitStream *stream);

}

The rest of the player class is below here, and commented out for reference and easy addition to my own should I need to do so.

If anyone has anything helpful to add, please feel free. I am by no means anything more than a beginning programmer.
#6
05/08/2008 (11:09 am)
Been there done that, there are no drivers for my card on that site. It was one month since i checked though, so im gonna check again.

Edit: nope, they still only have drivers for up to X1800.
Edit2: on closer inspectation, it seems that while AMD does not have any drives for X2300, the company that made and sold my laptop should have drives. Seems kinda strange to me.