Help with a simple cmd
#1

Hi, what's up? I'm still learning pawn so I kinda know I did something wrong in the script.

It's the following error:

H:\samp03csvr_R2-2_win32\pawno\try.pwn(129) : error 033: array must be indexed (variable "-unknown-")

And the following code:

Quote:

COMMAND: setfightstyle(playerid, params[])
{

new fights;
if (sscanf(params, "s", fights))SendClientMessage(playerid, 0xFFFFFF, "Usage: /setfightstyle <fightstyle> type /fightlist for a list of styles");
else if(fights == GetPlayerFightingStyle(playerid)) SendClientMessage(playerid, 0xFFFFFF, "You already have that fightingstyle");
else
{
if(fights == "boxing") SendClientMessage(playerid, 0xFFFFFF, "Your style has been changed to boxing!"); SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
}

return 1;


}

I think my declaration of fights is wrong but I'm not sure. Could anyone of you explain me how it is supposed to be done?
Reply
#2

You can't check like that if the string is equal to something. You have to use strcmp.

Here is how it should be:

Код:
COMMAND: setfightstyle(playerid, params[])
{
new fights;
if (sscanf(params, "s", fights))SendClientMessage(playerid, 0xFFFFFF, "Usage: /setfightstyle <fightstyle> type /fightlist for a list of styles");
else if(fights == GetPlayerFightingStyle(playerid)) SendClientMessage(playerid, 0xFFFFFF, "You already have that fightingstyle");
else
{
if(!strcmp(fights, "boxing", true))) SendClientMessage(playerid, 0xFFFFFF, "Your style has been changed to boxing!"); SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
}
return 1;
}
Reply
#3

nvm... delete this post
Steve M. was faster
Reply
#4

Can this also be done with a switch? ;o
Reply
#5

I don't think so.
Reply
#6

Ok thanks for your help, I appreciate it a lot
Reply
#7

I changed it a little and now I get these errors:

Quote:

H:\samp03csvr_R2-2_win32\pawno\try.pwn(130) : error 035: argument type mismatch (argument 1)
H:\samp03csvr_R2-2_win32\pawno\try.pwn(131) : error 029: invalid expression, assumed zero
H:\samp03csvr_R2-2_win32\pawno\try.pwn(131) : warning 215: expression has no effect
H:\samp03csvr_R2-2_win32\pawno\try.pwn(131) : error 001: expected token: ";", but found "if"
H:\samp03csvr_R2-2_win32\pawno\try.pwn(131) : error 035: argument type mismatch (argument 1)
H:\samp03csvr_R2-2_win32\pawno\try.pwn(131) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


5 Errors.

With these lines:

Quote:

COMMAND: setfightstyle(playerid, params[])
{

new fights, message[40];
if (sscanf(params, "s", fights))SendClientMessage(playerid, 0xFFFFFF, "Usage: /setfightstyle <fightstyle> type /fightlist for a list of styles");
else if(fights == GetPlayerFightingStyle(playerid)) SendClientMessage(playerid, 0xFFFFFF, "You already have that fightingstyle");
else
{
format(message, sizeof (message), "You fighting style has been changed to %s", fights);
if(!strcmp(fights, "boxing", true)) SendClientMessage(playerid, 0xFFFFFF, message); SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
else if(!strcmp(fights, "kungfu", true)) SendClientMessage(playerid, 0xFFFFFF, message); SetPlayerFightingStyle(playerid, FIGHT_STYLE_KUNGFU);
else if(!strcmp(fights, "kneehead", true)) SendClientMessage(playerid, 0xFFFFFF, message); SetPlayerFightingStyle(playerid, FIGHT_STYLE_KNEEHEAD);
else SendClientMessage(playerid, 0xFFFFFF, "Unknown style");
}

return 1;


}

Reply
#8

You're trying to store a string in the variable fights using sscanf and to compare it using strcmp, but the variable is not an array.
Reply
#9

I see, but if I declarate it as an array it gets messed up too with errors. Than how should I fix that?
Reply
#10

The first and bigger problem is that you've got two functions each on the lines that set the fighting style. The way you have laid out the code works with one function after an if statement, but not with more than that. You need to put the two functions inside brackets, for example:

Код:
if(!strcmp(fights, "boxing", true))
{
    SendClientMessage(playerid, 0xFFFFFF, message);
    SetPlayerFightingStyle(playerid, FIGHT_STYLE_BOXING);
}
Secondly, because you've changed fights to a string, the line that begins else if(fights == ... will no longer work because it is checking whether a string is equal to a fighting style (an integer). You're either going to have to go through each style the user can type, checking which it is and assign a variable to the one they choose then check if it is the same as the one they have (for example, if they choose boxing, set a variable to 5 and check if that is their current fighting style). The far simpler option would just be allowing them to set the same fighting style again, as it will cause no harm - just delete that line.
Reply
#11

Ok thanks, I'm currently trying to find out if my own solution will work. If not I'll try yours too Thanks a lot.
Reply
#12

My own solution works and I think that's much easier. I made it like this if you're interested:

Quote:


COMMAND: setfightstyle(playerid, params[])
{

new style[6], fightvar;
style[0] = FIGHT_STYLE_NORMAL;
style[1] = FIGHT_STYLE_BOXING;
style[2] = FIGHT_STYLE_KUNGFU;
style[3] = FIGHT_STYLE_KNEEHEAD;
style[4] = FIGHT_STYLE_GRABKICK;
style[5] = FIGHT_STYLE_ELBOW;

if (sscanf(params, "i", fightvar))SendClientMessage(playerid, 0xFFFFFF, "Usage: /setfightstyle <number> type /fightlist for a list of styles");
else
{
if(style[fightvar] == GetPlayerFightingStyle(playerid)) SendClientMessage(playerid, 0xFFFFFF, "You already have this fightingstyle");
else
{
SendClientMessage(playerid, 0xFFFFFF, "Your Style has been changed!");
SetPlayerFightingStyle(playerid, style[fightvar]);
}
}

return 1;


}

Reply
#13

Haha, I thought you wanted to do it using words rather than numbers after the command, so I didn't suggest this way. But you're right, this is a good and simple solution and I'm glad your command works now!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)