Your issue is here:
*prob* 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));
*prob* buffer = strcasestr(targetname,arg1);
First off MAKE_STRING can ONLY be used for static data. Never use it to
create a string to dynamically allocated data, use ALLOC_STRING instead.
Second it does not return a valid pointer, it returns an offset into
gpGlobals->StringBase. This means when you do the strcasestr arg1 is not
pointing to real memory (the warning sign is the fact you had to
explicit cast the return value of MAKE_STRING).
The part that confuses me is why use MAKE_STRING at all, If what you
really want is a char * then CMD_ARGV(x) already returns that. You only
need to use MAKE_STRING if you want to pass a string to the engine.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ben Waldher
Sent: Monday, September 08, 2003 12:24 PM
To: [EMAIL PROTECTED]
Subject: [hlcoders] Seg Fault
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
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders