SA-MP Forums Archive
[Help Please] Simple Weapon Command. - 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: [Help Please] Simple Weapon Command. (/showthread.php?tid=422570)



[Help Please] Simple Weapon Command. - daddyblake - 14.03.2013

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


Re: [Help Please] Simple Weapon Command. - Misiur - 14.03.2013

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


Re: [Help Please] Simple Weapon Command. - Scrillex - 14.03.2013

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

Because sscanf ain't right!


Re: [Help Please] Simple Weapon Command. - daddyblake - 14.03.2013

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


Re: [Help Please] Simple Weapon Command. - Scrillex - 14.03.2013

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