SA-MP Forums Archive
[solved]Whats wrong with this code? - 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: [solved]Whats wrong with this code? (/showthread.php?tid=135742)



[solved]Whats wrong with this code? - ruckfules99 - 21.03.2010

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);



Re: Whats wrong with this code? - Fabio11 - 21.03.2010

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;
}



Re: Whats wrong with this code? - ruckfules99 - 21.03.2010

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


Re: Whats wrong with this code? - MadeMan - 21.03.2010

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.


Re: Whats wrong with this code? - ruckfules99 - 21.03.2010

Thank you! it fixed it.