SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 21/11/2010, 05:20 PM   #1
0ne
Gangsta
 
Join Date: Sep 2009
Posts: 585
Reputation: 0
Default Give a weapon with integer and string?

pawn Code:
if(sscanf(inputtext, "d[24]",weaponid) || sscanf(inputtext, "s[24]",weaponid))
            {
                ShowPlayerDialog(playerid,115,DIALOG_STYLE_INPUT,"Spawn weapons","Input the spawn weapon id(name):","Select","Cancel");
                return 1;
            }
            if (weaponid < 0 || weaponid > 47)
            {
                ShowPlayerDialog(playerid,115,DIALOG_STYLE_INPUT,"Spawn weapons","Input the spawn weapon id(name):","Select","Cancel");
                SendClientMessage(playerid,COLOR_RED,"*[INFO]: Invalid weapon id!");
                return 1;
            }

Any ideas how to give a weapon with integer or string? in the dialog input u can write desert/dese/eagle << string or 24 << integer and get the weapon?
0ne is offline  
Old 21/11/2010, 05:21 PM   #2
Cameltoe
High-roller
 
Cameltoe's Avatar
 
Join Date: Apr 2010
Location: Norway
Posts: 1,768
Reputation: 24
Default Re: Give a weapon with integer and string?

Check ladmin.
__________________

Quote:
Originally Posted by Cameltoe View Post
Share the progress so others who are looking for the same also find's their answer.
Quote:
Originally Posted by teomakedonija View Post
ahaha i don't want
Rep++;
Cameltoe is offline  
Old 21/11/2010, 05:23 PM   #3
0ne
Gangsta
 
Join Date: Sep 2009
Posts: 585
Reputation: 0
Default Re: Give a weapon with integer and string?

His links are broken, it gives something else to download instead of ladmin, and i want to make the script unique.
0ne is offline  
Old 21/11/2010, 05:26 PM   #4
Cameltoe
High-roller
 
Cameltoe's Avatar
 
Join Date: Apr 2010
Location: Norway
Posts: 1,768
Reputation: 24
Default Re: Give a weapon with integer and string?

Quote:
Originally Posted by 0ne View Post
His links are broken, it gives something else to download instead of ladmin, and i want to make the script unique.
I men't that you should read the script, though if the link is broken your pretty much stuck.
__________________

Quote:
Originally Posted by Cameltoe View Post
Share the progress so others who are looking for the same also find's their answer.
Quote:
Originally Posted by teomakedonija View Post
ahaha i don't want
Rep++;
Cameltoe is offline  
Old 21/11/2010, 05:27 PM   #5
0ne
Gangsta
 
Join Date: Sep 2009
Posts: 585
Reputation: 0
Default Re: Give a weapon with integer and string?

Well I'm not stuck as long as there is thousands of other scripters who can help me
0ne is offline  
Old 22/11/2010, 10:59 AM   #6
0ne
Gangsta
 
Join Date: Sep 2009
Posts: 585
Reputation: 0
Default Re: Give a weapon with integer and string?

help please..
0ne is offline  
Old 22/11/2010, 11:01 AM   #7
LarzI
High-roller
 
LarzI's Avatar
 
Join Date: Apr 2007
Location: Norway
Posts: 3,495
Reputation: 136
Default Re: Give a weapon with integer and string?

You do sscanf with a string, then use isNumeric to check if the input is numeric. If it is; use strval, if not search through a variable to find the desired ID for the weapon name.
__________________


NEW: [FS] Simple Cellphones

if( strfind( title, "REP", true ) != -1 )
{________________________________________
Sigh();__________________________
}________________________________________


LarzI is offline  
Old 22/11/2010, 11:26 AM   #8
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,201
Reputation: 3178
Default Re: Give a weapon with integer and string?

Try convert to a number first - not a string. If that fails then compare the string to weapon names in order (that's the method used in sscanf for getting a player by ID or name. There's no point using sscanf for only one parameter, especially only one string parameter.
Y_Less is offline  
Old 22/11/2010, 12:01 PM   #9
0ne
Gangsta
 
Join Date: Sep 2009
Posts: 585
Reputation: 0
Default Re: Give a weapon with integer and string?

I can't speak fluent English, so its kind of hard for me to understand some words cause I'm still learning, I can't understand everything in one pile, but i understand some of it ofc. I updated my code, see now:

pawn Code:
new weaponid;
            new weaponid2[24];
            new weapon;
            new string[128];
            new gangfile[256];
            format(gangfile,sizeof(gangfile),"Gangs/%d.txt",dUserINT(pName(playerid)).("PlayerGang"));
            if(sscanf(inputtext, "d[24]",weaponid) || sscanf(inputtext, "s[24]",weaponid2))
            {
                ShowPlayerDialog(playerid,115,DIALOG_STYLE_INPUT,"Spawn weapons","Input the spawn weapon id(name):","Select","Cancel");
                return 1;
            }
            if(!IsNumeric(weaponid2))
            {
                weapon = GetWeaponIDFromName(weaponid2);
            }
            else
            {
                weapon = weaponid;
            }
            if (weaponid < 0 || weaponid > 47)
            {
                ShowPlayerDialog(playerid,115,DIALOG_STYLE_INPUT,"Spawn weapons","Input the spawn weapon id(name):","Select","Cancel");
                SendClientMessage(playerid,COLOR_RED,"*[INFO]: Invalid weapon id!");
                return 1;
            }
            if(!IsValidWeapon(weapon))
            {
                ShowPlayerDialog(playerid,115,DIALOG_STYLE_INPUT,"Spawn weapons","Input the spawn weapon id(name):","Select","Cancel");
                SendClientMessage(playerid,COLOR_RED,"*[INFO]: Invalid weapon id!");
                return 1;
            }

It doesn't return the name if its not numeric, it should do like this:

desert, would apply a desert eagle , but instead of applying it gives me this line:

pawn Code:
if(sscanf(inputtext, "d[24]",weaponid) || sscanf(inputtext, "s[24]",weaponid2))
            {
                ShowPlayerDialog(playerid,115,DIALOG_STYLE_INPUT,"Spawn weapons","Input the spawn weapon id(name):","Select","Cancel");
                return 1;
            }
As u said ur words:

Quote:
Try convert to a number first - not a string
, does that mean i do this:

pawn Code:
if(sscanf(inputtext, "d[24]",weaponid)
and then check if its valid/numeric and so on, then if(sscanf(inputtext,"s[24]",weaponid(or weaponid2)?)) and do almost the same like with numbers?
0ne is offline  
Old 22/11/2010, 12:15 PM   #10
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,201
Reputation: 3178
Default Re: Give a weapon with integer and string?

I said you don't need sscanf at all.
Y_Less is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Take a weapon and give other one. xDENNNIISSSS Help Archive 2 13/09/2010 09:07 PM
format string array to integer? plutoniumman Help Archive 2 06/08/2010 04:17 AM
How to convert float to integer or string? CoaPsyFactor Help Archive 3 02/08/2010 08:24 PM
Give a weapon help matdav Help Archive 7 07/07/2010 05:11 AM
Are IP's an integer or string? Celson Help Archive 1 27/07/2009 08:19 AM


All times are GMT. The time now is 04:08 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.