Hello There, Guest! Login or Register


Useful Functions/Snippets/Commands
#25
Meh, was bored before so I whipped up this:

(02-02-2009, 06:04 PM)Jay_ link Wrote: GivePlayerSpawnWeapon

This is a useful function that a lot of people often request. It gives a player a spawn weapon.

Put this above OnGameModeInit:
Code:
static stock iPlayerSpawnWeapon[MAX_PLAYERS][50];

And put this at the bottom of your code:
Code:
stock GivePlayerSpawnWeapon(iPlayerID,iWeaponID,iAmmo)
{
    // Is the player connected?
    if(!IsPlayerConnected(iPlayerID))
        return false;
    // Is the weapon ID valid?
    if(iWeaponID < 1 || iWeaponID > 50)
        return false;

    // If a player already has this spawn weapon, just add the ammo.
    if(iPlayerSpawnWeapon[iPlayerID][iWeaponID] > 0)
    {
        iPlayerSpawnWeapon[iPlayerID][iWeaponID] += iAmmo;
        GivePlayerWeapon(iPlayerID,iWeaponID,iAmmo);
        return 1;
    }
    
    iPlayerSpawnWeapon[iPlayerID][iWeaponID] = iAmmo;
    GivePlayerWeapon(iPlayerID,iWeaponID,iAmmo);
    return true;
}

Now, under OnPlayerSpawn, add this:
Code:
    for(new iWeaponID; iWeaponID < 50; iWeaponID++)
    {
        if(iPlayerSpawnWeapon[playerid][iWeaponID] > 0)
            GivePlayerWeapon(playerid,iWeaponID,iPlayerSpawnWeapon[playerid][iWeaponID]);
    }

Jay

I know Raymond was after something like this..
Reply


Messages In This Thread
Useful Functions/Snippets/Commands - by Jay - 04-21-2008, 03:19 PM
Re: Useful Functions/Snippets/Commands - by Jay - 04-21-2008, 07:42 PM
Re: Useful Functions/Snippets/Commands - by Smoke - 04-23-2008, 06:50 AM
Re: Useful Functions/Snippets/Commands - by Jay - 04-23-2008, 04:54 PM
Re: Useful Functions/Snippets/Commands - by Smoke - 04-24-2008, 10:18 AM
Re: Useful Functions/Snippets/Commands - by Jay - 04-29-2008, 01:03 PM
Re: Useful Functions/Snippets/Commands - by Jay - 05-08-2008, 11:54 AM
Re: Useful Functions/Snippets/Commands - by Jay - 02-02-2009, 10:17 PM