Question Info: Function, [...] is correct ? - SOLVED, Thanks. -
Speed++ - 27.06.2012
Function:
PHP код:
GivePlayerWeapons(playerid, params)
{
new
start = 1,
num = numargs();
for(new i = start; i < num; i++)
{
GivePlayerWeapon(playerid, getarg(i), getarg(i++));
}
return 1;
}
Example usage:
PHP код:
GivePlayerWeapons(playerid, 9, 26, 32, 1, 3, 4);
is correct
??
Re: Question Info: Function, [...] is correct ? -
JaTochNietDan - 27.06.2012
Why ask if it's correct, why not test it?
If you would have tested it, you would've found out instantly that it was wrong instead of having to wait for a response here!
I believe the correct format for an unspecified number of parameters is this:
pawn Код:
GivePlayerWeapons(playerid, ...)
{
new
start = 1,
num = numargs();
for(new i = start; i < num; i++)
{
GivePlayerWeapon(playerid, getarg(i), getarg(i + 1));
}
return 1;
}
Additionally, using ++ increments the integer, so you don't really want to do that inside the getarg function, as that doesn't appear to be what you're intending to do. You appear to be looking for the index + 1, which is what I have edited it to as an example.
Hope that helps.
Re: Question Info: Function, [...] is correct ? -
Speed++ - 27.06.2012
Edit.
|
|
|
\/
Re: Question Info: Function, [...] is correct ? - SOLVED -
Speed++ - 28.06.2012
EDIT:
Don't work...
PHP код:
GivePlayerWeapons(playerid, ...)
{
new
start = 1,
num = numargs();
for(new i = start; i < num; i++)
{
GivePlayerWeapon(playerid, getarg(i), getarg(i + 1));
}
return 1;
}
use...
PHP код:
GivePlayerWeapons(playerid, 9, 1, 26, 400, 46, 450); // Chainsaw, Sawnoff Shotgun & Tec-9
give me a
parachute, Brass Knuckles, Chainsaw, Sawnoff Shotgun, Tec-9
the syntax is:
PHP код:
GivePlayerWeapons(playerid, weapon_1, ammo_1, weapon_2, ammo_2, weapon_3, ammo_3);
etc
Re: Question Info: Function, [...] is correct ? - SOLVED -
JaTochNietDan - 28.06.2012
Quote:
Originally Posted by Speed++
EDIT:
Don't work...
PHP код:
GivePlayerWeapons(playerid, ...)
{
new
start = 1,
num = numargs();
for(new i = start; i < num; i++)
{
GivePlayerWeapon(playerid, getarg(i), getarg(i + 1));
}
return 1;
}
use...
PHP код:
GivePlayerWeapons(playerid, 9, 1, 26, 400, 46, 450); // Chainsaw, Sawnoff Shotgun & Tec-9
give me a parachute, Brass Knuckles, Chainsaw, Sawnoff Shotgun, Tec-9
the syntax is:
PHP код:
GivePlayerWeapons(playerid, weapon_1, ammo_1, weapon_2, ammo_2, weapon_3, ammo_3);
etc
|
pawn Код:
GivePlayerWeapons(playerid, ...)
{
new
start = 1,
num = numargs();
for(new i = start; i < num; i+= 2)
{
GivePlayerWeapon(playerid, getarg(i), getarg(i + 1));
}
return 1;
}
Problem was you would need to increment the index by 2 every time the loop iterates, as you need to jump an extra argument ahead to get to the next weapon.
Hope that helps.