Question Info: Function, [...] is correct ? - SOLVED
#1

Function:

PHP код:
GivePlayerWeapons(playeridparams)
{
    new
        
start 1,
        
num numargs();
    for(new 
startnumi++)
    {
        
GivePlayerWeapon(playeridgetarg(i), getarg(i++));
    }
    return 
1;

Example usage:

PHP код:
GivePlayerWeapons(playerid92632134); 
is correct ??
Reply
#2

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.
Reply
#3

Edit.

|
|
|
\/
Reply
#4

EDIT:

Don't work...

PHP код:
GivePlayerWeapons(playerid, ...) 

    new 
        
start 1
        
num numargs(); 
    for(new 
startnumi++) 
    { 
        
GivePlayerWeapon(playeridgetarg(i), getarg(1)); 
    } 
    return 
1

use...

PHP код:
GivePlayerWeapons(playerid912640046450); // Chainsaw, Sawnoff Shotgun & Tec-9 
give me a parachute, Brass Knuckles, Chainsaw, Sawnoff Shotgun, Tec-9

the syntax is:

PHP код:
GivePlayerWeapons(playeridweapon_1ammo_1weapon_2ammo_2weapon_3ammo_3); 
etc
Reply
#5

Quote:
Originally Posted by Speed++
Посмотреть сообщение
EDIT:

Don't work...

PHP код:
GivePlayerWeapons(playerid, ...) 

    new 
        
start 1
        
num numargs(); 
    for(new 
startnumi++) 
    { 
        
GivePlayerWeapon(playeridgetarg(i), getarg(1)); 
    } 
    return 
1

use...

PHP код:
GivePlayerWeapons(playerid912640046450); // Chainsaw, Sawnoff Shotgun & Tec-9 
give me a parachute, Brass Knuckles, Chainsaw, Sawnoff Shotgun, Tec-9

the syntax is:

PHP код:
GivePlayerWeapons(playeridweapon_1ammo_1weapon_2ammo_2weapon_3ammo_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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)