Command /weaps problem...
#1

Hello, guys!

I want to make a command that, when you type /weaps [ID], it shows you selected player's weapons, and when you type just /weaps (without completting the param), it shows you a Dialog Style Tablist like this:



If the Player X has a Rocket and Grenades, his name will appear there two times, showing the both Weapons and their ammo.

If there are 10 players with big weapons, in this dialog I want all of them to appear..

There is what I made...

PHP код:
CMD:weaps(playeridparams[])
{
    if(
Player[playerid][Level] >= || Player[playerid][VIP] >= 7)
    {
        new 
pIDCountWxWeapName[24], slotweapammoCountP 0Str[0] = '\0'Str2[0] = '\0';
        new 
Str4[50] = "{00BBF6}Name\t{00BBF6}Weapon\t{00BBF6}Ammo";
        
//----------------------------------------------------------------------
        
if(sscanf(params"u"pID))
        {
            foreach(new 
Player)
            {
                new 
weapons[2][4];
                
GetPlayerWeaponData(l7weapons[1][0], weapons[1][1]);
                
GetPlayerWeaponData(l8weapons[1][2], weapons[1][3]);
                if(
weapons[1][2] == 16)
                {
                       
format(Str2024"{00FF00}%s {00BBF6}(ID:%d) \t{00FF00}Grenades \t{FF0000}%d\n%s"ReturnName(l), lweapons[1][3], Str);
                       
CountP++;
                   }
                   
//--------------------------------------------------------------
                   
else if(weapons[1][2] == 18)
                   {
                    
format(Str2024"{00FF00}%s {00BBF6}(ID:%d) \t{00FF00}Molotovs \t{FF0000}%d\n%s"ReturnName(l), lweapons[1][3], Str);
                       
CountP++;
                }
                
//--------------------------------------------------------------
                
if(weapons[1][0] == 35)
                {
                    
format(Str2024"{00FF00}%s {00BBF6}(ID:%d) \t{00FF00}Rocket Launcher \t{FF0000}%d\n%s"ReturnName(l), lweapons[1][1], Str);
                     
CountP++;
                }
                
//--------------------------------------------------------------
                
else if(weapons[1][0] == 36)
                {
                    
format(Str2024"{00FF00}%s {00BBF6}(ID:%d) \t{00FF00}Heat Seeker \t{FF0000}%d\n%s"ReturnName(l), lweapons[1][1], Str);
                     
CountP++;
                }
                
//--------------------------------------------------------------
                
else if(weapons[1][0] == 37)
                {
                    
format(Str2024"{00FF00}%s {00BBF6}(ID:%d) \t{00FF00}FlameThrower \t{FF0000}%d\n%s"ReturnName(l), lweapons[1][1], Str);
                     
CountP++;
                }
              }
            new 
Str3[100];
            
format(Str3300"%s\n%s"Str4Str);
            if(
CountP == 0) return SendClientMessage(playerid0xFF0000AA"USAGE: {49FFFF}/weaps [ID]");
            
//--------------------------------------------------------------------------
            
else return ShowPlayerDialog(playerid123DIALOG_STYLE_TABLIST_HEADERS"{BBFF00}Players with {00BBF6}Big Weapons"Str3"Close"""), SendCommandToAdmins(playerid"Weaps");
        }
        
Str[0] = '\0'Str2[0] = '\0';
        
//----------------------------------------------------------------------
         
if(IsPlayerConnected(pID) && pID != INVALID_PLAYER_ID)
         {
            
format(Str128"%s's Weapons:"ReturnName(pID)), SendClientMessage(playerid0x00FF00AAStr);
            
//------------------------------------------------------------------
            
for(slot 0slot 14slot++)
            {
                
GetPlayerWeaponData(pIDslotweapammo);
                
//--------------------------------------------------------------
                
if(ammo != && weap != 0CountW++;
            }
            if(
CountW 1SendClientMessage(playerid0x00FF00AA"This player don't have Weapons!");
            
//------------------------------------------------------------------
            
if(CountW >= 1)
            {
                for(
slot 0slot 14slot++)
                {
                    
GetPlayerWeaponData(pIDslotweapammo); SendCommandToAdmins(playerid"Weaps");
                    
//----------------------------------------------------------
                    
if(ammo != && weap != 0)
                    {
                        
GetWeaponName(weapWeapNamesizeof(WeapName));
                        
//------------------------------------------------------
                        
if(ammo == 65535 || ammo == 1format(Str2128"%s%s (1)"Str2WeapName);
                        else 
format(Str2128"%s%s (%d)"Str2WeapNameammo); x++;
                        
//------------------------------------------------------
                        
if(>= 5)
                        {
                             
SendClientMessage(playerid0x00FF00AAStr2); 0format(Str2128"");
                        }
                        else 
format(Str2128"%s,  "Str2);
                    }
                }
                
//--------------------------------------------------------------
                
if(<= && 0)
                {
                    
Str2[strlen(Str2)-3] = '.'SendClientMessage(playerid0x00FF00AAStr2);
                }
            }
            
//------------------------------------------------------------------
            
return 1;
        }
        
//----------------------------------------------------------------------
        
else return ERROR_NotConnected(playerid);
    }
    else return 
ErrorMessages(playerid4);

Can someone help me fix this command ? It have lot of bugs... Sometimes, when I type /weaps [ID], it shows me about 10 times this on the chat: SendCommandToAdmins(playerid, "Weaps");

Sometimes, when 2 players have 2 different big weapons, and I type /weaps, the server gets crashed, and sometimes it shows me the message 'SERVER: UNKNOWN COMMAND', but I have in my GameMode the callback 'public OnPlayerCommandPerformed'...

Thank you very much!
Reply
#2

pawn Код:
GetWeaponNameEx(weaponid, weapon[], len = sizeof(weapon))
{
    switch(weaponid)
    {
        case 18: return strcat(weapon, "Molotovs", len);
        case 44: return strcat(weapon, "Night Vision Goggles", len);
        case 45: return strcat(weapon, "Thermal Goggles", len);
        default: return GetWeaponName(weaponid, weapon, len);
    }
    return false;
}

CMD:weaps(playerid, params[])
{
    if(Player[playerid][Level] < 3 || Player[playerid][VIP] < 7) ErrorMessages(playerid, 4);
    else
    {
        new pID;
        sscanf(params, "U(-1)", pID);
        if(pID == INVALID_PLAYER_ID) ERROR_NotConnected(playerid);
        else
        {
            new CountW;
            static strTemp[220],strDest[220 char],strWeap[5500 char],weap[2][2];
            if(pID == -1)
            {
                strWeap = !"{00BBF6}Name\t{00BBF6}Weapon\t{00BBF6}Ammo\n";
                foreach(new i : Player)
                {
                    GetPlayerWeaponData(i, 7, weap[0][0], weap[0][1]);
                    GetPlayerWeaponData(i, 8, weap[1][0], weap[1][1]);
                    strTemp[0] = EOS;
                    //--------------------------------------------------------------
                    if(WEAPON_ROCKETLAUNCHER <= weap[0][0] <= WEAPON_MINIGUN)
                    {
                        GetWeaponNameEx(weap[0][0], weapon);
                        format(strTemp, sizeof(strTemp), "{00FF00}%s {00BBF6}(ID:%d) \t{00FF00}%s \t{FF0000}%d\n", ReturnName(i), i, weapon, weap[0][1]),CountW++;
                    }
                    if(WEAPON_GRENADE <= weap[1][0] <= WEAPON_MOLTOV)
                    {
                        GetWeaponNameEx(weap[1][0], weapon);
                        if(!strTemp[0]) format(strTemp, sizeof(strTemp), "{00FF00}%s {00BBF6}(ID:%d) \t{00FF00}%s \t{FF0000}%d\n", ReturnName(i), i, weapon, weap[1][1]);
                        else format(strTemp, sizeof(strTemp), "%s{00FF00}%s {00BBF6}(ID:%d) \t{00FF00}%s \t{FF0000}%d\n", strTemp, ReturnName(i), i, weapon, weap[1][1]);
                        CountW++;
                    }
                    if(strTemp[0])
                    {
                        strpack(strDest,strTemp);
                        strcat(strWeap,strDest);
                    }
                }
                if(!CountW) SendClientMessage(playerid, 0xFF000000, "USAGE: {49FFFF}/weaps [ID/Name]");
                else{
                    strWeap{strlen(strWeap)-1} = EOS;
                    ShowPlayerDialog(playerid, 123, DIALOG_STYLE_TABLIST_HEADERS, "{BBFF00}Players with {00BBF6}Big Weapons", strWeap, "Close", ""), SendCommandToAdmins(playerid, "Weaps");
                }
            }
            else
            {
                for(new i=0; i != 13; i++)
                {
                    GetPlayerWeaponData(pID, i, weap[0][0], weap[0][1]);
                    if(weap[0][0] > 0 && weap[0][1] > 0)
                        CountW++;
                }
                if(CountW < 1) SendClientMessage(playerid, 0x00FF0000, "This player don't have Weapons!");
                else{
                    strWeap = !"{00BBF6}Weapon\t{00BBF6}Ammo\n";
                    for(new i=0; i != 13; i++)
                    {
                        GetPlayerWeaponData(pID, i, weap[0][0], weap[0][1]);
                        if(weap[0][0] > 0 && weap[0][1] > 0)
                        {
                            GetWeaponNameEx(weap[0][0], weapon);
                            if(weap[0][1] == 65535 || weap[0][1] == 1) format(strTemp, sizeof(strTemp), "{00FF00}%s \t{FF0000}1\n",weapon);
                            else format(strTemp, sizeof(strTemp), "{00FF00}%s \t{FF0000}%d\n",weapon, weap[0][1]);

                            strpack(strDest,strTemp);
                            strcat(strWeap,strDest);
                        }
                    }
                    strWeap{strlen(strWeap)-1} = EOS;
                    format(strTemp, sizeof(strTemp), "{BBFF00}%s's {00BBF6}Weapons:", ReturnName(pID)),
                    ShowPlayerDialog(playerid, 123, DIALOG_STYLE_TABLIST_HEADERS, strTemp, strWeap, "Close", ""), SendCommandToAdmins(playerid, "Weaps");
                }
            }
        }
    }
    return 1;
}
Try this
Reply
#3

It gives me those errors:

Код:
D:\Altele\SAMP\XSW V1\gamemodes\XSW.pwn(8692) : error 017: undefined symbol "weapon"
D:\Altele\SAMP\XSW V1\gamemodes\XSW.pwn(8693) : error 017: undefined symbol "weapon"
D:\Altele\SAMP\XSW V1\gamemodes\XSW.pwn(8697) : error 017: undefined symbol "weapon"
D:\Altele\SAMP\XSW V1\gamemodes\XSW.pwn(8698) : error 017: undefined symbol "weapon"
D:\Altele\SAMP\XSW V1\gamemodes\XSW.pwn(8699) : error 017: undefined symbol "weapon"
D:\Altele\SAMP\XSW V1\gamemodes\XSW.pwn(8730) : error 017: undefined symbol "weapon"
D:\Altele\SAMP\XSW V1\gamemodes\XSW.pwn(8731) : error 017: undefined symbol "weapon"
D:\Altele\SAMP\XSW V1\gamemodes\XSW.pwn(8732) : error 017: undefined symbol "weapon"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


8 Errors.
Where should I define this variable ? If I define it in /weaps command, it gives me those errors:

Код:
D:\Altele\SAMP\XSW V1\gamemodes\XSW.pwn(8692) : error 035: argument type mismatch (argument 2)
D:\Altele\SAMP\XSW V1\gamemodes\XSW.pwn(8697) : error 035: argument type mismatch (argument 2)
D:\Altele\SAMP\XSW V1\gamemodes\XSW.pwn(8730) : error 035: argument type mismatch (argument 2)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
Line 8692: GetWeaponNameEx(weap[0][0], weapon);
Line 8697: GetWeaponNameEx(weap[1][0], weapon);
Line 8730: GetWeaponNameEx(weap[0][0], weapon);
Reply
#4

Change new CountW; to new CountW,weapon[24];
Reply
#5

No.. That's not what I wanted... Now, when I type /weaps and I don't complete the param, it gives me the Player Not Connected Error, and when I complete the param (for example /weaps 0), it shows me a Dialog Style Tablist with ID 0's Big Weapons...

What I actually want is, when you type /weaps and you don't complete the param (when you type just /weaps, not /weaps 0, /weaps 1 or any other /weaps [ID]), if any player on the server have big any weapon, you see a Dialog Style Tablist with it's big weapons, as in my first post.

If there are no players with big weapons on the server, you see command's usage, as in my first post.
If you complete the param (if you type /weaps 0 or /weaps 1 or any other /weaps [ID]), you see in a SendClientMessage all player's weapons...
Reply
#6

Yes sscanf returns INVALID_PLAYER_ID instead -1 ( I don't know why, maybe bug or old version sscanf ? ) if you type only /weaps

Quote:
Originally Posted by TheRullZ
Посмотреть сообщение
If you complete the param (if you type /weaps 0 or /weaps 1 or any other /weaps [ID]), you see in a SendClientMessage all player's weapons...
Why in SendClientMessage? in dialog looks better
Reply
#7

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Yes sscanf returns INVALID_PLAYER_ID instead -1 ( I don't know why, maybe bug or old version sscanf ? ) if you type only /weaps


Why in SendClientMessage? in dialog looks better
Okay, we let there a Dialog, but I'll have to add in it all player's weapons, and when SSCANF returns me INVALID_PLAYER_ID, what can I do to return a dialog with all big weapons of all online players, and if there is no one with big weapons, an simple SendClientMessage ?
Reply
#8

pawn Код:
CMD:weaps(playerid, params[])
{
    if(Player[playerid][Level] < 3 || Player[playerid][VIP] < 7) ErrorMessages(playerid, 4);
    else
    {
        new pID, bool:all = isnull(params);
        sscanf(params, "U(-1)", pID);
        if(pID == INVALID_PLAYER_ID && !all) ERROR_NotConnected(playerid);
        else
        {
            new CountW,weapon[24];
            static strTemp[220],strDest[220 char],strWeap[5500 char],weap[2][2];
            if(all)
            {
                strWeap = !"{00BBF6}Name\t{00BBF6}Weapon\t{00BBF6}Ammo\n";
                foreach(new i : Player)
                {
                    GetPlayerWeaponData(i, 7, weap[0][0], weap[0][1]);
                    GetPlayerWeaponData(i, 8, weap[1][0], weap[1][1]);
                    strTemp[0] = EOS;
                    //--------------------------------------------------------------
                    if(WEAPON_ROCKETLAUNCHER <= weap[0][0] <= WEAPON_MINIGUN)
                    {
                        GetWeaponNameEx(weap[0][0], weapon);
                        format(strTemp, sizeof(strTemp), "{00FF00}%s {00BBF6}(ID:%d) \t{00FF00}%s \t{FF0000}%d\n", ReturnName(i), i, weapon, weap[0][1]),CountW++;
                    }
                    if(WEAPON_GRENADE <= weap[1][0] <= WEAPON_MOLTOV)
                    {
                        GetWeaponNameEx(weap[1][0], weapon);
                        if(!strTemp[0]) format(strTemp, sizeof(strTemp), "{00FF00}%s {00BBF6}(ID:%d) \t{00FF00}%s \t{FF0000}%d\n", ReturnName(i), i, weapon, weap[1][1]);
                        else format(strTemp, sizeof(strTemp), "%s{00FF00}%s {00BBF6}(ID:%d) \t{00FF00}%s \t{FF0000}%d\n", strTemp, ReturnName(i), i, weapon, weap[1][1]);
                        CountW++;
                    }
                    if(strTemp[0])
                    {
                        strpack(strDest,strTemp);
                        strcat(strWeap,strDest);
                    }
                }
                if(!CountW) SendClientMessage(playerid, 0xFF000000, "USAGE: {49FFFF}/weaps [ID/Name]");
                else{
                    strWeap{strlen(strWeap)-1} = EOS;
                    ShowPlayerDialog(playerid, 123, DIALOG_STYLE_TABLIST_HEADERS, "{BBFF00}Players with {00BBF6}Big Weapons", strWeap, "Close", ""), SendCommandToAdmins(playerid, "Weaps");
                }
            }
            else
            {
                for(new i=0; i != 13; i++)
                {
                    GetPlayerWeaponData(pID, i, weap[0][0], weap[0][1]);
                    if(weap[0][0] > 0 && weap[0][1] > 0)
                        CountW++;
                }
                if(CountW < 1) SendClientMessage(playerid, 0x00FF0000, "This player don't have Weapons!");
                else{
                    strWeap = !"{00BBF6}Weapon\t{00BBF6}Ammo\n";
                    for(new i=0; i != 13; i++)
                    {
                        GetPlayerWeaponData(pID, i, weap[0][0], weap[0][1]);
                        if(weap[0][0] > 0 && weap[0][1] > 0)
                        {
                            GetWeaponNameEx(weap[0][0], weapon);
                            if(weap[0][1] == 65535 || weap[0][1] == 1) format(strTemp, sizeof(strTemp), "{00FF00}%s \t{FF0000}1\n",weapon);
                            else format(strTemp, sizeof(strTemp), "{00FF00}%s \t{FF0000}%d\n",weapon, weap[0][1]);

                            strpack(strDest,strTemp);
                            strcat(strWeap,strDest);
                        }
                    }
                    strWeap{strlen(strWeap)-1} = EOS;
                    format(strTemp, sizeof(strTemp), "{BBFF00}%s's {00BBF6}Weapons:", ReturnName(pID)),
                    ShowPlayerDialog(playerid, 123, DIALOG_STYLE_TABLIST_HEADERS, strTemp, strWeap, "Close", ""), SendCommandToAdmins(playerid, "Weaps");
                }
            }
        }
    }
    return 1;
}
Reply
#9

Oh, it's very good now! Thank you very much, you're a savior!

There is just one more last small problem... Instead showing 'Molotovs', the Dialogs are showing 'RocketLauncherMolotovs'... There is a string wich should be setted to EOS ('\0'), and is not, and I don't know wich...



I don't want to destroy the command, so I think is better to ask you wich string should be setted to 0 and where...
Reply
#10

Yup thats wiki xd
should be
pawn Код:
GetWeaponNameEx(weaponid, weapon[], len = sizeof(weapon))
{
    weapon[0] = EOS;
    switch(weaponid)
    {
        case 18: return strcat(weapon, "Molotovs", len);
        case 44: return strcat(weapon, "Night Vision Goggles", len);
        case 45: return strcat(weapon, "Thermal Goggles", len);
        default: return GetWeaponName(weaponid, weapon, len);
    }
    return false;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)