SA-MP Forums Archive
Weapon ID won't return - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Weapon ID won't return (/showthread.php?tid=309570)



Weapon ID won't return - Outcast - 08.01.2012

Well, I want a player to be able to save a weapon, but when I try to save it, I get the command saved instead of the weapon ID.

This is the code:
pawn Код:
if (strcmp("store", option, true, 4) == 0){
                    new option2[50], number, Float:Armor;
                    if(sscanf(params, "s[30]s[30]", option, option2)) return SendClientMessage(playerid, COLOR_USAGE, "[USAGE:] /trunk store weapon | armor | money.");
                   
                    if (strcmp("weapon", option2, true, 4) == 0){
                        if(GetPlayerScore(playerid) == 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR:] You need to be level 2 or above to use this.");
                        if(GetPlayerWeapon(playerid) == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR:] You are not holding a weapon.");
                        new str[80], weapname[20];
                        vInfo[vid][TrunkWeapon1] = GetPlayerWeapon(playerid);
                        print(vInfo[vid][TrunkWeapon1]);
                        format(str, sizeof(str), "stores %s in the trunk of the vehicle", GetWeaponName(vInfo[vid][TrunkWeapon1], weapname, sizeof(weapname)));
                        return PlayerActionMsg(playerid, str)
                    }
                 }



Re: Weapon ID won't return - Jochemd - 08.01.2012

pawn Код:
if(!strcmp("store", option, true))
{
    new option2[50], number, Float:Armor;
    if(sscanf(params, "s[30]s[30]", option, option2)) return SendClientMessage(playerid, COLOR_USAGE, "[USAGE:] /trunk store weapon | armor | money.");
    {
        if(!strcmp("weapon", option2, true))
        {
            if(GetPlayerScore(playerid) == 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR:] You need to be level 2 or above to use this.");
            if(GetPlayerWeapon(playerid) == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR:] You are not holding a weapon.");
            new str[80], weapname[20];
            vInfo[vid][TrunkWeapon1] = GetPlayerWeapon(playerid);
            GetWeaponName(vInfo[vid][TrunkWeapon1], weapname, sizeof(weapname));
            format(str, sizeof(str), "stores %s in the trunk of the vehicle", weapname);
            return PlayerActionMsg(playerid, str);
        }
    }
}
GetWeaponName doesn't return the weapon name, but it stores it in the string you gave, so it stores in weapname. So, use weapname to show the weapon!

Edit: Just noticed. You are using strcmp before you even did sscanf, so I doubt this works.


Re: Weapon ID won't return - Outcast - 08.01.2012

Yeah, but I don't have a problem with GetWeaponName, I have a problem with GetPlayerWeapon. The weapon ID should be stored in the variable, but it isn't. When I print the weapon ID, nothing shows up. Instead of weapon id, it stores me "store weapon" in the string

pawn Код:
vInfo[vid][TrunkWeapon1] = GetPlayerWeapon(playerid); // NOT WORKING?
This is the result I get (chat log)
Код:
[09:49:16] * Marcus Keaton stores   in the trunk of the vehicle

[09:49:18] ___________Trunk___________

[09:49:18] Weapon Slot 1:  store weapon  << Here should go a weapon name, from GetWeaponName(vInfo[vid][TrunkWeapon1]

[09:49:18] ___________________________

[09:49:18] * Marcus Keaton checks the trunk of the vehicle.



Re: Weapon ID won't return - Jochemd - 08.01.2012

Hmm, well, then I don't know. Try to print GetPlayerWeapon to see what it outputs.

Just wondering
Код:
[09:49:18] Weapon Slot 1:  store weapon
Are you using %s here? Should be %d.


Re: Weapon ID won't return - Outcast - 08.01.2012

Here's the code for /trunk check command

pawn Код:
if (strcmp("check", option, true, 4) == 0){
                    new str[50], weapname[20];
                    GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                    if(boot == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR:] The trunk is closed.");
                    SendClientMessage(playerid, COLOR_USAGE, "___________Trunk___________");
                    if(vInfo[vid][TrunkWeapon1] != 0){
                        format(str, sizeof(str), "Weapon Slot 1: %s", GetWeaponName(vInfo[vid][TrunkWeapon1], weapname, sizeof(weapname)));
                        SendClientMessage(playerid, COLOR_USAGE, str)
                    }
                    if(vInfo[vid][TrunkWeapon2] != 0){
                        format(str, sizeof(str), "Weapon Slot 2: %s", GetWeaponName(vInfo[vid][TrunkWeapon2], weapname, sizeof(weapname)));
                        SendClientMessage(playerid, COLOR_USAGE, str);
                    }
                    if(vInfo[vid][TrunkWeapon3] != 0){
                        format(str, sizeof(str), "Weapon Slot 3: %s", GetWeaponName(vInfo[vid][TrunkWeapon3], weapname, sizeof(weapname)));
                        SendClientMessage(playerid, COLOR_USAGE, str);
                    }
                    if(vInfo[vid][TrunkArmor] != 0){
                        format(str, sizeof(str), "Armor: %s", vInfo[vid][TrunkArmor]);
                        SendClientMessage(playerid, COLOR_USAGE, str);
                    }
                    if(vInfo[vid][TrunkMoney] != 0){
                        format(str, sizeof(str), "Money: %s", vInfo[vid][TrunkMoney]);
                        SendClientMessage(playerid, COLOR_USAGE, str);
                    }
                    SendClientMessage(playerid, COLOR_USAGE, "___________________________");
               
                    return PlayerActionMsg(playerid, "check the trunk of the vehicle.");   
                }
               
                if (strcmp("store", option, true, 4) == 0){
                    new option2[50], number, Float:Armor;
                    if(sscanf(params, "s[30]s[30]", option, option2)) return SendClientMessage(playerid, COLOR_USAGE, "[USAGE:] /trunk store weapon | armor | money.");
                    GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                    if(boot == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR:] The trunk is closed.");
                   
                    if (strcmp("weapon", option2, true, 4) == 0){
                        if(GetPlayerScore(playerid) == 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR:] You need to be level 2 or above to use this.");
                        if(GetPlayerWeapon(playerid) == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR:] You are not holding a weapon.");
                        new str[80], weapname[20];
                        vInfo[vid][TrunkWeapon1] = GetPlayerWeapon(playerid);
                        print(vInfo[vid][TrunkWeapon1]);
                        GetWeaponName(vInfo[vid][TrunkWeapon1], weapname, sizeof(weapname))
                        format(str, sizeof(str), "stores %s in the trunk of the vehicle", weapname);
                        return PlayerActionMsg(playerid, str)
                    }
                 }



Re: Weapon ID won't return - Jochemd - 08.01.2012

pawn Код:
format(str, sizeof(str), "Weapon Slot 1: %s", GetWeaponName(vInfo[vid][TrunkWeapon1], weapname, sizeof(weapname)));
SendClientMessage(playerid, COLOR_USAGE, str);
Quote:
Originally Posted by Jochemd
Посмотреть сообщение
GetWeaponName doesn't return the weapon name, but it stores it in the string you gave, so it stores in weapname. So, use weapname to show the weapon!



Re: Weapon ID won't return - Outcast - 08.01.2012

Lol, I read what you said and I haven't noticed it. Thanks man


Re: Weapon ID won't return - Jochemd - 08.01.2012

Quote:
Originally Posted by Outcast
Посмотреть сообщение
Lol, I read what you said and I haven't noticed it. Thanks man
No problem, you're welcome.