Author Topic: Score donation script  (Read 1399 times)

I've had this idea for a while now, but, I'm attempting to create a script that would allow someone to "donate their score to another player. This would, obviously, A) subtract X score from the donor and B) add X score to the receiver. 

However, being a person who's only made one script in torque before (which needed assistance), I'm not quite sure how I define what's what. Or much of anything, really.

I know I would need to use something like
function ServerCmdDonateScore(%client, %score, %target)
{stuff
}

which I believe translates to
/donatescore <amount> <target>.

If I'm misunderstood, I can try to explain more, but I'm basically trying to figure out where to start.

Thanks in advance.

Use the server command you have there and construct it with the follow information;

To check a client's score (for seeing if they have enough to donate) use:
Code: [Select]
%client.score

To find a client by their name (ie. finding a %client from what the person enters for %target) use:
Code: [Select]
%targetClient = findClientByName(%target);
//Make sure you use isObject(%targetClient) to check if the client with that name actually exists

And finally to add/substract score (officially - changing the %client.score variable won't update the player list)
Code: [Select]
%client.incScore(1); //add 1 score
%client.incScore(-1); //take 1 score

I think I did something terribly wrong.
Can anybody tell me what? For all I know, the following script is complete gibberish to torque.
Code: [Select]
function servercmddonatescore(%client, %score, %target)
{
if(%client.score < 1)
{
messageClient(%client, '', "\c6You must have at least \c51 \c6point to donate.");
}
else
{
%targetClient = findClientByName(%target);
if(isObject(%Targetclient))
{
if(%client.score >= %score)
{
%client.incScore(-%score);
%target.incscore(%score);
messageClient(%target, '', "\c5%client \c6 has donated \c5%score \c6to you.");
}
else
{
messageClient(%client, '', "\c6Not enough score.");
}
else
{
messageClient(%client, '', "\c6 Invalid name.");
}
}
}
};
My console says there's a syntax error.
« Last Edit: March 14, 2011, 08:44:16 PM by Wheatley »





I'll try it out.
On one of the lines you have -%score, you will most likely get a syntax error from it.


Nevermind, just tried it out. My mistake.

On one of the lines you have -%score, you will most likely get a syntax error from it.
Sorry, but that's valid.


Ok, I've modified the script about 20 different times and It's working, so I just need to modify a text-color typo and I'll submit it. Thanks for your help, guys!

You did quite a good job actually. If anyone else who had only ever made one script had received my information they would of just requested the script to be written by someone else or just sat there going "HOWDO?".

messageClient(%target, '', "\c5%client \c6 has donated \c5%score \c6to you.");

This is going to look like "103998 has donated 5 to you"

You want this:
Code: [Select]
messageClient(%target, '', "\c5%client.getPlayerName() \c6 has donated \c5%score \c6 Points to you.");

Code: [Select]
messageClient(%targetClient, '', "\c5" @ %client.getPlayerName() SPC "\c6 has donated \c5" @ %score SPC "\c6 Points to you.");
« Last Edit: March 16, 2011, 12:21:17 AM by Destiny/Zack0Wack0 »

A few things.
First, it's a good idea to get in the habit of proper indentation, it makes everything a lot easier to read.
Second, checking if the client's score is greater than one is pointless, as you are allowing them to donate more than one point, as well as later checking if the score they wish to donate is greater than their current score.
Third, you want to check if the score they want to donate is greater than 0, otherwise players can donate zero or negative scores and get all the score they want.
And finally, a personal opinion, it doesn't matter how you do it, but I think having the arguments be target then score makes more sense than score then target.