Fix for auto reload when switching weapons?
#1

Is there any fix for that auto reload of weapon when player switch his weapon and the weapon is auto reloaded.

I want to make reloading mandatory.
Reply
#2

Lol no one can even make this
Reply
#3

Quote:
Originally Posted by Gangster-rocks
Посмотреть сообщение
Lol no one can even make this
Unless someone actually does something, it is thought as impossible.
Reply
#4

When I think about it, I can't see any ways in which it would be possible. Seeing as when you use SetPlayerAmmo, it will always go to the max ammo if it's above it. Example, setting ammo to 100 for a gun such as M4 would still have 50 or 60 (Whatever the max ammo per clip is) ammo left in it, unless you get the gun to reload to max ammo once it reaches 0, which would be really inconvenient to have in your script.
Reply
#5

Alright, got a fix for it, may not be very well, but it fixes my problem.
I have tested it for one weapon/slot only for now, but I am sure it will work for every weapon.


What I did was store ammo in a variable.

pawn Код:
new ammo=330;
Instead of giving player ammo, which I want, I gave him ammo, max clip can hold like
pawn Код:
GivePlayerWeapon(playerid,WEAPON_AK47,30);
And when he want to reload, he would have to press a key, probably KEY_YES, then I calculated the ammo he needed to refill his clip and subtracted that ammo from the variable.

pawn Код:
ApplyAnimation(playerid,"RIFLE","RIFLE_load",2,0,1,1,0,1000,1);
    new rem = GetPlayerAmmo(playerid);
    GivePlayerWeapon(playerid,WEAPON_AK47,-rem);
    GivePlayerWeapon(playerid,WEAPON_AK47,30);
    ammo-=30-rem;
Full code with which it was tested (for one weapon only) is
pawn Код:
#include <a_samp>
#include <ZCMD>
#include <sscanf2>

new ammo=330;

public OnGameModeInit()
{
    AddPlayerClass(0,0,0,0,0,0,0,0,0,0,0);
}

public OnPlayerSpawn(playerid)
{
    GivePlayerWeapon(playerid,WEAPON_AK47,30);
    ammo-=30;
    return 1;
}

CMD:r(playerid,params[])
{
    #pragma unused params
    ApplyAnimation(playerid,"RIFLE","RIFLE_load",2,0,1,1,0,1000,1);
    new rem = GetPlayerAmmo(playerid);
    GivePlayerWeapon(playerid,WEAPON_AK47,-rem);
    GivePlayerWeapon(playerid,WEAPON_AK47,30);
    ammo-=30-rem;
    new msg[20];
    format(msg,20,"New Ammo : %d",ammo);
    SendClientMessage(playerid,-1,msg);
    return 1;
}
More things we may add are
  1. Checking if Player is crouching/standing
  2. Geeting Player Armed Weapon
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)