SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 26/05/2020, 09:30 AM   #1
Filbert
Huge Clucker
 
Join Date: May 2016
Posts: 251
Reputation: 1
Question 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!```");
        }
    }
Filbert is online now   Reply With Quote
Old 26/05/2020, 09:48 AM   #2
SharpenBlade
Big Clucker
 
Join Date: May 2020
Posts: 178
Reputation: 23
Default 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!```");
    }

SharpenBlade is online now   Reply With Quote
Old 26/05/2020, 10:11 AM   #3
Filbert
Huge Clucker
 
Join Date: May 2016
Posts: 251
Reputation: 1
Default Re: can i do this? (||)

Quote:
Originally Posted by SharpenBlade View Post
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");
Filbert is online now   Reply With Quote
Old 26/05/2020, 10:22 AM   #4
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,711
Reputation: 1671
Default 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.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#1966
Kwarde is online now   Reply With Quote
Old 26/05/2020, 12:03 PM   #5
Filbert
Huge Clucker
 
Join Date: May 2016
Posts: 251
Reputation: 1
Default 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.
Filbert is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 06:41 PM.


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