This is a multi-part message in MIME format.
--
[ Picked text/plain from multipart/alternative ]
I'm trying to create a function in which users will be able to exchange "Money." They 
can do this through a command, with this syntax: givemoney <part of targetname> 
<ammount>

However, I'm getting a seg fault. GDB says its on the strcasestr line.

 else if (FStrEq(pcmd,"givemoney")){
  CBasePlayer *pPlayer = GetClassPtr((CBasePlayer *)pev);
  //Error Checking
  if(CMD_ARGC() != 3){
   CLIENT_PRINTF(pEntity, print_console, UTIL_VarArgs("Invalid Syntax.\n"));
   return;
  }
  if(atoi(CMD_ARGV(2)) < 1 || atoi(CMD_ARGV(2)) > pPlayer->m_iMoney){
   CLIENT_PRINTF(pEntity, print_console, UTIL_VarArgs("You don't have that much money. 
%i\n",atoi(CMD_ARGV(2))));
   return;
  }
  //Find our target
  CBasePlayer *target = NULL;
  char *buffer;
  char targetname[32];
  const char *arg1 = (const char *)MAKE_STRING(CMD_ARGV(1));
  while( ((target = (CBasePlayer *)UTIL_FindEntityByClassname(target, "player")) != 
NULL) && !FNullEnt(target->edict())){
   CLIENT_PRINTF(pEntity,print_console,UTIL_VarArgs("Ok"));
   strcpy(targetname,STRING(target->pev->netname));
   buffer = strcasestr(targetname,arg1);
   if(buffer != NULL)
    break;
  }
  if(target == NULL) return;
  //Work the magic
  CBasePlayer *pTarget = GetClassPtr((CBasePlayer *)target);
  pPlayer->m_iMoney -= atoi(CMD_ARGV(2));
  pTarget->m_iMoney += atoi(CMD_ARGV(2));
  CLIENT_PRINTF(pEntity,print_console,UTIL_VarArgs("You have given %s 
$%i.\n",target->edict()->v.netname,atoi(CMD_ARGV(2))));
  CLIENT_PRINTF(pTarget->edict(),print_chat,UTIL_VarArgs("%s has given you 
$%i.\n",pev->netname,pPlayer->m_iMoney));
 }

If you could find a solution, i'd appreciate it.
--


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to