new Float:RandomPickup[][3] = { // Positions for X, Y and Z } new cash; new bagholder;
new rand = random(sizeof(RandomPickup)); cash = CreatePickup(1550, 2, RandomPickup[rand][0], RandomPickup[rand][1], RandomPickup[rand][2], 0);
if(pickupid == cash) { new string[120], name[MAX_PLAYER_NAME]; GetPlayerName(playerid,name,sizeof(name)); GivePlayerMoney(playerid,10000); format(string, sizeof(string), "%s found the Money Bag!", name); TextDrawSetString(notification, string); SetTimer("CloseTextdraw_notification", 2*1000, false); bagholder = GetPlayerID(name); SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.1, -0.2, 0, 0, 90, 0.5, 0.8, 0.8, 0.8); DestroyPickup(cash); } return 1;
stock GetPlayerID(const Name[]) { for(new i; i<MAX_PLAYERS; i++) { if(IsPlayerConnected(i)) { new pName[MAX_PLAYER_NAME]; GetPlayerName(i, pName, sizeof(pName)); if(strcmp(Name, pName, true)==0) { return i; } } } return -1; }
if(playerid == bagholder) { DestroyPickup(cash); new Float:X, Float:Y, Float:Z; GetPlayerPos(playerid, X, Y, Z); cash = CreatePickup(1550, 2, X, Y, Z, 0); RemovePlayerAttachedObject(playerid, 1); SendClientMessage(playerid, LIGHTGREEN, "You lost the {FF0000}Money Bag!"); }
if(pickupid == cash)
{
new string[120], name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
GivePlayerMoney(playerid,10000);
format(string, sizeof(string), "%s found the Money Bag!", name);
TextDrawSetString(notification, string);
SetTimer("CloseTextdraw_notification", 2*1000, false);
bagholder = playerid;
SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.1, -0.2, 0, 0, 90, 0.5, 0.8, 0.8, 0.8);
DestroyPickup(cash);
}
return 1;
Why can't you just use playerid in OnPlayerPickupPickup?
And just a tip, the money bag will be displaced on some skins because some skins are different than others. |
if(playerid == bagholder) { new Float:X, Float:Y, Float:Z; GetPlayerPos(playerid, X, Y, Z); cash = CreatePickup(1550, 2, X, Y, Z, 0); RemovePlayerAttachedObject(playerid, 1); SendClientMessage(playerid, LIGHTGREEN, "You lost the {FF0000}Money Bag!"); bagholder = -1; }