Server Help

ASSS Questions - Minor command problem

Reaem - 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?

Code: Show/Hide

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;
      }
   }
}

hellzlaker - 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;
CypherJF - 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?
Dr Brain - 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.
tcsoccerman - Sat Mar 01, 2008 11:20 pm
Post subject:
points is just flag points?
Reaem - 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
Dr Brain - 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.
Smong - 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.
Anonymous - Tue Mar 04, 2008 9:15 pm
Post subject:
Glad you told me that, thanks smong =)
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group