[HELP] /sellgun with dcmd
#1

Hello! Thanks for taking a peek at my post.

I've search far and wide through the forums for some relevant information on my problem, but to no avail. All of the posts I seen pertained to strcmp commands.

I am attempt to make a /sellgun command. The syntax I am aiming for is "/sellgun (target ID) (gun name)", but when typed without the last 2 parameters, gives a list of guns you can make. I am not sure how to get my code to check for those extra parameters, or even recognize them.

I have tons of commands in my script that are already dcmd, so I would prefer to keep them dcmd. I do not use sscanf or zcmd.

Here is my code:

Код:
dcmd_sellgun(playerid, params[])
{
 	new string[64], PlayerName[24];
	new tmp[256], tmp2[256], Index; tmp = strtok(params,Index), tmp2 = strtok(params,Index);
	new number;
	new StringLength;
	new id;
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
 	format(string, sizeof(string),"xadmin/Users/%s.ini", udb_encode(PlayerName));
	number = dini_Int(string, "Job");
  	StringLength = strlen(params);
  	id = ReturnPlayerID(tmp);
	
	if(number == 6)
	{
	    if(StringLength == 7)
		{
		    SendClientMessage(playerid, CHAT_COLOR_RED, "Works");
		}
		else if(id == INVALID_PLAYER_ID)
		{
		    SendClientMessage(playerid, CHAT_COLOR_RED, "Invalid Player ID!");
		}
		else
		{
		    SendClientMessage(playerid, CHAT_COLOR_RED, "Test");
		}
	}
	else if(number != 6)
	{
	    SendClientMessage(playerid, CHAT_COLOR_RED, "You are not a Arms Dealer!");
	}

	return 1;
}
Any help is much appreciated!

- Haegon
Reply
#2

Код:
dcmd_sellgun( playerid, params[] )
{
	new
		otherid,
		wepname[50],
		idx;
	
	if( sscanf( params, "us", otherid, wepname ) )
		//show list here
		
	else
		//show other code here

	return 1;
}
Using sscanf is what I should do. Easy and less messy.
Also string lenghts of 256 are really not necessary for player names/id's or weapon names..
Reply
#3

I just don't understand how sscanf works, I suppose. I'll do a bit of research on it though. Thanks.
Reply
#4

Here's my new code with sscanf.

Код:
dcmd_sellgun( playerid, params[] )
{
	new otherid, wepname[50];
	new string[64], PlayerName[24];
	new number;
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
	format(string, sizeof(string),"xadmin/Users/%s.ini", udb_encode(PlayerName));
	number = dini_Int(string, "Job");
	

	if(sscanf(params, "us", otherid, wepname))
	{
 		if(number == 6)
		{
			if(otherid == INVALID_PLAYER_ID)
			{
		    	SendClientMessage(playerid, CHAT_COLOR_RED, "Invalid Player ID!");
			}
			else
			{
			    SendClientMessage(playerid, CHAT_COLOR_RED, "Works");
			}
		}
	}
	
	else
	{
		if(number == 6)
		{
		    SendClientMessage(playerid, CHAT_COLOR_RED, "Gun List");
		}
		else if(number != 6)
		{
		    SendClientMessage(playerid, CHAT_COLOR_RED, "You are not an Arms Dealer!");
		}
	}

	return 1;
}
When I do /sellgun when my job isn't Arms Dealer (job 6), it shows nothing. If I do /sellgun with no extra parameters as an arms dealer, it jump to the "Works" part of the code, when it should go to "Gun List". If I type /sellgun (targetid) (gun name), it jumps to the "Gun List" part.

I am so confused. Are there no better ways to do this? :P

Thanks!
Reply
#5

Not the best way to do it but it will show you how you could have done it
pawn Код:
dcmd_sellgun( playerid, params[] )
{
    new otherid, wepname[50];
    new string[64], PlayerName[24];
    new number;
    GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
    format(string, sizeof(string),"xadmin/Users/%s.ini", udb_encode(PlayerName));
    number = dini_Int(string, "Job");
    if(number != 6) return SendClientMessage(playerid, CHAT_COLOR_RED, "You are not an Arms Dealer!");
    else if(sscanf(params, "us", otherid, wepname)) return SendClientMessage(playerid, CHAT_COLOR_RED, "Use: Blah!");
    else if(otherid == INVALID_PLAYER_ID) return SendClientMessage(playerid, CHAT_COLOR_RED, "Invalid Player ID!");
    else
    {
        SendClientMessage(playerid, CHAT_COLOR_RED, "Works");
        SendClientMessage(playerid, CHAT_COLOR_RED, "Yeey :D");
    }
    return 1;
}
Reply
#6

Bwahah! It works. Thanks a million guys.
Reply
#7

So, I got to the part where you can actually sell the weapon. I made it do something like
Код:
 if(weaponName == "bat")
to check if the player wanted to sell a bat, but it gave me array problems, so I tried strcmp, and it just isn't working.

Is there any way I can check if they typed the right weapon in weaponName without using strcmp?

Код:
dcmd_sellgun(playerid, params[])
{
    new otherid, weaponName;
    new string[64], PlayerName[24], matlist[100], matsep[100], armslevel1[100], armslevel2[100], armslevel3[100], armslevel4[100], armslevel5[100];
    new number, armslevel;
    GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
    format(string, sizeof(string),"xadmin/Users/%s.ini", udb_encode(PlayerName));
    number = dini_Int(string, "Job");
   	new MatA = dini_Int(string, "MatA");
	new MatB = dini_Int(string, "MatB");
	new MatC = dini_Int(string, "MatC");
    armslevel = dini_Int(string, "ArmsDealerLevel");
    format(matsep, sizeof(matsep),       "--------------------------------[Guns You Can Sell]--------------------------------");
    format(armslevel1, sizeof(armslevel1), "Level 1: Bat(A-200) | Cane(A-200) | Flowers(A-50) | Katana(A-200) | SDPistol(A-250)");
    format(armslevel2, sizeof(armslevel2), "Level 2: Shotgun(A-300, B-300) | Rifle(B-500) | Small Vibrator(A-50, B-50)");
    format(armslevel3, sizeof(armslevel3), "Level 3: MP5(C-500) | AK47(A-500, B-250 | Large Vibrator(A-100, B-100)");
    format(armslevel4, sizeof(armslevel4), "Level 4: M4(B-500, C-500) | Purple Dildo (A-100, B-100, C-100)");
    format(armslevel5, sizeof(armslevel5), "Level 5: SPAS12(B-500, C-1000)");
    format(matlist, sizeof(matlist),       "---------------[A - %d]---------------[B - %d]--------------[C - %d]---------------", MatA, MatB, MatC);
    if(number != 6) return SendClientMessage(playerid, CHAT_COLOR_RED, "You are not an Arms Dealer!");
    else if(sscanf(params, "rs[32]", otherid, weaponName) && (armslevel == 1)) SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, matsep), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel1), SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, matlist);
    else if(sscanf(params, "rs[32]", otherid, weaponName) && (armslevel == 2)) SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, matsep), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel1), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel2), SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, matlist);
    else if(sscanf(params, "rs[32]", otherid, weaponName) && (armslevel == 3)) SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, matsep), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel1), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel2), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel3), SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, matlist);
    else if(sscanf(params, "rs[32]", otherid, weaponName) && (armslevel == 4)) SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, matsep), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel1), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel2), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel3), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel4), SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, matlist);
    else if(sscanf(params, "rs[32]", otherid, weaponName) && (armslevel == 5)) SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, matsep), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel1), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel2), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel3), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel4), SendClientMessage(playerid, CHAT_COLOR_WHITE, armslevel5), SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, matlist);
    else if(otherid == INVALID_PLAYER_ID) return SendClientMessage(playerid, CHAT_COLOR_RED, "Invalid Player ID!");
    else
    {
		if(armslevel == 1)
		{
		    if(strcmp(params, "Bat", true, 3))
		    {
		    	GivePlayerWeapon(otherid, 5, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Bat works.");
        	}
        	else if(strcmp(params, "Cane", true, 4))
        	{
        		GivePlayerWeapon(otherid, 15, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Cane works.");
        	}
        	else if(strcmp(params, "Flowers", true, 7))
        	{
		    	GivePlayerWeapon(otherid, 14, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Flowers works.");
        	}
        	else if(strcmp(params, "Katana", true, 6))
   			{
		    	GivePlayerWeapon(otherid, 8, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Katana works.");
       		}
        	else if(strcmp(params, "SDPistol", true, 8))
        	{
		    	GivePlayerWeapon(otherid, 23, 10000);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "SDPistol works.");
        	}
		}
		else if(armslevel == 2)
		{
        	if(strcmp(params, "Bat", true, 3))
		    {
		    	GivePlayerWeapon(otherid, 5, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Bat works.");
        	}
        	else if(strcmp(params, "Cane", true, 4))
        	{
        		GivePlayerWeapon(otherid, 15, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Cane works.");
        	}
        	else if(strcmp(params, "Flowers", true, 7))
        	{
		    	GivePlayerWeapon(otherid, 14, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Flowers works.");
        	}
        	else if(strcmp(params, "Katana", true, 6))
   			{
		    	GivePlayerWeapon(otherid, 8, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Katana works.");
       		}
        	else if(strcmp(params, "SDPistol", true, 8))
        	{
		    	GivePlayerWeapon(otherid, 23, 10000);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "SDPistol works.");
        	}
		}
        else if(armslevel == 3)
        {
        	if(strcmp(params, "Bat", true, 3))
		    {
		    	GivePlayerWeapon(otherid, 5, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Bat works.");
        	}
        	else if(strcmp(params, "Cane", true, 4))
        	{
        		GivePlayerWeapon(otherid, 15, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Cane works.");
        	}
        	else if(strcmp(params, "Flowers", true, 7))
        	{
		    	GivePlayerWeapon(otherid, 14, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Flowers works.");
        	}
        	else if(strcmp(params, "Katana", true, 6))
   			{
		    	GivePlayerWeapon(otherid, 8, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Katana works.");
       		}
        	else if(strcmp(params, "SDPistol", true, 8))
        	{
		    	GivePlayerWeapon(otherid, 23, 10000);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "SDPistol works.");
        	}
		}
		else if(armslevel == 4)
		{
        	if(strcmp(params, "Bat", true, 3))
		    {
		    	GivePlayerWeapon(otherid, 5, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Bat works.");
        	}
        	else if(strcmp(params, "Cane", true, 4))
        	{
        		GivePlayerWeapon(otherid, 15, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Cane works.");
        	}
        	else if(strcmp(params, "Flowers", true, 7))
        	{
		    	GivePlayerWeapon(otherid, 14, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Flowers works.");
        	}
        	else if(strcmp(params, "Katana", true, 6))
   			{
		    	GivePlayerWeapon(otherid, 8, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Katana works.");
       		}
        	else if(strcmp(params, "SDPistol", true, 8))
        	{
		    	GivePlayerWeapon(otherid, 23, 10000);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "SDPistol works.");
        	}
		}
		else if(armslevel == 5)
		{
        	if(strcmp(params, "Bat", true, 3))
		    {
		    	GivePlayerWeapon(otherid, 5, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Bat works.");
        	}
        	else if(strcmp(params, "Cane", true, 4))
        	{
        		GivePlayerWeapon(otherid, 15, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Cane works.");
        	}
        	else if(strcmp(params, "Flowers", true, 7))
        	{
		    	GivePlayerWeapon(otherid, 14, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Flowers works.");
        	}
        	else if(strcmp(params, "Katana", true, 6))
   			{
		    	GivePlayerWeapon(otherid, 8, 1);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "Katana works.");
       		}
        	else if(strcmp(params, "SDPistol", true, 8))
        	{
		    	GivePlayerWeapon(otherid, 23, 10000);
        		SendClientMessage(playerid, CHAT_COLOR_LIGHTBLUE, "SDPistol works.");
        	}
		}
    }
    return 1;
}
Reply
#8

Quote:
Originally Posted by Haegon
Посмотреть сообщение
So, I got to the part where you can actually sell the weapon. I made it do something like
Код:
 if(weaponName == "bat")
to check if the player wanted to sell a bat, but it gave me array problems, so I tried strcmp, and it just isn't working.

Is there any way I can check if they typed the right weapon in weaponName without using strcmp?
Shoud look like:
pawn Код:
if(!strcmp(weaponName, "Bat", true))
{
    //Do your stuff!
}
You get the point
Reply
#9

When I do that, it gives me a bucket load of errors. :P

Код:
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1002) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1007) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1012) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1017) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1022) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1030) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1035) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1040) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1045) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1050) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1058) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1063) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1068) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1073) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1078) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1086) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1091) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1096) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1101) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1106) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1114) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1119) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1124) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1129) : error 035: argument type mismatch (argument 1)
C:\Users\Josh\Desktop\CGRP 0.3b\gamemodes\cgroleplay.pwn(1134) : error 035: argument type mismatch (argument 1)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


25 Errors.
There errors are on the actual strcmp lines - what confuses me is that the syntax looks correct. o_O
Reply
#10

Woops
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)