[BEP]AcerPilot
Unregistered
04.07.2011, 12:39
(
Последний раз редактировалось [BEP]AcerPilot; 04.07.2011 в 13:17.
Причина: Confirmed weapon values mixing
)
I noticed a few days ago that the function "GivePlayerWeapon" is bugged. Not the whole function, but it's last parameter, "ammo". I have this code in my script:
pawn Код:
GivePlayerWeapon(playerid, 32, 20);
It would give me a Tec9 with 20 bullets, but instead of 20 it gives me 520 bullets (420-100)! I think it's value is mixing with other weapons value, because when I bought the Tec9 on ammunation (I have weapon buy system), I was holding an Desert Eagle with 500 bullets (I wanted to be 500, not bug).
When I have no weapon it gives me the 20 bullets, withouth the additional 500.
I hope this can be fixed as soon as possible, because for a RP servers it's very bad having more bullets than you deserve to, as you only paid for 20 bullets.
Posts: 1,363
Threads: 14
Joined: Apr 2009
Reputation:
0
I don't think i understand your problem fully, it sounds like you're saying you get 500 extra ammo when you have a deagle with 500 ammo.
If you have an smg with 500 bullets and buy a tec 9 with 20 then yes you'll get 520 ammo for the tec 9, there are simple work arounds for this and is a GTA SA thing
Posts: 1,496
Threads: 78
Joined: Jun 2008
Reputation:
0
05.07.2011, 05:05
(
Последний раз редактировалось leong124; 05.07.2011 в 05:47.
)
If you have a weapon in that slot already, you ammo will be added.
For example if you have an MP5 with 500 ammo, and you give the player a UZI with 500 ammo,
he will have a UZI of 1000 ammo.
The solution is to store their current weapons, reset their weapons, and give them back with the new ammo.
So to conclude, this is not a bug.
Posts: 14
Threads: 0
Joined: Aug 2010
Reputation:
0
OR you can play as the ammo were compatible for the other weapon
[BEP]AcerPilot
Unregistered
Hum.. Ok, thanks.
@Leong: how would I do what you recommended? Because if I do GivePlayerWeapon the ammo wouldn't be added again?
Posts: 1,496
Threads: 78
Joined: Jun 2008
Reputation:
0
Firstly use GetPlayerWeaponData to get all the weapons of a player.
Then You can use ResetPlayerWeapons to clear his weapons.
After that you give them back all the weapons they have, except the weapon you wanted to give them.
Finally you can give the weapon you want to give to him.
[BEP]AcerPilot
Unregistered
Thanks for your answer Leong. I did what you recommended but didn't work. Take a look at my code:
pawn Код:
stock GivePlayerWeaponEx(playerid, gun, ammo)
{
new weapons[13], ammovar[13];
for(new i = 0; i < 13; i++)
{
GetPlayerWeaponData(playerid, i, weapons[i], ammovar[i]);
}
ResetPlayerWeapons(playerid);
for(new i = 0; i < 13; i++)
{
GivePlayerWeapon(playerid, weapons[i], ammovar[i]);
}
GivePlayerWeapon(playerid, gun, ammo);
}
OBS for admins: I think this topic should be renamed to "How to fix GivePlayerWeapon bug" and should be moved to "Scripting Discussion".
Posts: 1,046
Threads: 29
Joined: Mar 2010
That could help you:
pawn Код:
#define INVALID_WEAPON_SLOT_ID -1
stock SetPlayerWeapon(playerid, weapon, ammo)
{
new tweapon[13], tammo[13];
for(new i = 0; i < 13; i++) if(GetWeaponSlot(weapon) != i) GetPlayerWeaponData(playerid, i, tweapon[i], tammo[i]);
tweapon[GetWeaponSlot(weapon)] = weapon;
tammo[GetWeaponSlot(weapon)] = ammo;
ResetPlayerWeapons(playerid);
for(new i = 0; i < 13; i++) GivePlayerWeapon(playerid, tweapon[i], tammo[i]);
SetPlayerArmedWeapon(playerid, weapon);
}
stock GetWeaponSlot(weaponid)
{
new slot;
switch(weaponid)
{
case 0,1: slot = 0;
case 2..9: slot = 1;
case 22..24: slot = 2;
case 25..27: slot = 3;
case 28,29,32: slot = 4;
case 30,31: slot = 5;
case 33,34: slot = 6;
case 35..38: slot = 7;
case 16..18,39: slot = 8;
case 41..43: slot = 9;
case 10..15: slot = 10;
case 44..46: slot = 11;
case 40: slot = 12;
default: slot = INVALID_WEAPON_SLOT_ID;
}
return slot;
}
Usage:
pawn Код:
SetPlayerWeapon(playerid, weapon, ammo);
Example:
pawn Код:
SetPlayerWeapon(playerid, 32, 20);
This stock will just set the players weapon ID and ammo instead of increasing the ammo.
[BEP]AcerPilot
Unregistered
07.07.2011, 10:59
(
Последний раз редактировалось [BEP]AcerPilot; 07.07.2011 в 15:34.
)
OK, thanks guys. I'll test the codes.
#EDIT: Worked. Thanks for all that answered in here. Admins can lock this topic if they want to.
#EDIT2: I just noticed when I put GivePlayerWeaponEx in the stock that logs in the player when he types /login, the server stop working. All commands are 'Server: Unknown Command' and all the functions that should be executed after GivePlayerWeaponEx aren't executed. I think it's because it's the first time he will receive the weapons. Suggestions?