Game Development Community

Player stats by scripts

by Stephen · in Torque Game Engine · 09/15/2006 (11:03 pm) · 4 replies

How can I get player stats though scripts and without changing the engine? I'm looking for a very simple stat system. There will be Strength, Vitality, Dexterity, Energy that the player can choose from when creating a character.

Strength = Player can use heavier weapons and armor
Dexterity = Attack success and defense rating
Vitality = More health for player
Energy = More mana for player to cast spells

I just want to know if this can be done.

#1
09/16/2006 (12:16 am)
I had to do this for my RPG. You could have global variables for each one and have attack damage, health, whatever influenced by them. I'm using a script object however.
#2
09/16/2006 (1:44 am)
Could you post the code on how you did it?
#3
09/16/2006 (7:35 am)
Sure. Have a new script called stats.cs.

Now in there put some variables like

$Strength = 10;

$Energy = 10;

$Vitality = 10;

Then just tie those in with damage amounts, energy levels, whatever. This is extremely simplistic but seems to get the job done.
#4
10/10/2006 (9:44 pm)
I also implented stats in my game, but declaring global variables for a single player may be bad if you ever have multiplayer games.

A better option (I think) is to either declare the varibles for the specific client or player. So in server/game.cs after "MissionCleanup.add(%player);" in createplayer(), you would add

%player.Strength = 10;

%player.Energy = 10;

%player.Vitality = 10;

for example.

if you wanted to add it to the client instead, you would just say:

%player.client.Strength = 10;

%player.client.Energy = 10;

%player.client.Vitality = 10;


I'm not clear about which is better, they both seem to work just fine, and it is not harder to call up one than the other because if you have %client you can get player and vice versa because %client.player = %player and %player.client = %client.

So to get/change the value of your variable, you would just say, for example in:

function example(%client){

%client.Strength = 100;
}

or if you stored it in %player instead you would do:

function example(%client){

%client.player.Strength = 100;
}


I hope that answers your question. If there is someone who can clear up the difference between using %client and %player, please tell me.

You could technically get away with using globals, but if you ever want to do multiplayer or have the AI have stats, then you really have to store them on the player or client.

The only reason I went into so much detail on this is it is something that I had a lot of trouble with when I started too, so I wanted to clear it up in general.