[solved]Whats wrong with this code?
#1

In my script, i tried to add it so that if you have more then 1.5m It starts dropping your money by 10k each time. Along with a message saying " SERVER: You are carrying to much money! You have dropped 10k, Please deposit your money"

But the problem I'm having is, it keeps dropping money even after it's below 1.5M.


If you guys have a better code, I'd appreciate it.

Код:
forward CheckCash();
public CheckCash()
{
	for(new i=0; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i) && GetPlayerMoney(i) >= 1000000)
	{
		if(!Set[i])
		{
			Set[i] = true;
			Timer[i] = SetTimerEx("GetCash", 10000, 1, "d", i);
		}
	}
	return 1;
}

forward GetCash(playerid);
public GetCash(playerid)
{
	if(!GetPlayerMoney(playerid)) // if moneys == 0, timer stop
	{
		KillTimer(Timer[playerid]);
		Timer[playerid] = 0;
		Set[playerid] = false;
		return 1;
	}
	//if(GetPlayerMoney(playerid) > 1500000) Set[playerid] = false;
		if(!IsPlayerInAnyVehicle(playerid)) {
		GivePlayerMoney(playerid, -10000);
		SendClientMessage(playerid, 0xFFFF00AA, "SERVER: You are carrying to much money! You have dropped 10k, Please deposit your money");
	}
	return 1;
}
Timer

Код:
SetTimer("CheckCash", 10000, true);
Reply
#2

Try this

pawn Код:
forward CheckCash();
public CheckCash()
{
    for(new i=0; i < GetMaxPlayers(); i++)
    {
        if(IsPlayerConnected(i) && GetPlayerMoney(i) >= 1000000)
        {
            if(!Set[i])
            {
                Set[i] = true;
                Timer[i] = SetTimerEx("GetCash", 10000, 1, "d", i);
            }
        }
    } return 1;
}

forward GetCash(playerid);
public GetCash(playerid)
{
    if(!GetPlayerMoney(playerid)) // if moneys == 0, timer stop
    {
        KillTimer(Timer[playerid]);
        Timer[playerid] = 0;
        Set[playerid] = false;
        return 1;
    }
    //if(GetPlayerMoney(playerid) > 1500000) Set[playerid] = false;
        if(!IsPlayerInAnyVehicle(playerid)) {
        GivePlayerMoney(playerid, -10000);
        SendClientMessage(playerid, 0xFFFF00AA, "SERVER: You are carrying to much money! You have dropped 10k, Please deposit your money");
    }
    return 1;
}
Reply
#3

Still the samething....


once it starts dropping cash, it won't stop.



Like, say i spawn with 100k, It won't drop cash, but then when i go over the limit, it starts to drop but doesnt stop dropping after it goes below the limit
Reply
#4

You can use only 1 timer

pawn Код:
forward CheckCash();
public CheckCash()
{
    for(new i=0; i < GetMaxPlayers(); i++) if(IsPlayerConnected(i))
    {
        if(GetPlayerMoney(i) > 1500000)
        {
            if(!IsPlayerInAnyVehicle(i))
            {
                GivePlayerMoney(i, -10000);
                SendClientMessage(i, 0xFFFF00AA, "SERVER: You are carrying to much money! You have dropped 10k, Please deposit your money");
            }
        }
    }
}
Also, you had 1000000 instead of 1500000 before.
Reply
#5

Thank you! it fixed it.


Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)