Posts: 61
Threads: 9
Joined: Feb 2008
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
|
Posts: 6,609
Threads: 788
Joined: Dec 2006
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]
|
Posts: 61
Threads: 9
Joined: Feb 2008
no, he dont get the money and dont send the message
|
Posts: 353
Threads: 43
Joined: Sep 2006
No Jay.
Code: GivePlayerMoney(i,-100000);
is good. It also works good in my own gamemode!!!
|
Posts: 6,609
Threads: 788
Joined: Dec 2006
Well, whatever, But There are no problems with the code you posted Dimplex.
|
Posts: 3
Threads: 1
Joined: Apr 2008
04-23-2008, 01:50 AM
(This post was last modified: 04-23-2008, 01:57 AM by The_Zodiac)
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
|
Posts: 6,609
Threads: 788
Joined: Dec 2006
Well, whats the difference? except your version setting 200 indivdual timers for each player. You should check if the player is connected when looping.
|
Posts: 18
Threads: 6
Joined: Apr 2008
did you put
SetTimer("TaxUpdater", 180000, 1);
under OnGameModeInit??
|
Posts: 61
Threads: 9
Joined: Feb 2008
(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
|
Posts: 2,000
Threads: 124
Joined: Jan 2007
04-24-2008, 03:20 PM
(This post was last modified: 04-24-2008, 03:38 PM by Joeri)
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
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
|
|