I hope someone can help me with this ( I can't explain in title. )
#1

Hello reader,

I lately started using ZCMD and it seems it all works fine, I can script some commands and they work bla bla bla. I always thought that CMD:cmd(playerid, params[]) that the "params" are the player's typed text. So then I tried to create a /help [category] command and this is what happends:
Код:
C:\Users\Administrator\Desktop\samp03dsvr_R2_win32\gamemodes\test2.pwn(384) : error 033: array must be indexed (variable "params")
C:\Users\Administrator\Desktop\samp03dsvr_R2_win32\gamemodes\test2.pwn(393) : error 033: array must be indexed (variable "params")
C:\Users\Administrator\Desktop\samp03dsvr_R2_win32\gamemodes\test2.pwn(404) : error 033: array must be indexed (variable "params")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
This is the scriptcode I use:
pawn Код:
367 CMD:help(playerid, params[])
368 {
369     if (isnull(params))
370     {
371     if (IsPlayerAdmin(playerid) == 1)
372     {
373     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
374     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}General - Roleplay - Admin");
375     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
376     }
377         else if (IsPlayerAdmin(playerid) == 0)
378         {
379     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
380         SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}General - Roleplay");
381         SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
382         }
383     }
384     if ((params) == " General")
385 {
386     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
387     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| .:{FFFFFF}General commands{FFCC00}:.  |");
388     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}--------------------- {FFCC00}|");
389     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/g - This is used to chat in global OOC chat.");
390     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/pm - This is used to chat in private OOC chat.");
391     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
392     }
393     if ((params) == " Roleplay")
394     {
395     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
396     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| .:{FFFFFF}Roleplay commands{FFCC00}:.  |");
397     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}--------------------- {FFCC00}|");
398     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/me - This is used to create a roleplay sentence.");
399     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/act - This is used to create a roleplay sentence.");
400     SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
401     }
402     if (IsPlayerAdmin(playerid) == 1)
403     {
404         if ((params) == " Admin")
405         {
406         SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
407         SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| .:{FFFFFF}Admin commands{FFCC00}:.  |");
408         SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}--------------------- {FFCC00}|");
409         SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/spot - This show other players you are on Administrator duty.");
410         SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/createveh - This is used to create a vehicle.");
411         SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
412         }
413     }
414             else
415             {
416             SendClientMessage(playerid, KLEUR_WIT, "{B4B5B7}USAGE: /help [category]");
417             }
418     return 1;
419 }
I hope someone can help me with this, I already tried several things and they didn't work out!

Best regards,
Jesse
Reply
#2

pawn Код:
if(strcmp(params, "General", true) == 0)
not
pawn Код:
if((params) == " General")
You dont need the space before General btw
Reply
#3

Quote:
Originally Posted by iTorran
Посмотреть сообщение
pawn Код:
if(strcmp(params, "General", true) == 0)
not
pawn Код:
if((params) == " General")
You dont need the space before General btw
I use ZCMD instead of STRCMP, but maybe it will work the same. I will try it later ( As I am celebrating my birthday now :P ), I will update this topic ..

Best regards,
Jesse
Reply
#4

Okay, now I used:
pawn Код:
CMD:help(playerid, params[])
{
    if (isnull(params))
    {
    if (IsPlayerAdmin(playerid) == 1)
    {
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}General - Roleplay - Admin");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
    SendClientMessage(playerid, KLEUR_WIT, "{B4B5B7}USAGE: /help [category]");
    }
    }
    else if (IsPlayerAdmin(playerid) == 0)
    {
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}General - Roleplay");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
    SendClientMessage(playerid, KLEUR_WIT, "{B4B5B7}USAGE: /help [category]");
    }
           
    if (params, "General", true)
    {
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| .:{FFFFFF}General commands{FFCC00}:.  |");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}--------------------- {FFCC00}|");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/g - This is used to chat in global OOC chat.");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/pm - This is used to chat in private OOC chat.");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
    }
   
    else if (params, "Roleplay", true)
    {
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| .:{FFFFFF}Roleplay commands{FFCC00}:.  |");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}--------------------- {FFCC00}|");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/me - This is used to create a roleplay sentence.");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/act - This is used to create a roleplay sentence.");
    SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
    }
   
    else if (params, "Admin", true)
    {
    if (IsPlayerAdmin(playerid) == 0)
    {
    SendClientMessage(playerid, KLEUR_WIT, "{FF2F00}You are not an Administrator.");
    }
        else if (IsPlayerAdmin(playerid) == 1)
        {
        SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
        SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| .:{FFFFFF}Admin commands{FFCC00}:.  |");
        SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}--------------------- {FFCC00}|");
        SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/spot - This show other players you are on Administrator duty.");
        SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}/createveh - This is used to create a vehicle.");
        SendClientMessage(playerid, KLEUR_WIT, "{FFCC00}| {FFFFFF}------------------------------------------------------------------------------------ {FFCC00}|");
        }
    }
    return 1;
}
and it came up with these warnings:
Код:
C:\Users\Administrator\Desktop\samp03dsvr_R2_win32\gamemodes\test2.pwn(387) : warning 206: redundant test: constant expression is non-zero
C:\Users\Administrator\Desktop\samp03dsvr_R2_win32\gamemodes\test2.pwn(397) : warning 206: redundant test: constant expression is non-zero
C:\Users\Administrator\Desktop\samp03dsvr_R2_win32\gamemodes\test2.pwn(407) : warning 206: redundant test: constant expression is non-zero
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Warnings.
I still have no idea how to fix it, so if someone could help me I'd be really happy.
Reply
#5

pawn Код:
if(strcmp(params, "General", true) == 0)
not
pawn Код:
if(params, "General", true)
Reply
#6

Quote:
Originally Posted by iTorran
Посмотреть сообщение
pawn Код:
if(strcmp(params, "General", true) == 0)
not
pawn Код:
if(params, "General", true)
I thought I shouldn't use the (strcmp..............) part since I was using the if's in an ZCMD command :P. After your second reply I figured that you were or right, or you were a too stupid to understand that I was using ZCMD. I am really glad that I can say you were right, and this also solved my problem ( + some minor changes I made, but your help was the thing I needed! ). I will +rep you, thank you once again.

Best regards,
Jesse
Reply
#7

Little note for you again, maybe it's not too late to earn my rep!

Look, there is a difference:

pawn Код:
if(!strcmp(cmdtext, "/me", true, 3))
This you should not use, this is the form of a command you would script! (Read this again, it was also helpful for me at first: https://sampwiki.blast.hk/wiki/Using_strcmp%28%29 )

pawn Код:
if(strcmp(params, "General", true) == 0)
Here you don't write it in a form of command, you are comparing the string (strcmp) with the params and are checking it, if it's true! Therefore, you can use such a form!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)