Duel command problem
#1

After the player selects the weapon in the dialog, the message string is not sent.
pawn Код:
CMD:duel (playerid, params[])
{
    new giveid;
    if (gIsDuelActive == 1) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"A duel is already active!");
    if (PlayerInfo[playerid][IsInDuel] == 1) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"You are already in a duel!");
    if (sscanf(params, "u", giveid)) return SendClientMessage(playerid, -1, ""RED"USAGE: "WHITE"/duel [ID]");
    if (giveid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"Invalid player ID!");
    if (PlayerInfo[giveid][NoDuelRequests] == 1) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"The player has duel requests disabled!");
    if (PlayerInfo[giveid][IsWaiting] == 1) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"The player is waiting for another duel!");
    ShowPlayerDialog(playerid, DIALOG_CHOOSE_WEAPON, DIALOG_STYLE_LIST, ""PREMIUM"Choose weapon for duel:", "• Desert Eagle\n• Sawn Off Shotgun\n• Combat Shotgun\n• Micro SMG/Uzi\n• M4\n• Shotgun", "Select", "Cancel");
    PlayerInfo[playerid][IsWaiting] = 1;
    PlayerInfo[playerid][DuelTargetID] = giveid;
    return 1;
}
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if (dialogid == DIALOG_CHOOSE_WEAPON)
    {
        if (!response) return 1;
        if (response)
        {
            switch (listitem)
            {
                case 0:
                {
                    gCurrentDuelWeaponID = 24;
                    format(str, sizeof(str), ""RED"[DUEL] "LIGHTBLUE"%s(%d) has challenged you for a duel with "PREMIUM"Desert Eagle"LIGHTBLUE"! (Use /accept or /deny)", GetName(playerid), playerid);
                    SendClientMessage(PlayerInfo[playerid][DuelTargetID], -1, str);
                    PlayerInfo[PlayerInfo[playerid][DuelTargetID]][IsWaiting] = 1;
                }
                case 1:
                {
                    gCurrentDuelWeaponID = 26;
                    format(str, sizeof(str), ""RED"[DUEL] "LIGHTBLUE"%s(%d) has challenged you for a duel with "PREMIUM"Sawn Off Shotgun"LIGHTBLUE"! (Use /accept or /deny)", GetName(playerid), playerid);
                    SendClientMessage(PlayerInfo[playerid][DuelTargetID], -1, str);
                    PlayerInfo[PlayerInfo[playerid][DuelTargetID]][IsWaiting] = 1;
                }
                case 2:
                {
                    gCurrentDuelWeaponID = 27;
                    format(str, sizeof(str), ""RED"[DUEL] "LIGHTBLUE"%s(%d) has challenged you for a duel with "PREMIUM"Combat Shotgun"LIGHTBLUE"! (Use /accept or /deny)", GetName(playerid), playerid);
                    SendClientMessage(PlayerInfo[playerid][DuelTargetID], -1, str);
                    PlayerInfo[PlayerInfo[playerid][DuelTargetID]][IsWaiting] = 1;
                }
                case 3:
                {
                    gCurrentDuelWeaponID = 28;
                    format(str, sizeof(str), ""RED"[DUEL] "LIGHTBLUE"%s(%d) has challenged you for a duel with "PREMIUM"Micro SMG/Uzi"LIGHTBLUE"! (Use /accept or /deny)", GetName(playerid), playerid);
                    SendClientMessage(PlayerInfo[playerid][DuelTargetID], -1, str);
                    PlayerInfo[PlayerInfo[playerid][DuelTargetID]][IsWaiting] = 1;
                }
                case 4:
                {
                    gCurrentDuelWeaponID = 31;
                    format(str, sizeof(str), ""RED"[DUEL] "LIGHTBLUE"%s(%d) has challenged you for a duel with "PREMIUM"M4"LIGHTBLUE"! (Use /accept or /deny)", GetName(playerid), playerid);
                    SendClientMessage(PlayerInfo[playerid][DuelTargetID], -1, str);
                    PlayerInfo[PlayerInfo[playerid][DuelTargetID]][IsWaiting] = 1;
                }
                case 5:
                {
                    gCurrentDuelWeaponID = 25;
                    format(str, sizeof(str), ""RED"[DUEL] "LIGHTBLUE"%s(%d) has challenged you for a duel with "PREMIUM"Shotgun"LIGHTBLUE"! (Use /accept or /deny)", GetName(playerid), playerid);
                    SendClientMessage(PlayerInfo[playerid][DuelTargetID], -1, str);
                    PlayerInfo[PlayerInfo[playerid][DuelTargetID]][IsWaiting] = 1;
                }
            }
        }
    }
    return 1;
}
Reply
#2

Why are you using "ud" for giveid instead of "u"?
And where is the new str[length]?
Reply
#3

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Why are you using "ud" for giveid instead of "u"?
And where is the new str[length]?
I removed d, still not working.
Reply
#4

Why d'you use so bad code?
Reply
#5

I'll optimize you code, when I'll come back.
Reply
#6

PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_CHOOSE_WEAPON:
        {
            if !
response *then return true;
            switch(
listitem)
            {
                case 
0gCurrentDuelWeaponID 24;
                case 
1..3gCurrentDuelWeaponID 25+listitem;
                case 
4gCurrentDuelWeaponID 31;
                case 
5gCurrentDuelWeaponID 25;
                
            }
             
format(strsizeof(str), ""RED"[DUEL] "LIGHTBLUE"%s(%d) has challenged you for a duel with "PREMIUM"%s"LIGHTBLUE"! (Use /accept or /deny)"GetName(playerid), playeridgetWeaponName(.id=gCurrentDuelWeaponID));
            
SendClientMessage(PlayerInfo[playerid][DuelTargetID], -1str);
            
PlayerInfo[PlayerInfo[playerid][DuelTargetID]][IsWaiting] = 1;
        }
    }
    return 
true;
}
getWeaponName(id)
{
    new 
str[15];
    switch(
id)
    {
        case 
24str "Desert Eagle";
        case 
25str "Shotgun";
        case 
26str "Sawn Off";
        case 
27str "Combat Shotgun";
        case 
28str "Micro SMG/UZI";
        case 
31str "M4";
    }
    return 
str;
}
CMD:duel (playeridparams[])
{
    if 
gIsDuelActive == *then return SendClientMessage(playerid, -1""RED"ERROR: "GREY"A duel is already active!");
    if 
PlayerInfo[playerid][IsInDuel] == *then return SendClientMessage(playerid, -1""RED"ERROR: "GREY"You are already in a duel!");
    if 
sscanf(params"u"params[0]) *then return SendClientMessage(playerid, -1""RED"USAGE: "WHITE"/duel [ID]");
    if 
params[0] == INVALID_PLAYER_ID *then return SendClientMessage(playerid, -1""RED"ERROR: "GREY"Invalid player ID!");
    if 
PlayerInfo[params[0]][NoDuelRequests] == *then return SendClientMessage(playerid, -1""RED"ERROR: "GREY"The player has duel requests disabled!");
    if 
PlayerInfo[params[0]][IsWaiting] == *then return SendClientMessage(playerid, -1""RED"ERROR: "GREY"The player is waiting for another duel!");
    
PlayerInfo[playerid][IsWaiting] = 1;
    
PlayerInfo[playerid][DuelTargetID] = params[0];
    
ShowPlayerDialog(playeridDIALOG_CHOOSE_WEAPONDIALOG_STYLE_LIST""PREMIUM"Choose weapon for duel:""• Desert Eagle\n• Sawn Off Shotgun\n• Combat Shotgun\n• Micro SMG/Uzi\n• M4\n• Shotgun""Select""Cancel");
    return 
1;

Reply
#7

Hmm..thanks for that.
But it does not send the message, something is wrong with this, maybe?:
pawn Код:
format(str, sizeof(str), ""RED"[DUEL] "LIGHTBLUE"%s(%d) has challenged you for a duel with "PREMIUM"%s"LIGHTBLUE"! (Use /accept or /deny)", GetName(playerid), playerid, getWeaponName(.id=gCurrentDuelWeaponID));
            SendClientMessage(PlayerInfo[playerid][DuelTargetID], -1, str); // here?
            PlayerInfo[PlayerInfo[playerid][DuelTargetID]][IsWaiting] = 1;
Reply
#8

I just optimized this code, not repair
Reply
#9

Quote:
Originally Posted by SyntaxQ
Посмотреть сообщение
Hmm..thanks for that.
But it does not send the message, something is wrong with this, maybe?:
pawn Код:
format(str, sizeof(str), ""RED"[DUEL] "LIGHTBLUE"%s(%d) has challenged you for a duel with "PREMIUM"%s"LIGHTBLUE"! (Use /accept or /deny)", GetName(playerid), playerid, getWeaponName(.id=gCurrentDuelWeaponID));
            SendClientMessage(PlayerInfo[playerid][DuelTargetID], -1, str); // here?
            PlayerInfo[PlayerInfo[playerid][DuelTargetID]][IsWaiting] = 1;
Then, try to change this: sscanf(params, "u", params[0])
To this: sscanf(params, "i", params[0])
Reply
#10

pawn Код:
CMD:duel (playerid, params[])
{
    if(gIsDuelActive == 1) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"A duel is already active!");
    if(PlayerInfo[playerid][IsInDuel]) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"You are already in a duel!");
    new giveid;
    if(sscanf(params, "u", giveid)) return SendClientMessage(playerid, -1, ""RED"USAGE: "WHITE"/duel [ID]");
    if(giveid == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"Invalid player ID!");
    if(PlayerInfo[giveid][NoDuelRequests] == 1) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"The player has duel requests disabled!");
    if(PlayerInfo[giveid][IsWaiting] == 1) return SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"The player is waiting for another duel!");
    ShowPlayerDialog(playerid, DIALOG_CHOOSE_WEAPON, DIALOG_STYLE_LIST, ""PREMIUM"Choose weapon for duel:", "• Desert Eagle\n• Sawn Off Shotgun\n• Combat Shotgun\n• Micro SMG/Uzi\n• M4\n• Shotgun", "Select", "Cancel");
    PlayerInfo[playerid][IsWaiting] = 1;
    PlayerInfo[playerid][DuelTargetID] = giveid;
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_CHOOSE_WEAPON)
    {
        if(response)
        {
            new weapon, duelstr[128], gunname[32];
            switch(listitem)
            {
                case 0: weapon = 24;
                case 1: weapon = 26;
                case 2: weapon = 27;
                case 3: weapon = 28;
                case 4: weapon = 31;
                case 5: weapon = 25;
            }
            gCurrentDuelWeaponID = weapon;
            //I'm not sure if you're meant to be using a global variable for this, so I'll leave it for you to decide.
            GetWeaponName(weapon, gunname, sizeof(gunname));
            format(duelstr, sizeof(duelstr), ""RED"[DUEL] "LIGHTBLUE"%s(%d) has challenged you to a duel with a "PREMIUM"%s"LIGHTBLUE"! (Use /accept or /deny)", GetName(playerid), playerid, gunname);
            SendClientMessage(PlayerInfo[playerid][DuelTargetID], -1, duelstr);
            PlayerInfo[PlayerInfo[playerid][DuelTargetID]][IsWaiting] = 1;
        }
        return 1;
    }
    return 0; //OnDialogResponse should return 0, not 1.
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)