Hello There, Guest! Login or Register


Public function, taxupdater
#1
Hey all,

I need some help whit a public function i made.
This is the idea, If you have over the 3mil, you pay every 2 min 100000.
Now i made this:
Code:
forward TaxUpdater();
The public function:
Code:
public TaxUpdater()
{
     for(new i=0; i<MAX_PLAYERS; i++)
         {
        if(GetPlayerMoney(i) > 3000000)
                    {
             GivePlayerMoney(i,-100000);
             SendClientMessage(i, COLOR_GREEN,"You payed 100000 tax.");
             }
         }
}
and a timer:
Code:
    SetTimer("TaxUpdater", 180000, 1);
But if i have more than 3 mil, he dont get 100000 of my money.
How i must fix this?

Grtz Dimplex
Reply
#2
I can't see the problem to be honest, is the message appearing saying that the player has payed the tax?

also:

GivePlayerMoney(i,-100000);

Should be:

GivePlayerMoney(i,0-100000);

[me=Jay]sucks @ maths[/me]
Reply
#3
no, he dont get the money and dont send the message 8)7
Reply
#4
No Jay.

Code:
GivePlayerMoney(i,-100000);
is good. It also works good in my own gamemode!!!
Reply
#5
Well, whatever, But There are no problems with the code you posted Dimplex.
Reply
#6
Dimplex you could try:


Code:
forward TaxUpdater();
and
public TaxUpdater()
change it for:
Code:
forward TaxUpdater(playerid);
and
public TaxUpdater(playerid)

And
change your settimer ex for:
Code:
for(new i=0;i<MAX_PLAYERS;i++){SetTimerEx("TaxUpdater", 180000, 1,"i",i);}

Code:
public TaxUpdater()
{
    
        if(GetPlayerMoney(i) > 3000000)
                    {
             GivePlayerMoney(i,-100000);
             SendClientMessage(i, COLOR_GREEN,"You payed 100000 tax.");
             }
         
}


It's the same result...anyway i'd try it.


Posting your full code in pastebin should be useful too


Zodiac
Reply
#7
Well, whats the difference? except your version setting 200 indivdual timers for each player. You should check if the player is connected when looping.
Reply
#8
did you put


SetTimer("TaxUpdater", 180000, 1);

under OnGameModeInit??
Reply
#9
(04-24-2008, 11:03 AM)Smoke link Wrote: did you put


SetTimer("TaxUpdater", 180000, 1);

under OnGameModeInit??
Yes i did,
Now i changed it whit the help of zodiac.
Now it is this:
Code:
public TaxUpdater(playerid)
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
    SetTimerEx("TaxUpdater", 180000, 1,"i",i);
        }
        if(GetPlayerMoney(i) > 3000000)
                    {
             GivePlayerMoney(i,-100000);
             SendClientMessage(i, COLOR_GREEN,"You payed 100000 tax.");
             }

}
And i disabeled the old timer.
But now he gives this errors,
Code:
D:\Scripting\GTA SA Samp\gamemodes\SecondLife.pwn(450) : error 017: undefined symbol "i"
D:\Scripting\GTA SA Samp\gamemodes\SecondLife.pwn(452) : error 017: undefined symbol "i"
D:\Scripting\GTA SA Samp\gamemodes\SecondLife.pwn(453) : error 017: undefined symbol "i"
Pawn compiler 3.2.3664              Copyright (c) 1997-2006, ITB CompuPhase


3 Errors.
What must supose to do?
Grtz and thnx,
Dimplex
Reply
#10
Code:
[quote='The_Zodiac link' pid='7834' dateline='1208911845']
change it for:
[code]forward TaxUpdater(playerid);
and
public TaxUpdater(playerid)
[/code][/quote]
There is no need to declare a function with the parameters included.

First, indent you code corectly D:
Code:
public TaxUpdater(playerid)
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
    SetTimerEx("TaxUpdater", 180000, 1,"i",i);
// u closed the for() loop where u defined 'i' !!!     }
    
        if(GetPlayerMoney(i) > 3000000)
        {
            GivePlayerMoney(i,-100000);
            SendClientMessage(i, COLOR_GREEN,"You payed 100000 tax.");
        }
}

}

But, that code will cause a huge CPU load :o

This is better:

Code:
top:

forward TaxUpdater();

Ongameinit:

SetTimerEx("TaxUpdater", 180000, 1,"i",i);

function:

public TaxUpdater(playerid)
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerConnected(i) == 1)
            {
        if(GetPlayerMoney(i) > 3000000)
                {
        GivePlayerMoney(i,-100000);
        SendClientMessage(i, COLOR_GREEN,"You payed 100000 tax.");
        }
           }
    }
}

just a tip: you can check if a timer is running by simple adding a 'debug message', just a simple SendClientMessageToAll(white, "Time activated"); to the function it should trigger.


-oost 8)
Reply