[Needed] Weapon will stay in hand untill stored away with a command.
#1

So the title says everything. I need a script that you couldn't scroll your weapon away from your hand. Only way to be placed away is storing it off by the server, ex. /trunk putgun etc.

Any ideas? I'd like to have a 'newb show' like, this goes into that kind of stuff, and this goes in the bottom of the script etc.


Thanks for responses.
Reply
#2

Just run a timer checking if the player has the weapon that was given to them, if not regive them it. Means every time they scroll it'll immediately set their weapon back.
Reply
#3

Use a variable, GetPlayerWeapon and SetPlayerArmedWeapon under OnPlayerUpdate.
Reply
#4

Quote:
Originally Posted by MP2
View Post
Use a variable, GetPlayerWeapon and SetPlayerArmedWeapon under OnPlayerUpdate.
But ehh... I got the little hunch now. But, how should it kind of look like, quickly? As i don't know how to set the weaponid either, as the weapon can be any.. And all.
Reply
#5

pawn Code:
new pWeapon[MAX_PLAYERS];

stock SetPlayerWeapon(playerid, weaponid, ammo)
{
    GivePlayerWeapon(playerid, weaponid, ammo);
    pWeapon[playerid] = weaponid;
    return 1;
}

public OnPlayerUpdate(playerid)
{
    if(GetPlayerWeapon(playerid) != pWeapon[playerid]) // If they changed weapon
    {
        SetPlayerArmedWeapon(playerid, pWeapon[playerid]); // Force their weapon back
    }
    return 1;
}
Do note though, if their ammo runs out it's going to call SetPlayerArmedWeapon constantly - a fix must be made for this.

To fix it, you would need to get the ammo using GetPlayerWeaponData, thus needing to get the slot for the weapon. If it's 0, don't force that weapon back.
Reply
#6

Uhh... This is what i keep getting:
pawn Code:
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\pawno\include\morphinc.inc(43) : warning 217: loose indentation
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\pawno\include\morphinc.inc(44) : warning 217: loose indentation
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(3028) : error 010: invalid function or declaration
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(3521) : error 004: function "SafeGivePlayerMoney" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(3550) : error 004: function "SafeGivePlayerMoney" is not implemented
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(3896) : error 004: function "SafeSetPlayerInterior" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(3939) : error 017: undefined symbol "GetVehicleName"
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(3939) : warning 202: number of arguments does not match definition
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(3955) : error 004: function "IsASalesVehicle" is not implemented
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(3959) : error 004: function "GetVehiclePrice" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(4054) : error 004: function "SafeSetPlayerPos" is not implemented
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(4059) : error 004: function "SafeSetPlayerPos" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(4064) : error 004: function "SafeSetPlayerPos" is not implemented
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(4069) : error 004: function "SafeSetPlayerPos" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(4074) : error 004: function "SafeSetPlayerPos" is not implemented
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(4884) : error 004: function "ABroadCast" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(4886) : error 004: function "ABroadCast" is not implemented
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(5686) : error 004: function "ClearChatbox" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(5704) : error 004: function "SendAdminMessage" is not implemented
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(5731) : error 004: function "SendAdminMessage" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(5753) : error 004: function "ClearChatbox" is not implemented
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(5761) : error 004: function "SendAdminMessage" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(5763) : error 004: function "SendAdminMessage" is not implemented
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(5913) : error 004: function "SendIRCMessage" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(5935) : error 004: function "SendIRCMessage" is not implemented
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(6252) : error 004: function "OOCOff" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(6266) : error 004: function "OOCOff" is not implemented
C:\Users\Da'
J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(6272) : error 004: function "SafeGivePlayerMoney" is not implemented
C:\Users\Da' J'\Desktop\GTA San Andreas modfiles\Raven's Roleplay 0.3d V4.2\gamemodes\larp.pwn(6288) : error 004: function "OOCOff" is not implemented

Compilation aborted.Pawn compiler 3.2.3664          Copyright © 1997-2006, ITB CompuPhase


26 Errors.
Btw, thanks for very quick answers. And what does that damn classic 26 errors mean! >.< It's always 26 errors.
Reply
#7

Another option is to disable the player slot by weapon id(give negative weapon ammo will disable your slot):

pawn Code:
new PlayerWeapons[MAX_PLAYERS][2][13];

TogglePlayerWeapons(playerid, bool:toggle, ...)
{
    new Args = numargs();

    if(!toggle)
    {
        for(new i = 0; i < 13; i++)
        {
            GetPlayerWeaponData(playerid, i, PlayerWeapons[playerid][0][i], PlayerWeapons[playerid][1][i]);
            for(new arg = 2; arg < Args; arg++)
            {
                if(PlayerWeapons[playerid][0][i] == getarg(arg))
                {
                    GivePlayerWeapon(playerid, PlayerWeapons[playerid][0][i], - (PlayerWeapons[playerid][1][i] * 2));
                    continue;
                }
            }
        }
    }
    else
    {
        ResetPlayerWeapons(playerid);
        for(new i = 0; i < 13; i++)
        {
            GetPlayerWeaponData(playerid, i, PlayerWeapons[playerid][0][i], PlayerWeapons[playerid][1][i]);
            for(new arg = 2; arg < Args; arg++)
            {
                if(PlayerWeapons[playerid][1][i] < 0 && PlayerWeapons[playerid][0][i] == getarg(arg))
                {
                    PlayerWeapons[playerid][1][i] -= (PlayerWeapons[playerid][1][i] * 2);
                }
            }            
            GivePlayerWeapon(playerid, PlayerWeapons[playerid][0][i], PlayerWeapons[playerid][1][i]);
        }
    }
    return 1;
}

GivePlayerWeaponEx(playerid, weaponid, ammo)
{
    GivePlayerWeapon(playerid, weaponid, ammo);
    PlayerWeapons[playerid][1][GetWeaponSlot(weaponid)] += ammo;
}

stock ResetPlayerWeaponsEx(playerid)
{
    ResetPlayerWeapons(playerid);
    for(new i = 0; i < 13; i++) PlayerWeapons[playerid][1][i] = 0;
}

stock GetWeaponSlot(weaponid)
{
    switch (weaponid)
    {
        case  0,      1: return  0; // Unarmed
        case  2  ..   9: return  1; // Melee
        case 22  ..  24: return  2; // Pistol
        case 25  ..  27: return  3; // Shotgun
        case 28, 29, 32: return  4; // SMG
        case 30,     31: return  5; // Machinegun
        case 33,     34: return  6; // Rifle
        case 35  ..  38: return  7; // Heavy
        case 16, 18, 39: return  8; // Projectile
        case 42,     43: return  9; // Special
        case 14        : return 10; // Gifts
        case 44  ..  46: return 11; // Special
        case 40        : return 12; // Detonator
    }
    return 0;
}
Remember to replace all GivePlayerWeapon for GivePlayerWeaponEx and all ResetPlayerWeapon for ResetPlayerWeaponEx.

pawn Code:
//Example

//Disable Deagle:
TogglePlayerWeapons(playerid, false, 24);
//Enable Deagle and disable MP5 and M4:
TogglePlayerWeapons(playerid, false, 29, 31);
TogglePlayerWeapons(playerid, true, 24);
Reply
#8

Quote:
Originally Posted by CyNiC
View Post
Another option is to disable the player slot by weapon id(give negative weapon ammo will disable your slot):

pawn Code:
TogglePlayerWeapons(playerid, bool:toggle, ...)
{
    new Args = numargs();

    if(!toggle)
    {
        for(new i = 0; i < 13; i++)
        {
            GetPlayerWeaponData(playerid, i, PlayerWeapons[playerid][0][i], PlayerWeapons[playerid][1][i]);
            for(new arg = 2; arg < Args; arg++)
            {
                if(PlayerWeapons[playerid][0][i] == getarg(arg))
                {
                    GivePlayerWeapon(playerid, PlayerWeapons[playerid][0][i], - (PlayerWeapons[playerid][1][i] * 2));
                    continue;
                }
            }
        }
    }
    else
    {
        ResetPlayerWeapons(playerid);
        for(new i = 0; i < 13; i++)
        {
            GetPlayerWeaponData(playerid, i, PlayerWeapons[playerid][0][i], PlayerWeapons[playerid][1][i]);
            for(new arg = 2; arg < Args; arg++)
            {
                if(PlayerWeapons[playerid][1][i] < 0 && PlayerWeapons[playerid][0][i] == getarg(arg))
                {
                    PlayerWeapons[playerid][1][i] -= (PlayerWeapons[playerid][1][i] * 2);
                }
            }            
            GivePlayerWeapon(playerid, PlayerWeapons[playerid][0][i], PlayerWeapons[playerid][1][i]);
        }
    }
    return 1;
}

GivePlayerWeaponEx(playerid, weaponid, ammo)
{
    GivePlayerWeapon(playerid, weaponid, ammo);
    PlayerWeapons[playerid][1][GetWeaponSlot(weaponid)] += ammo;
}

stock GetWeaponSlot(weaponid)
{
    switch (weaponid)
    {
        case  0,      1: return  0; // Unarmed
        case  2  ..   9: return  1; // Melee
        case 22  ..  24: return  2; // Pistol
        case 25  ..  27: return  3; // Shotgun
        case 28, 29, 32: return  4; // SMG
        case 30,     31: return  5; // Machinegun
        case 33,     34: return  6; // Rifle
        case 35  ..  38: return  7; // Heavy
        case 16, 18, 39: return  8; // Projectile
        case 42,     43: return  9; // Special
        case 14        : return 10; // Gifts
        case 44  ..  46: return 11; // Special
        case 40        : return 12; // Detonator
    }
    return 0;
}
Remember to replace all GivePlayerWeapon for GivePlayerWeaponEx.

pawn Code:
//Example

//Disable Deagle:
TogglePlayerWeapons(playerid, false, 24);
//Enable Deagle and disable MP5 and M4:
TogglePlayerWeapons(playerid, false, 29, 31);
TogglePlayerWeapons(playerid, true, 24);
I don't get it. Where i need to put this stack? O.o
Reply
#9

Anywhere outside callbacks (and after includes). Best place would be the bottom of your script.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)