SA-MP Forums Archive
Money bag problem. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Money bag problem. (/showthread.php?tid=235151)



Money bag problem. - bhaveshnande - 05.03.2011

I am creating a money bag system where when the server starts, money bag (pickup) is created at a random position.
When someone picks up the pickup the money bag gets attached to his body and when other player shoots him he looses the money bag and at the place where he dies a new pickup is created again with the same modelid.

But the problem is this script worked well for the first time but at the second time it all messed up. Whenever the player is killed it says 'You lost the Money Bag' and creates a new pickup at his death place even if he didn't picked up the pickup earlier.

Here is my code :

Outside
Код:
new Float:RandomPickup[][3] =
{
      // Positions for X, Y and Z
}
new cash;
new bagholder;
In OnGameModeInit
Код:
new rand = random(sizeof(RandomPickup));
cash = CreatePickup(1550, 2, RandomPickup[rand][0], RandomPickup[rand][1], RandomPickup[rand][2], 0);
OnPlayerPickUpPickup(playerid, pickupid)
Код:
 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;
Outside
Код:
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;
}
OnPlayerDeath
Код:
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!");
	}
Where am I wrong?
Sometimes it even creates the pickup at the place of killerid instead of the player who got killed.


Re: Money bag problem. - Th3Angel - 05.03.2011

Why can't you just use playerid in OnPlayerPickupPickup?
pawn Код:
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;
And just a tip, the money bag will be displaced on some skins because some skins are different than others.


Re: Money bag problem. - bhaveshnande - 05.03.2011

Quote:
Originally Posted by Th3Angel
Посмотреть сообщение
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.
Oh didn't thought of it!

Well even now if I die, a new pickup is created at my death place but I am still a bagholder
( means my playerid is still == bagholder ) and after I die again a new pickup is created at that place. How can I not be bagholder?

Also after restarting the server my playerid is always == bagholder. And if I die without picking up that pickup it does all the things stated in OnPlayerPickupPickup


Re: Money bag problem. - bhaveshnande - 07.03.2011

*bump* Any help please?


Re: Money bag problem. - Loppa - 07.03.2011

OnPlayerDeath
Код:
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;
	}



Re: Money bag problem. - bhaveshnande - 07.03.2011

Oh thank you Loppa, changing the bagholder value to -1 did it all right