04.06.2015, 15:37
(
Последний раз редактировалось CoaPsyFactor; 04.06.2015 в 15:50.
Причина: misspelled title
)
Hello,
In this thread I'll explain to you step by step how to create simple Anti No-reload functionality.
First, You'll need latest (0.3z) version of SA:MP as we are going to use callback "OnPlayerWeaponShot", second you'll need to implement your own "GetPlayerSkill" function.
So let's start, firstly we'll define how many round per minute can any weapon fire on each player skill level. For this we'll use information from THIS source.
*Almost each weapon have 3 different RPM's, RPM depends on player shooting skill for that weapon.
After we gather all required informations we will create an array containing each RPM for each weapon, It will look something like this.
So, now when we have RPM informations for each weapon we need to define some more arrays and public functions.
Functions:
Array:
Okay, now we are ready to implement our functionality.
I hope you understood tutorial, if you have any question or if you find any bug please notify me. Feel free to ask anything
Cheers...
In this thread I'll explain to you step by step how to create simple Anti No-reload functionality.
First, You'll need latest (0.3z) version of SA:MP as we are going to use callback "OnPlayerWeaponShot", second you'll need to implement your own "GetPlayerSkill" function.
So let's start, firstly we'll define how many round per minute can any weapon fire on each player skill level. For this we'll use information from THIS source.
*Almost each weapon have 3 different RPM's, RPM depends on player shooting skill for that weapon.
After we gather all required informations we will create an array containing each RPM for each weapon, It will look something like this.
pawn Код:
enum _weapon_info {
clipSize,
rpm[3]
}
new wInfos[47][_weapon_info] = {
{0, {0,0,0}},//none weapon
...// list of weapons
{7, {65, 75, 85}},//desert eagle
...// rest of list
}
Functions:
pawn Код:
forward GetPlayerWeaponSkill(playerid, weaponid); // will return integer which presents player skill for certain weapon
forward ClearLastShot(playerid); // will clear number of shots
pawn Код:
enum _player_shot_infos {
weaponId,
shotCount,
timer
};
new pLastShot[MAX_PLAYERS][_player_shot_infos]
pawn Код:
public GetPlayerSkillLevel(playerid, weaponid)
{
return 400;
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
new rpm, time, skilLLevel = GetPlayerSkillLevel(playerid, weaponid)// get player skill level;
if (pLastShot[playerid][lWeaponId] != weaponid) {// check is current weapon same as on previous shot
if (pLastShot[playerid][timer]) {// check is timer active
KillTimer(pLastShot[playerid][timer]);//if so, deactivate timer
}
pLastShot[playerid][lWeaponId] = weaponid; // set weapon to current one
pLastShot[playerid][lCount] = 0; // reset shot counter
if (skilLLevel < 300) { // check for skill level and set required array offset
rpm_offset = 0;
} else if (skilLLevel < 600) {
rpm_offset = 1;
} else if (skilLLevel < 900) {
rpm_offset = 2;
}
// calculate time required to reset shot counter
// as we have RPM (Round per minute) we'll need to convert that to RPS (round per second)
// and then multiply it with weapon's clip size
// that's how we'll get time required to shot out all bullets from one clip
time = floatround((wInfo[weaponid][rpm][rpm_offset] / 60)) * wInfo[weaponid][clipSize];
// now we start timer with calculated time multiplied with 1000 to convert it to milliseconds
pLastShot[playerid][timer] = SetTimerEx("ClearLastShot", time * 1000, false, "d", playerid);
} else {// in case that shot came from same weapon as last one
pLastShot[playerid][shotCount]++;// add +1 bullet to counter
}
if (pLastShot[playerid][shotCount] > wInfo[weaponid][clipSize]) {// check is player shooting more than weapon can hold
return 0;// if yes, return 0 to prevent bullet from causing damage
}
return 1;//in case that all is okay, bullet should cause damage
}
public ClearLastShot(playerid)
{
pLastShot[playerid][shotCount] = 0; // reset counter to 0
}
Cheers...