SA-MP Forums Archive
get player weapon data / pickup command - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: get player weapon data / pickup command (/showthread.php?tid=583180)



get player weapon data / pickup command - thaKing - 26.07.2015

So, I tried to make that player can't pickup weapon if he already has that type of weapon.

Код:
if (GetPlayerWeaponData(playerid, GetWeaponSlot(gid), PlayerData[playerid][pWeapon], PlayerData[playerid][pAmmo]))
			return SendErrorMessage(playerid, "Atvainojiet, Jums jau ir љī tipa ierocis!");
Translate: Sorry, you already have this type of weapon!

Well, I think the problem is that it isn't checking player weapons, but I'm not sure. The code compliers without any errors, but it isn't working in game.


Re: get player weapon data / pickup command - youssefehab500 - 26.07.2015

Can you show us the full code? The full pickup check.


Re: get player weapon data / pickup command - thaKing - 26.07.2015

Here the cmd and some functions for it.
Код:
CMD:pickupgun(playerid, params[])
{
	if(IsPlayerNearDroppedWeapon(playerid))
	{
	    new gid = GetNearestWeaponID(playerid);

	    if(gid == 999)
			return SendErrorMessage(playerid, "Ierocis ir iegūts ar papildprogrammu palīdzību! (līdzu, ziņojiet administrācijai)");
			
		new slot = GetWeaponSlot(gid);
			
		if (GetPlayerWeaponData(playerid, slot, PlayerData[playerid][pWeapon], PlayerData[playerid][pAmmo]))
			return SendErrorMessage(playerid, "Atvainojiet, Jums jau ir šī tipa ierocis!");
			
		if(GetPlayerWeapon(playerid) != 0)
			return SendErrorMessage(playerid, "Lai paceltu jaunu ieroci, nolieciet pašreizējo.");

		PickupDroppedWeapon(playerid, gid);

		SendServerMessage(playerid, "Jūs pacēlāt %s ar %i lodēm.", GetWeaponNameEx(gid), GetPlayerAmmo(gid));
		SendNearbyMessage(playerid, 10.0, COLOR_PURPLE, "** %s tikko pacēla uz zemes esošo %s.", GetPlayerNameEx(playerid), GetWeaponNameEx(GetPlayerWeapon(playerid)));
	} else {
		SendErrorMessage(playerid, "Jūs neatrodaties uz zemes nomesta ieroča tuvumā!");
	}
	return 1;
}
Код:
GetWeaponSlot(weaponid)
{
    switch (weaponid)
    {
        case 1: return 0;
        case 2..9: return 1;
        case 22..24: return 2;
        case 25..27: return 3;
        case 28, 29, 32: return 4;
        case 30, 31: return 5;
        case 33, 34: return 6;
        case 35..38: return 7;
        case 16..18, 39: return 8;
        case 41..43: return 9;
        case 10..15: return 10;
        case 44..46: return 11;
        case 40: return 12;
    }
    return 999;
}
Код:
GetNearestWeaponID(playerid)
{
	for (new i; i < MAX_DROPPED_WEAPONS; i ++)
	{
	    if (IsPlayerInRangeOfPoint(playerid, 2.0, WeaponData[i][wX], WeaponData[i][wY], WeaponData[i][wZ]))
	    {
	        return i;
	    }
	}
	return 999;
}