[Help Please] Simple Weapon Command.
#1

This is gonna look so nooby to most of you, but hey I am new to scripting. I am trying to make a command to buy a gun with a certain ammount of ammo.
I understand I need to use sscanf for this, and I've used it a couple of times in my script with no issue but this just isnt working, so I made a test command to try and understand how it works.

This is the code (sorry if it isnt posted correctly).

Код:
CMD:testgun(playerid,params[]){

if(IsPlayerInRangeOfPoint(playerid, 2, 295.8800,-38.5147,1001.5156))
			{
			new gun;
			new bullets;
  	if(sscanf(params, "coltd", gun, bullets))
	    return givePlayerValidWeapon(playerid, 22, bullets);
   }
   return 1;
   }
This is SUPPOSED to give the player a "colt" (id 22) with a specified ammount of ammo ("bullets").

However typing /testgun will just give the player a colt, with 0 ammo. (so it dissapears instantly I just see it flash up in the top right). No matter whether I type /testgun, /testgun colt 50, /testgun blahblahblah, the results are the same.

I'm missing something, and just cannot figure out what it is.

Any help with this would be greatly appreciated!

Thanks
Reply
#2

Sscanf doesn't work like that. Also - for God's sake, indentation.

pawn Код:
CMD:testgun(playerid,params[]){

    if(IsPlayerInRangeOfPoint(playerid, 2, 295.8800,-38.5147,1001.5156))
    {
        new gun[5], bullets;
        if(!sscanf(params, "s[5]d", gun, bullets) && !strcmp(gun, "colt", true)) return givePlayerValidWeapon(playerid, 22, bullets);
    }
    return 1;
}
#Some explanation:
Sscanf will return false if every element is matched. So we need to search for string (5 chars will suffice for colt), and one integer (number of bullets). If sscanf is successful, then check if the string is equal "colt" (case insensitive) and return your function
Reply
#3

Ofcorse it will where you have defined how much bullets you will give?

Because sscanf ain't right!
Reply
#4

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Sscanf doesn't work like that. Also - for God's sake, indentation.

pawn Код:
CMD:testgun(playerid,params[]){

    if(IsPlayerInRangeOfPoint(playerid, 2, 295.8800,-38.5147,1001.5156))
    {
        new gun[5], bullets;
        if(!sscanf(params, "s[5]d", gun, bullets) && !strcmp(gun, "colt", true)) return givePlayerValidWeapon(playerid, 22, bullets);
    }
    return 1;
}
Thanks, sscanf is confusing the hell out of me right now. I *think* I understand what you've done there, I'm going to go and try it out.

It worked, thankyou VERY much
Now to go and practise sscanf some more - need to get my head around this
Reply
#5

Just always to define how much string will be .. here is some tutorial about strings .. KLICK ME
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)