PDA

View Full Version : [Tutorial] [Tut] How to make a /givegun command using dcmd!


gemadon
13/12/2008, 10:09 PM
Note: to do this, you must download the dini include and the utils include!

You must add this to your script: stock sscanf(string[], format[], {Float,_}:...)
{
new
formatPos = 0,
stringPos = 0,
paramPos = 2,
paramCount = numargs();
while (paramPos < paramCount && string[stringPos])
{
switch (format[formatPos++])
{
case '\0':
{
return 0;
}
case 'i', 'd':
{
new
neg = 1,
num = 0,
ch = string[stringPos];
if (ch == '-')
{
neg = -1;
ch = string[++stringPos];
}
do
{
stringPos++;
if (ch >= '0' && ch <= '9')
{
num = (num * 10) + (ch - '0');
}
else
{
return 1;
}
}
while ((ch = string[stringPos]) && ch != ' ');
setarg(paramPos, 0, num * neg);
}
case 'h', 'x':
{
new
ch,
num = 0;
while ((ch = string[stringPos++]))
{
switch (ch)
{
case 'x', 'X':
{
num = 0;
continue;
}
case '0' .. '9':
{
num = (num << 4) | (ch - '0');
}
case 'a' .. 'f':
{
num = (num << 4) | (ch - ('a' - 10));
}
case 'A' .. 'F':
{
num = (num << 4) | (ch - ('A' - 10));
}
case ' ':
{
break;
}
default:
{
return 1;
}
}
}
setarg(paramPos, 0, num);
}
case 'c':
{
setarg(paramPos, 0, string[stringPos++]);
}
case 'f':
{
new tmp[25];
strmid(tmp, string, stringPos, stringPos+sizeof(tmp)-2);
setarg(paramPos, 0, _:floatstr(tmp));
}
case 's', 'z':
{
new
i = 0,
ch;
if (format[formatPos])
{
while ((ch = string[stringPos++]) && ch != ' ')
{
setarg(paramPos, i++, ch);
}
if (!i) return 1;
}
else
{
while ((ch = string[stringPos++]))
{
setarg(paramPos, i++, ch);
}
}
stringPos--;
setarg(paramPos, i, '\0');
}
default:
{
continue;
}
}
while (string[stringPos] && string[stringPos] != ' ')
{
stringPos++;
}
while (string[stringPos] == ' ')
{
stringPos++;
}
paramPos++;
}
while (format[formatPos] == 'z') formatPos++;
return format[formatPos];
}

Also: #define SCM SendClientMessage // Above OnFilterScriptInIt

Ok, in this tutorial, I will be teaching you how to make a /givegun command using dini (obviously).

First of all, you must have this above OnFilterScriptInIt..

#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

Then do this..

public OnPlayerCommandText(playerid, cmdtext [])
{
dcmd(givegun, 7, cmdtext);
return 0;
}

that tells the script that /givegun is the command, the (7) is there because that is the number of letters in the word givegun.

Once you have that done, just below the end of body (}) type:

dcmd_givegun(playerid, params[])
{

Now we're ready to make the script! You must include this under the start of body

You must include... new id = ReturnUser(params); <---That tells the script that the id its focusing on is whatever the player typed..

then include this after "new id" new mr[24]; new pname[24]; new str[256];..

By now the script should look something like..

public OnPlayerCommandText(playerid, cmdtext [])
{
dcmd(givegun, 7, cmdtext);
return 0;
}

dcmd_givegun(playerid, params[])
{
new id = ReturnUser(params); new mr[24]; new pname[24];

Ok, so now you must add this.. new gpw; new gpa; and under that put.. gpw = GetPlayerWeapon(playerid);
gpa = GetPlayerAmmo(playerid); this tells the script what the two variables, gpw, and gpa means..

you must include this under..

GetPlayerName(id, mr, 24);
GetPlayerName(playerid, pname, 24);

That tells the script that the variable mr and pname means get the player's name, the one thats recieving the gun and the one that's giving the gun.

Under that add.. if (sscanf(params, "d", id))
{
SendClientMessage(playerid, 0xFF0000AA, "Usage: /givewep [playerid]");
return 1;
} <---This means so if the player types just /givewep without stating the playerid to give the weapon to, it will display that message..

Now add this.. else if(GetPlayerWeapon(playerid) == 0)
{
SCM(playerid, COLOR_RED, "No weapon equipped!");
} <-- This means if the player does not have a weapon in hand, it will display a message..

Almost done! now.. put this..

else if(GetPlayerWeapon(playerid) > 0)
{
GivePlayerWeapon(id, gpw, gpa);
}
return 1;
} <---This will make it so if the player actually has a weapon, it will give the id the weapon and the amount of ammo it has, and thats the end of the script!

So it should look like..

public OnPlayerCommandText(playerid, cmdtext [])
{
dcmd(givegun, 7, cmdtext);
return 0;
{

dcmd_givegun(playerid, params[])
{
new id = ReturnUser(params); new mr[24]; new pname[24]; new str[256];
new gpw; new gpa;
gpw = GetPlayerWeapon(playerid);
gpa = GetPlayerAmmo(playerid);
GetPlayerName(id, mr, 24);
GetPlayerName(playerid, pname, 24);
format(str, sizeof(str), "%s Hands %s a weapon", pname, mr);
if (sscanf(params, "d", id))
{
SendClientMessage(playerid, 0xFF0000AA, "Usage: /givewep [playerid]");
return 1;
}
else if(GetPlayerWeapon(playerid) == 0)
{
SCM(playerid, COLOR_RED, "No weapon equipped!");
}
else if(GetPlayerWeapon(playerid) > 0)
{
GivePlayerWeapon(id, gpw, gpa);
}
return 1;
}

I may have left out things that may cause you to get errors or warnings, if so, post them here! Thank you for reading this tutorial!

gemadon
13/12/2008, 10:27 PM
What do u mean, it does work lol..

LarzI
13/12/2008, 10:54 PM
ok?
So SCM is a default function? no!

FUNExtreme
13/12/2008, 10:55 PM
Now you have to explain me why I need dini for this. As i looked you did not even use it

gemadon
13/12/2008, 11:21 PM
Now you have to explain me why I need dini for this. As i looked you did not even use it


Umm.. if you dont use dini then the script will not know what dcmd is and stuff..

gemadon
13/12/2008, 11:22 PM
ok?
So SCM is a default function? no!


Ok i fixed that, gosh u dont have to be so hard on me, this was straight out of my gamemode I just made a few errors..

x-cutter
13/12/2008, 11:39 PM
Maybe if you added to your code the ReturnUser function it would be better for newbies.

Zezombia
14/12/2008, 12:28 AM
Umm.. if you dont use dini then the script will not know what dcmd is and stuff..


Yes it will, dini has nothing to do with dcmd other then the fact that their made by the same person. Rename this:

[Tut] How to make a /givegun command using dcmd!

FUNExtreme
14/12/2008, 12:57 AM
Umm.. if you dont use dini then the script will not know what dcmd is and stuff..


Yes it will, dini has nothing to do with dcmd other then the fact that their made by the same person. Rename this:

[Tut] How to make a /givegun command using dcmd!


Now he hears it from more then 1 person, so please remove everything about dini

matt2127
14/12/2008, 02:36 AM
I think it's good for your first tutorial. Good work. Just make sure to make indentations when posting on the forums.

anonymoushacker
02/08/2009, 07:51 PM
Uhmm......



whats this?

C:\Users\rac\Desktop\Gta San Andreas\filterscripts\sugg.pwn(178) : error 017: undefined symbol "ReturnUser"


whats the solution to it?

that error is reffering to this

new id = ReturnUser(params);

gemadon
07/08/2009, 01:36 AM
Uhmm......



whats this?

C:\Users\rac\Desktop\Gta San Andreas\filterscripts\sugg.pwn(178) : error 017: undefined symbol "ReturnUser"


whats the solution to it?

that error is reffering to this

new id = ReturnUser(params);


You must use DCMD commands in order for this to work, if you dont, PAWNO will not know what ReturnUser(params) is, DCMD tells pawno what params is

ruarai
07/08/2009, 07:08 AM
no it doesnt... your thinking of dutils or something :?:

gemadon
07/08/2009, 10:34 PM
oh yeah, thats right ^^

pmk1
19/05/2010, 09:48 PM
well can you tell me even if i use dutils i get the undefined paramusers?