Stock Help
#1

So is there anyway I could make this work?

Код:
stock GetDrugID (drugname[32])
{
	new drugid;
	if(drugname == "weed")
	{
		drugid = 1;
		return drugid;
	}
	else if(drugname == "shrooms")
	{
		drugid = 2;
		return drugid;
	}
	else if(drugname == "heroin")
	{
		drugid = 3;
		return drugid;
	}
	else if(drugname == "lsd")
	{
		drugid = 4;
		return drugid;
	}
	else if(drugname == "meth")
	{
		drugid = 5;
		return drugid;
	}
	return 1;
}
I'm sure I'm doing something wrong here, because I feel like something like this could be possible. Anyway the errors it's giving me are these:

Код:
sarp.pwn(12352) : error 033: array must be indexed (variable "drugname")
sarp.pwn(12357) : error 033: array must be indexed (variable "drugname")
sarp.pwn(12362) : error 033: array must be indexed (variable "drugname")
sarp.pwn(12367) : error 033: array must be indexed (variable "drugname")
sarp.pwn(12372) : error 033: array must be indexed (variable "drugname")
Reply
#2

https://sampwiki.blast.hk/wiki/Strcmp
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Oh okay, so would it be something like:
Код:
if(strcmp(drugname, "weed", true))
{
 Do Stuff
}
Or is that incorrect?
Reply
#4

Dont ever again put a size in a Fuction's array parameter!.

You see, this
pawn Код:
stock GetDrugID (drugname[32])
must be
pawn Код:
stock GetDrugID (drugname[])
Reply
#5

So I have completed my stock and I'm having a few issues, this is the completed stock:

Код:
stock GetDrugID (drugname[])
{
	new drugid;
	if(strcmp(drugname, "weed", true))
	{
		drugid = 1;
		return drugid;
	}
	else if(strcmp(drugname, "shrooms", true))
	{
		drugid = 2;
		return drugid;
	}
	else if(strcmp(drugname, "heroin", true))
	{
		drugid = 3;
		return drugid;
	}
	else if(strcmp(drugname, "lsd", true))
	{
		drugid = 4;
		return drugid;
	}
	else if(strcmp(drugname, "meth", true))
	{
		drugid = 5;
		return drugid;
	}
        return 1;
}
However in the command I'm using, you have to enter a drug name. And at the moment when I enter something like Meth, it still comes up as Weed.

So what I'm trying to say is the stock is just returning everything as Weed even if you enter something like Meth.
Reply
#6

The strcmp function returns 0 when the strings match, due to the way it works internally. So prefix each occurence of strcmp with the negation operator (!).
pawn Код:
if(!strcmp(...))
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
The strcmp function returns 0 when the strings match, due to the way it works internally. So prefix each occurence of strcmp with the negation operator (!).
pawn Код:
if(!strcmp(...))
Oh okay thank you very much, issue resolved.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)