gemadon
13/12/2008, 09: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!
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!