My /job command problem
#1

Hello everyone, i'm back with a new question
Well, i tried to make a /job command, player can use /job join/quit, i get no errors In Game but when type /job join or /job quit or type anything after job, Nothing happens...

Here's my command code

Код:
COMMAND:job(playerid, params[])
{
	new option[4];
    if(sscanf(params,"s[4]", option))return SendClientMessage(playerid, GREY, "USAGE: /job [join/quit]");
    if(strlen(option) < 1) return SendClientMessage(playerid, GREY, "Invalid option.");
	else if(!strcmp(option, "join", true))
	{
    	if(IsPlayerInRangeOfPoint(playerid, 3.0, -361.4394,1572.8923,75.9229))
    	{
	    	if(PlayerStat[playerid][JobID] >= 1) return SendClientMessage(playerid, GREY, "You already have a job (use /job quit to leave it).");
	    	SendClientMessage(playerid, GREY, "You have joined the Garbage Man job.");
	     	PlayerStat[playerid][JobID] = 1;
     	}
    	else if(IsPlayerInRangeOfPoint(playerid, 3.0, -1958.6456,323.6250,1552.1406))
    	{
    		if(PlayerStat[playerid][JobID] >= 1) return SendClientMessage(playerid, GREY, "You already have a job (use /job quit to leave it).");
     		SendClientMessage(playerid, GREY, "You have joined the Table Cleaner job.");
     		PlayerStat[playerid][JobID] = 2;
    	}
    	else if(IsPlayerInRangeOfPoint(playerid, 3.0, -1971.0381,324.3919,1552.1387))
    	{
	    	if(PlayerStat[playerid][JobID] >= 1) return SendClientMessage(playerid, GREY, "You already have a job (use /job quit to leave it).");
	    	SendClientMessage(playerid, GREY, "You have joined the Cells Cleaner job.");
	    	PlayerStat[playerid][JobID] = 3;
    	}
        else if(IsPlayerInRangeOfPoint(playerid, 3.0, -349.1976,1544.5193,75.5625))
	    {
		    if(PlayerStat[playerid][JobID] >= 1) return SendClientMessage(playerid, GREY, "You already have a job (use /job quit to leave it).");
		    SendClientMessage(playerid, GREY, "You have joined the Boxer job.");
		    PlayerStat[playerid][JobID] = 4;
	    }
	    /*else if(IsPlayerInRangeOfPoint(playerid, 3.0, 0,0,0))
	    {
		    if(PlayerStat[playerid][JobID] >= 1) return SendClientMessage(playerid, GREY, "You already have a job (use /job quit to leave it).");
		    SendClientMessage(playerid, GREY, "You have joined the Boxs Boy job.");
		    PlayerStat[playerid][JobID] = 5;
	    }*/
	    else return SendClientMessage(playerid, GREY, "You are not near any Job right now.");
	}
	else if(!strcmp(option, "quit", true))
	{
		new string[128];
		if(PlayerStat[playerid][JobID] < 1) return SendClientMessage(playerid, GREY, "You don't have a job to quit.");
		if(PlayerStat[playerid][HoursInJob] <= 4)
		{
		    format(string, sizeof(string), "You must get 5 paychecks before quiting your job. you currently have (%d)." , PlayerStat[playerid][HoursInJob]);
		    SendClientMessage(playerid, GREY, string);
		}
		else
		{
		    SendClientMessage(playerid, GREY, "You have successfully quited your job.");
		    PlayerStat[playerid][HoursInJob] = 0;
		    PlayerStat[playerid][JobID] = 0;
		}
	}
    return 1;
}
Thanks.
Reply
#2

I've made your code a lot neater and removed pointless code (such as the sscanf statement with your 'option' string), try this:

pawn Код:
CMD:job(playerid, params[])
    if(isnull(params))
        return SendClientMessage(playerid, GREY, "USAGE: /job [join/quit]");
   
    if(strcmp(params, "join", true) == 0) {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, -361.4394,1572.8923,75.9229)) {
            if(PlayerStat[playerid][JobID] >= 1)
                return SendClientMessage(playerid, GREY, "You already have a job (use /job quit to leave it).");
                SendClientMessage(playerid, GREY, "You have joined the Garbage Man job.");
                PlayerStat[playerid][JobID] = 1;
            }
        } else if(IsPlayerInRangeOfPoint(playerid, 3.0, -1958.6456,323.6250,1552.1406)) {
            if(PlayerStat[playerid][JobID] >= 1)
                return SendClientMessage(playerid, GREY, "You already have a job (use /job quit to leave it).");

            SendClientMessage(playerid, GREY, "You have joined the Table Cleaner job.");
            PlayerStat[playerid][JobID] = 2;
        } else if(IsPlayerInRangeOfPoint(playerid, 3.0, -1971.0381,324.3919,1552.1387)) {
            if(PlayerStat[playerid][JobID] >= 1)
                return SendClientMessage(playerid, GREY, "You already have a job (use /job quit to leave it).");

            SendClientMessage(playerid, GREY, "You have joined the Cells Cleaner job.");
            PlayerStat[playerid][JobID] = 3;
        }
        else if(IsPlayerInRangeOfPoint(playerid, 3.0, -349.1976,1544.5193,75.5625)) {
            if(PlayerStat[playerid][JobID] >= 1)
                return SendClientMessage(playerid, GREY, "You already have a job (use /job quit to leave it).");

            SendClientMessage(playerid, GREY, "You have joined the Boxer job.");
            PlayerStat[playerid][JobID] = 4;
        }
        else return SendClientMessage(playerid, GREY, "You're not at a valid job location.");
    } else if(strcmp(params, "quit", true) == 0) {
        new string[75];
       
        if(PlayerStat[playerid][JobID] < 1) return SendClientMessage(playerid, GREY, "You don't have a job to quit.");
        if(PlayerStat[playerid][HoursInJob] <= 4)
        {
            format(string, sizeof(string), "You must get 5 paychecks before quitting your job, you currently have %d." , PlayerStat[playerid][HoursInJob]);
            SendClientMessage(playerid, GREY, string);
        }
        else
        {
            SendClientMessage(playerid, GREY, "You have successfully quit your job.");
            PlayerStat[playerid][HoursInJob] = 0;
            PlayerStat[playerid][JobID] = 0;
        }
    } else return SendClientMessage(playerid, GREY, "Invalid option.");
   
    return 1;
}
Reply
#3

Код:
C:\Soumi\Oussama\My Gamemode\pawno\include\SII.inc(249) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Soumi\Oussama\My Gamemode\pawno\include\streamer.inc(435) : warning 202: number of arguments does not match definition
C:\Soumi\Oussama\My Gamemode\pawno\include\streamer.inc(449) : warning 202: number of arguments does not match definition
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(878) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(926) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(936) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(946) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(965) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(982) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(992) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1004) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1016) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1028) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1040) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1058) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1076) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1131) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1139) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1156) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1199) : warning 216: nested comment
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1227) : warning 209: function "cmd_job" should return a value
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1227) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1228) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1229) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1230) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1231) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1235) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1236) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1237) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1239) : error 021: symbol already defined: "SendClientMessage"
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1241) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1242) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1243) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1245) : error 021: symbol already defined: "SendClientMessage"
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1248) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1249) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1250) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1252) : error 021: symbol already defined: "SendClientMessage"
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1255) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1256) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1259) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1260) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1265) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1271) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1273) : error 010: invalid function or declaration
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1454) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1554) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1585) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(1828) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(2076) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(2201) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(2218) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(2235) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\user\Documents\MPRP\gamemodes\MPRP.pwn(2251) : warning 203: symbol is never used: "string"
You forgot something... and what's wrong with the sscanf statement? i think that the problem could be here
Код:
if(sscanf(params,"s[4]", option))
Maybe i have to replace the s[4] with something else?

EDIT: Why are there two ";" here
Код:
if(isnull(params))
        return SendClientMessage(playerid, GREY, "USAGE: /job [join/quit]");;
Thanks for helping.
Reply
#4

Forgot a bracket, fixed.

By default, 'params' contains the value of what the person types in the command, there's no point extracting what the player typed in to an entirely new string via sscanf if you know that you only have one value to consider, in the 'params' string.
Reply
#5

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
Forgot a bracket, fixed.

By default, 'params' contains the value of what the person types in the command, there's no point extracting what the player typed in to an entirely new string via sscanf if you know that you only have one value to consider, in the 'params' string.
Thanks a lot Calg00ne, i just replaced
this
Код:
 if(sscanf(params,"s[4]", option))
with
Код:
if(isnull(params))
and
the option variable with params. its now working.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)