SA-MP Forums Archive
Question Info: Function, [...] is correct ? - SOLVED - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Question Info: Function, [...] is correct ? - SOLVED (/showthread.php?tid=354640)



Question Info: Function, [...] is correct ? - SOLVED, Thanks. - Speed++ - 27.06.2012

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 ??


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 
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


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 
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.