Problem with giveplayerMoney to right person
#1

Hi


I having some problem with my robbery system...

I don't have the code now as I'm not on my computer but I can explain:

A player enters a checkpoint then it will give him 3 stars on wanted level, then the timer starts for 9 secounds it gives the player the money who robbed and a message that says: You sucsess fully robbed The 4 Dragons casino...

But the wrong player gets the money not he who robbed..

Edit: If you need some code I'll try to fix it.
Reply
#2

pawn Код:
//When player robs
SetTimerEx("Robbery", 9000, false, "id", playeridwhorobbed, amountofmoneystolen);

forward Robbery(playerid, money);
public Robbery(playerid, money)
{
    GivePlayerMoney(playerid, money);
    return 1;
}
NOTE: These are just examples, you have to replace things like 'playeridwhorobbed' and 'amountofmoneystolen' with the appropriate values.
Reply
#3

Thanks alot! I will try with SetTimerEx instead.. Anyway it's almost the same.
Reply
#4

pawn Код:
new Robber[MAX_PLAYERS];
forward Robplace(playerid);
// under the https://sampwiki.blast.hk/wiki/OnPlayerEnterCheckpoint
//for tips ^^
SetTimerEx("RobPlace", 9000, false, "i", playerid);

public RobPlace(playerid)
{
  SetPlayerWantedLevel(playerid, 3);
  Robber[playerid] = 1;
  for(new i=0; i<MAX_PLAYERS; i++)
  {
    new robcash = GetPlayerMoney(i)/i; // < untested never did it like this b4 but it is suppose to work......
    GivePlayerMoney(playerid, 10000000/robcash);
  }
  new robstring[256];
  new name[MAX_PLAYER_NAME];
  GetPlayerName(playerid, name, sizeof(name));
  format(robstring, sizeof(robstring), "%s Is Robbed the bank", name);
  SendClientMessageToAll(-1, robstring);
  return 1;
}
;

Hope this help you in some way
Reply
#5

I'm not sure about this part:
pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
  {
    new robcash = GetPlayerMoney(i)/i; // < untested never did it like this b4 but it is suppose to work......
    GivePlayerMoney(playerid, 10000000/robcash);
  }
Firstly if the player was ID 0 and they had more than 10 million in cash, not to mention, why are you getting the money from other players anyway? :S
You started a loop, so that if there is like 10 people connected, it is going to give a certain amount to the player from each players 10 times. So they may end up getting 100 million. I would recommend testing a code if you don't understand it, and if you're certain it works, then you can feel confident that it works. Other than that tiny flaw, good effort.
Reply
#6

let me explain it gets every player money.... then it divides it by each player after that i just put a random rob amount 10m to be divided by equation robcash.... understood?

10m divided by what was divided earlier i dont think they would get alot
Reply
#7

pawn Код:
new count = 0; //Amount of players online
new robamount;

for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i)) //Foreach is a better option
    {
        count++;
        robamount += ((GetPlayerMoney(i)) / count);
    }
}
GivePlayerMoney(playerid, robamount);
It's hard to explain how loops work in my point of view :P
So read this: https://sampwiki.blast.hk/wiki/Loops

Just remember, I'm not trying to have a go at you here because you got something wrong, I just want to explain it further, so the OP doesn't have to post about two problems in one thread, or make a new one out of it.
Reply
#8

Oh i know your problem pretty well, am so sure that you've SetTimer and not SetTimerEx.
Your timer is set something like this
pawn Код:
SetTimer("Robbed",9000,0);
And then you used
pawn Код:
forward Robbed(playerid);
public Robbed(playerid)
{
GivePlayerMoney(playerid,5000);
//bla bla
}
Well that ofc won't work, it will give the money ect to ID 0, now try to replace that timer with this one
pawn Код:
SetTimerEx("Robbed",9000,0,"i",playerid);
Reply
#9

well the timer would of gone under onplayerentercheckpoint so when that player enters the checkpoint the timer starts ... for that playerid then triggering the function if not

//if u dont understand read the earlier post............
pawn Код:
//under checkpoint function
  Robber[playerid] = 1;

public RobPlace(playerid)
{
 if(Robber[playerid] == 1)
 {
  SetPlayerWantedLevel(playerid, 3);
  for(new i=0; i<MAX_PLAYERS; i++)
  {
    new robcash = GetPlayerMoney(i)/i; // < untested never did it like this b4 but it is suppose to work......
    GivePlayerMoney(playerid, 10000000/robcash);
  }
  new robstring[256];
  new name[MAX_PLAYER_NAME];
  GetPlayerName(playerid, name, sizeof(name));
  format(robstring, sizeof(robstring), "%s Is Robbed the bank", name);
  SendClientMessageToAll(-1, robstring);
 }
 return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)