SA-MP Forums Archive
Stock Help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Stock Help (/showthread.php?tid=538719)



Stock Help - Joshayersm - 23.09.2014

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")



Re: Stock Help - Vince - 23.09.2014

https://sampwiki.blast.hk/wiki/Strcmp


Re: Stock Help - Joshayersm - 23.09.2014

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


Re: Stock Help - XStormiest - 23.09.2014

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[])



Re: Stock Help - Joshayersm - 23.09.2014

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.


Re: Stock Help - Vince - 23.09.2014

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(...))



Re: Stock Help - Joshayersm - 24.09.2014

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.