Format again. How can I format() the vars?
#1

pawn Код:
COMMAND:giveweapon(playerid,params[]) {
    new
        weap[30],
        weapname[30],
        id,
        name1[30],
        name2[30],
        ammo,
        text[128];
    sscanf(params,"sii",id,weap,ammo);
    if(!IsNumeric(weap)) {
        format(weap,sizeof(weap),"%i",GetWeaponIDFromName(weap));
    }
    if(PlayerInfo[playerid][pAdminLevel] >= 4) {
        if(!isnull(params)) {
            if(IsPlayerConnected(id)) {
//this is where to code shows an error. (type mismatch)
            format(weap,sizeof(weap),"%i",weap);
                GetWeaponName(weap,weapname,sizeof(weapname));
                GetPlayerName(playerid,name1,sizeof(name1));
                GetPlayerName(id,name2,sizeof(name2));
                if(ammo == 0) {
                    ammo = 100;
                }
                format(text,sizeof(text),"Administrator \"%s\" has given \"%s\" a weapon: %s, ammo: %i.",name1,name2,weapname,ammo);
                SendClientMessageToAll(COLOR_BLUE,text);
                GivePlayerWeapon(id,weap,ammo);
(I haven't finished the code yet..)

I can't format the weap to be 'compatible' with GetWeaponName.
please DON'T rewrite or correct the code, I just want to know how does it became useable with GetWeaponName.
Reply
#2

Код:
format(weap,sizeof(weap),"%i",weap);
Hmm. You could try this:
Код:
format(weap,sizeof(weap),"%i",strval(weap));
Reply
#3

pawn Код:
GivePlayerWeapon(id,GetWeaponName(weap),ammo);
I'm assuming this is what you need?
Reply
#4

@Kwarde: still an error :[
@Skylar: yes, I want a /giveweapon, but I want to able to give a weapon with a weap name, so I tried to create one, only the format went wrong.
Reply
#5

pawn Код:
COMMAND:givegun(playerid, params[])
{
    new
        WeaponName[50],
        WeaponAmmo,
        user
    ;
    if(sscanf(params, "us[50]i", user, WeaponName, WeaponAmmo))
        return SendClientMessage(playerid, white, "[USAGE] /givegun [playerid] [weapon name] [weapon ammo]");
    if(PVar[playerid][pAdmin] >= 3)
    {
        GivePlayerWeapon(user, GetWeaponModelIDFromName(WeaponName), WeaponAmmo);
        SendClientMessage(user, white, "You have been given a weapon.");
    }
    else return ErrorMessage(playerid, 3);
    return 1;
}
Like that? You're going to need GetWeaponModelIDFromName and the WeaponName variable.

pawn Код:
GetWeaponModelIDFromName(wname[])
{
    for(new i = 0; i < 48; i++) {
        if (i == 19 || i == 20 || i == 21) continue;
        if (strfind(aWeaponNames[i], wname, true) != -1) {
            return i;
        }
    }
    return -1;
}
pawn Код:
new aWeaponNames[][32] =
{
    {"Unarmed"}, {"BrassKnuckles"}, {"GolfClub"}, {"NightStick"}, {"Knife"}, {"BaseballBat"},
    {"Shovel"}, {"PoolCue"}, {"Katana"}, {"Chainsaw"}, {"PurpleDildo"}, {"BigWhiteVibrator"},
    {"MedWhiteVibrator"}, {"SmlWhiteVibrator"}, {"Flowers"}, {"Cane"}, {"Grenade"}, {"Teargas"},
    {"Molotov"}, {"Empty Slot 1"}, {"Empty Slot 2"}, {"Empty Slot 3"}{"Colt45"}, {"SDPistol"},
    {"DesertEagle"}, {"Shotgun"}, {"SawnoffShotgun"}, {"Spas12"}, {"Mac10"},
    {"MP5"}, {"AK47"}, {"M4"}, {"Tec9"}, {"CountryRifle"}, {"Sniper"}, {"RPG"},
    {"HeatRPG"}, {"Flamethrower"}, {"Minigun"}, {"Satchel"}, {"Detonator"},
    {"SprayCan"}, {"Extinguisher"}, {"Camera"}, {"NVGoggles"}, {"IRGoggles"},
    {"Parachute"}, {"Fake Pistol"}
};
Reply
#6

variable = value;

Not format. Format is for strings.
Reply
#7

@Skylar: He asked not to rewrite the code.
@MP2: Nothing to say actually :P
Reply
#8

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
@Skylar: He asked not to rewrite the code.
@MP2: Nothing to say actually :P
Just giving him an example; He used sscanf wrong aswell.
Reply
#9

Except when he's using sscanf instead of sscanf2, or not? (With sscanf1 it just worked, something like that.)
Reply
#10

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
Except when he's using sscanf instead of sscanf2, or not? (With sscanf1 it just worked, something like that.)
Really? Hmm, I wasn't aware.. Learning comes from every angle now-a-days it seems.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)