SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   can i do this? (||) (https://forum.sa-mp.com/showthread.php?t=675984)

Filbert 26/05/2020 09:30 AM

can i do this? (||)
 
pawn Code:
if(channel == g_Discord_Admin_CMD)
    {
        if(!strcmp(command, "!mycommand", true)) {
            if(role == (g_Role_Level_1 || g_Role_Level_2 || g_Role_Level_3 || g_Role_Level_4)) { //<<<<<<<<<<<<<<<<<<<<<
                //My action
            } else return DCC_SendChannelMessage(g_Discord_Admin_CMD, "```ERROR: You're not an admin!```");
        }
    }

SharpenBlade 26/05/2020 09:48 AM

Re: can i do this? (||)
 
I am not sure you can. Try like this:
PHP Code:

if(channel == g_Discord_Admin_CMD)
{
    if(!
strcmp(command"!mycommand"true)) 
    {
        if(
role == g_Role_Level_1 || role == g_Role_Level_2 || role == g_Role_Level_3 || role == g_Role_Level_4)
        {
            
//My action
        

        else return 
DCC_SendChannelMessage(g_Discord_Admin_CMD"```ERROR: You're not an admin!```");
    }



Filbert 26/05/2020 10:11 AM

Re: can i do this? (||)
 
Quote:

Originally Posted by SharpenBlade (Post 4148105)
I am not sure you can. Try like this:
PHP Code:

if(channel == g_Discord_Admin_CMD)
{
    if(!
strcmp(command"!mycommand"true)) 
    {
        if(
role == g_Role_Level_1 || role == g_Role_Level_2 || role == g_Role_Level_3 || role == g_Role_Level_4)
        {
            
//My action
        

        else return 
DCC_SendChannelMessage(g_Discord_Admin_CMD"```ERROR: You're not an admin!```");
    }



I have 8 or more admin roles.. It would be too long if i do that (i guess). Or can i use switch or something like
PHP Code:

new g_Role[8]; 

?

But i have no idea how to make that. Can you give me an example? How to make this as simple as possible?
I have this
pawn Code:
new DCC_Role:g_Role_Level_1;
new DCC_Role:g_Role_Level_2;
new DCC_Role:g_Role_Level_3;
new DCC_Role:g_Role_Level_4;
new DCC_Role:g_Role_Level_5;
new DCC_Role:g_Role_Level_6;
new DCC_Role:g_Role_Level_7;
new DCC_Role:g_Role_Level_8;
And this under OnGameModeInit()

pawn Code:
g_Role_Level_1 = DCC_FindRoleById("myroleid");
g_Role_Level_2 = DCC_FindRoleById("myroleid");
g_Role_Level_3 = DCC_FindRoleById("myroleid");
g_Role_Level_4 = DCC_FindRoleById("myroleid");
g_Role_Level_5 = DCC_FindRoleById("myroleid");
g_Role_Level_6 = DCC_FindRoleById("myroleid");
g_Role_Level_7 = DCC_FindRoleById("myroleid");
g_Role_Level_8 = DCC_FindRoleById("myroleid");

Kwarde 26/05/2020 10:22 AM

Re: can i do this? (||)
 
Nope.
Tip: Create a filterscript and create a similar code to test it if you wanna know something like this. Example:

pawn Code:
#include <a_samp>

enum
{
    Role1 = 1,
    Role2,
    Role3,
    Role4,
    Role5
};

public OnFilterScriptInit()
{
    new role = Role4;
    if (role == (Role1 || Role4))
        print("Role is Role1 or Role4!");
    return 1;
}

EDIT: Can't use switches either; they require constant values.

I think the best solution for you is to use macro's.

Filbert 26/05/2020 12:03 PM

Re: can i do this? (||)
 
1 more question..
How can i get the 'rolename'?
pawn Code:
forward DCC_OnMessageCreate(DCC_Message:message);
public DCC_OnMessageCreate(DCC_Message:message)
{
    new realMsg[100];
    DCC_GetMessageContent(message, realMsg, 100);
    new bool:IsBot;
    new DCC_Channel:channel;
    DCC_GetMessageChannel(message, channel);
    new DCC_User:author;
    DCC_GetMessageAuthor(message, author);
    //=================This is what i dont get==================================
    new DCC_Role:role, rolename[128];//<<<<<<<<<<<<<<<<<<<<
    DCC_GetRoleName(role, rolename, 128);//<<<<<<<<<<<<<<<<<<<<
    //==========================================================================
    DCC_IsUserBot(author, IsBot);
    if(IsBot) return 1;
    new discordstr[256];
    new command[32], params[128];
    DCC_GetMessageContent(message, discordstr);
    sscanf(discordstr, "s[32]s[128]", command, params);
    if(channel == g_Discord_Admin_CMD)
    {
        if(!strcmp(command, "!mycommand", true)) {
            if(rolename == g_Role_Level_1 || rolename == g_Role_Level_2 || rolename == g_Role_Level_3 || rolename == g_Role_Level_4) {//<<<<<<<<<<<<<<<<<<<<<<<<
                //My actions
            } else return DCC_SendChannelMessage(g_Discord_Admin_CMD, "```ERROR: You are not a high enough level to use this command```");
        }
    }
    return 1;
}
Code:

error 033: array must be indexed (variable "rolename")
I tried it some ways, and still getting errors.


All times are GMT. The time now is 10:32 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.