Author |
Message |
Reaem Newbie
Joined: Oct 02 2005 Posts: 9 Offline
|
Posted: Sat Mar 01, 2008 9:23 pm Post subject: Minor command problem |
 |
|
|
|
Simple donate command: should transfer the entered amount of points from you to the target player
Problem: whenever I send this in public it works as entered, but when sending this privately to another player on my server, the command does not register at all. It doesn't even show up in my console log that the command was received. What am I missing?
local void Cdonate(const char *tc, const char *params, Player *p, const Target *target)
{
if (target->type != T_PLAYER || params == NULL)
{
chat->SendMessage(p, "Usage: ?donate # privately to a player");
return;
}
else
{
int cost = atoi(params);
if (check_pts(p, cost))
{
int p_pts = stats->GetStat(p, STAT_FLAG_POINTS, INTERVAL_RESET);
stats->SetStat(p, STAT_FLAG_POINTS, INTERVAL_RESET, p_pts - cost);
int t_pts = stats->GetStat(target->u.p, STAT_FLAG_POINTS, INTERVAL_RESET);
stats->SetStat(target->u.p, STAT_FLAG_POINTS, INTERVAL_RESET, t_pts + cost);
chat->SendMessage(p, "You have donated your points");
chat->SendMessage(target->u.p, "You have received a donation");
}
else
{
chat->SendMessage(p, "Not enough points");
return;
}
}
}
|
|
|
Back to top |
|
 |
hellzlaker Registered Cap Buster Popping men in the ass since Oct 2005
Gender: NEVER ENOUGH! Joined: Oct 27 2005 Posts: 34 Offline
|
Posted: Sat Mar 01, 2008 9:28 pm Post subject: |
 |
|
|
|
im not a programmer but i was learnin c++ 2 years ago and quit, so correct me if im wrong
the code u wrote
else
{
chat->SendMessage(p, "Not enough points");
return;
shouldnt it be ?
else if
{
chat->SendMessage(p, "Not enough points");
return; |
|
Back to top |
|
 |
CypherJF I gargle nitroglycerin

Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: Sat Mar 01, 2008 10:41 pm Post subject: |
 |
|
|
|
hellzlaker wrote: | im not a programmer but i was learnin c++ 2 years ago and quit, so correct me if im wrong
the code u wrote
else
{
chat->SendMessage(p, "Not enough points");
return;
shouldnt it be ?
else if
{
chat->SendMessage(p, "Not enough points");
return; |
No.
Don't you need to register the command to be listened to? _________________ Performance is often the art of cheating carefully. - James Gosling |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sat Mar 01, 2008 10:53 pm Post subject: |
 |
|
|
|
Make sure you've got privcmd_donate in the appropriate groupdef file, in addition to the cmd_donate one. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|
Back to top |
|
 |
tcsoccerman Server Help Squatter
Age:33 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Sat Mar 01, 2008 11:20 pm Post subject: |
 |
|
|
|
points is just flag points? |
|
Back to top |
|
 |
Reaem Newbie
Joined: Oct 02 2005 Posts: 9 Offline
|
Posted: Sun Mar 02, 2008 11:11 am Post subject: o |
 |
|
|
|
Oh. that's undoubtedy the problem then, thanks mr brain. I take it all commands must be listed once for each target it can be use on then, IE freqcmd_donate too? Or just for priv commands?
(Of course I am not going to allow someone to donate to a whole freq, but for educational purposes)
And no, points include kill and flag points together. The reason I consolidate those points via consolidate(p) into flag points is so I can more easily manipulate the numbers.
-JP |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sun Mar 02, 2008 11:13 am Post subject: |
 |
|
|
|
Freq commands fall under the privcmd_* designation. You'll have to fix your code to make sure the target is a player, otherwise you'll probably crash. |
|
Back to top |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Sun Mar 02, 2008 11:30 am Post subject: |
 |
|
|
|
Instead of GetStat/SetStat you may want to use IncrementStat to avoid race conditions. Despite its name you can pass in a negative amount. _________________ ss news  |
|
Back to top |
|
 |
Agile Guest
Offline
|
Posted: Tue Mar 04, 2008 9:15 pm Post subject: |
 |
|
|
|
Glad you told me that, thanks smong =) |
|
Back to top |
|
 |
|