Job Payment... -
SiJ - 13.07.2009
EDIT: SKIP TO THE LAST POST
Hey,
I had to close my server because of this BUG

Here's the code:
pawn Код:
new Calling[MAX_PLAYERS];
new pCall[MAX_PLAYERS] = 255;
#define Call_Cost 50
forward CallCost(playerid);
public CallCost(playerid)
{
new money = GetPlayerMoney(playerid);
if(pCall[playerid]==255)
{
KillTimer(Calling[playerid]); // In case timer wouldn't stop ^^
}
else if(money < Call_Cost)
{
pCall[playerid] = 255;
PhoneMsg(playerid,"Phone Operator: You don't have enough money to pay for this call!");
ErrorMsg(playerid,"Hangup!");
}
else
{
new str[256];
GivePlayerMoney(playerid,-Call_Cost);
format(str,sizeof(str),"Call Cost:~r~ %i $",Call_Cost);
GameTextForPlayer(playerid,str,3000,4);
}
}
public OnPlayerConnect(playerid)
{
pCall[playerid] = 255;
}
public OnPlayerDisconnect(playerid)
{
KillTimer(Calling[playerid]);
}
dcmd_call(playerid, params[])
{
new number;
if (sscanf(params, "d", number))
{
UsageMsg(playerid, "USAGE: /call <Phone #>");
HintMsg(playerid,"Available phone numbers: 112 (Emergency) 555 (Taxi)");
}
else if(number == 555)
{
new money = GetPlayerMoney(playerid);
if(money < Call_Cost)
{
pCall[playerid] = 255;
PhoneMsg(playerid,"Phone Operator: You don't have enough money to call!");
}
else if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
new str[256];
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USECELLPHONE);
format(str,sizeof(str),"Call Cost: ~r~%i$/min",Call_Cost);
GameTextForPlayer(playerid,str,4000,4);
GivePlayerMoney(playerid,-Call_Cost);
//[SKIP] code that checks if there any taxi drivers... It works fine
pCall[playerid] = 555;
SystemMsg(playerid,"San Fierro Taxi Company");
PhoneMsg(playerid,"Dispatch: Hello, please tell location to call taxi to.");
Calling[playerid] = SetTimerEx("CallCost",60000,1,"d",playerid);
}
else if(IsPlayerInAnyVehicle(playerid)) ErrorMsg (playerid,"You cannot speak in a vehicle..");
else ErrorMsg(playerid,"You can't call at the moment..");
}
return 1;
}
public OnPlayerText(playerid, text[])
{
if(pCall[playerid]==555)
{
new name[24];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(gTeam[i] == TEAM_TAXI)
{
//[SKIP] This works fine
}
}
pCall[playerid]=255;
return 0;
}
}
if(strcmp(cmdtext,"/h",true)==0 || strcmp(cmdtext,"/hangup",true)==0)
{
if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_USECELLPHONE)
{
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_STOPUSECELLPHONE);
pCall[playerid] = 255;
SystemMsg(playerid,"You hang up..");
KillTimer(Calling[playerid]);
}
else
{
ClearAnimations(playerid);
}
return 1;
}
Here's what happens:
When I connect sometimes it starts showing me GameText "Call Costs:....." and it starts taking from me money every minute (it seems SOMEHOW timer CallCost starts automatically?) but I haven't typed /call or anything like that.....
That's all the code which could cause this problem.. but what's wrong with the code?
P.S.
I changed
new Calling; (timer id) to
new Calling[MAX_PLAYERS];
(I thought it could help, but NO it didn't)
So please help me somebody.. Thanks..
Re: Why this happens? What's wrong? Calling - Price per minute bug.... -
dice7 - 13.07.2009
https://sampwiki.blast.hk/wiki/SetTimerEx
SetTimerEx(funcname[], interval, repeating, const format[], {Float,_}:...)
function name = CallCost
interval in miliseconds = 60000
repeating = true/1 //your problem
type of variable to pass = %d
variable = playerid
Re: Why this happens? What's wrong? Calling - Price per minute bug.... -
SiJ - 13.07.2009
Quote:
Originally Posted by dice7
https://sampwiki.blast.hk/wiki/SetTimerEx
SetTimerEx(funcname[], interval, repeating, const format[], {Float,_}:...)
function name = CallCost
interval in miliseconds = 60000
repeating = true/1 //your problem
type of variable to pass = %d
variable = playerid
|
It has to be repeating, so if player talks more than 1 minute, it would take more money from him..
That's why I have so many KillTimer functions..
Re: Why this happens? What's wrong? Calling - Price per minute bug.... -
dice7 - 13.07.2009
No. The problem is this:
SetTimerEx("CallCost",60000,
1,"d",playerid);
It should be 0. One or true means that the timer will constantly be repeating and 0 or false means that it will execute only once
Re: Why this happens? What's wrong? Calling - Price per minute bug.... -
SiJ - 13.07.2009
Quote:
Originally Posted by dice7
No. The problem is this:
SetTimerEx("CallCost",60000,1,"d",playerid);
It should be 0. One or true means that the timer will constantly be repeating and 0 or false means that it will execute only once
|
If I set timer CallCost just execute once, it would take money from player after one minute, and it would stop. But I need that it would take money every minute if player talks on the phone for like 3 minutes... And then he hangups, timer would stop.
Re: Why this happens? What's wrong? Calling - Price per minute bug.... -
SiJ - 13.07.2009
Am I wrong?
Re: Everything seems to be alright with the code... -
SiJ - 14.07.2009
*bump*
Hey,
Maybe there is another (easier) method to do what I want?
Cause I need to take money from player every minute while he's on phone..
Re: This code doesn't work... What's wrong? -
pen_theGun - 14.07.2009
pawn Код:
new pCall[MAX_PLAYERS];
#define MAX_CALL_COST 50
public OnGameModeInit()
{
SetTimer("CallCost", 60007, 1);
}
public OnPlayerConnect(playerid)
{
pCall[playerid] = 0;
}
public OnPlayerDisconnect(playerid)
{
pCall[playerid] = 0;
}
forward CallCost();
public CallCost()
{
for( new playerid=0; playerid < MAX_PLAYERS; playerid++ )
{
if( pCall[playerid] )
{
switch( pCall[playerid] )
{
case 555: {
if( GetPlayerMoney(playerid) < MAX_CALL_COST )
{
pCall[playerid] = 0;
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_STOPUSECELLPHONE);
PhoneMsg(playerid,"Phone Operator: You don't have enough money to pay for this call!");
ErrorMsg(playerid,"Hangup!");
}
else
{
GivePlayerMoney( playerid, -MAX_CALL_COST );
new str[64];
format(str,sizeof(str),"Call Cost: ~g~$~r~%i",Call_Cost);
GameTextForPlayer(playerid,str,3000,4);
}
}
}
}
}
return 1;
}
dcmd_call(playerid, params[])
{
new number;
if (sscanf(params, "d", number))
{
UsageMsg(playerid, "USAGE: /call <Phone #>");
HintMsg(playerid,"Available phone numbers: 112 (Emergency) 555 (Taxi)");
}
else if(number == 555)
{
if( GetPlayerMoney(playerid) < MAX_CALL_COST)
{
pCall[playerid] = 0;
PhoneMsg(playerid,"Phone Operator: You don't have enough money to call!");
}
else if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USECELLPHONE);
new str[64];
format(str,sizeof(str),"Call Cost: ~r~%i$/min",MAX_CALL_COST);
GameTextForPlayer(playerid,str,4000,4);
GivePlayerMoney(playerid, -MAX_CALL_COST);
//[SKIP] code that checks if there any taxi drivers... It works fine
pCall[playerid] = 555;
SystemMsg(playerid,"San Fierro Taxi Company");
PhoneMsg(playerid,"Dispatch: Hello, please tell location to call taxi to.");
}
else if(IsPlayerInAnyVehicle(playerid))
ErrorMsg (playerid,"You cannot speak in a vehicle..");
else ErrorMsg(playerid,"You can't call at the moment..");
}
return 1;
}
public OnPlayerText(playerid, text[])
{
if(pCall[playerid]==555)
{
new name[24];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(gTeam[i] == TEAM_TAXI)
{
//[SKIP] This works fine
}
}
pCall[playerid]=0;
return 0;
}
}
if(strcmp(cmdtext,"/h",true)==0 || strcmp(cmdtext,"/hangup",true)==0)
{
if( pCall[playerid] )
{
pCall[playerid] =0;
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_STOPUSECELLPHONE);
SystemMsg( playerid, "You hang up.." );
}
return 1;
}
Re: This code doesn't work... What's wrong? -
SiJ - 14.07.2009
Quote:
Originally Posted by pen_†ĥęGun
pawn Код:
new pCall[MAX_PLAYERS];
#define MAX_CALL_COST 50
public OnGameModeInit() { SetTimer("CallCost", 60007, 1); }
public OnPlayerConnect(playerid) { pCall[playerid] = 0; }
public OnPlayerDisconnect(playerid) { pCall[playerid] = 0; }
forward CallCost(); public CallCost() { for( new playerid=0; playerid < MAX_PLAYERS; playerid++ ) { if( pCall[playerid] ) { switch( pCall[playerid] ) { case 555: { if( GetPlayerMoney(playerid) < MAX_CALL_COST ) { pCall[playerid] = 0; SetPlayerSpecialAction(playerid,SPECIAL_ACTION_STOPUSECELLPHONE); PhoneMsg(playerid,"Phone Operator: You don't have enough money to pay for this call!"); ErrorMsg(playerid,"Hangup!"); } else { GivePlayerMoney( playerid, -MAX_CALL_COST ); new str[64]; format(str,sizeof(str),"Call Cost: ~g~$~r~%i",Call_Cost); GameTextForPlayer(playerid,str,3000,4); } } } } } return 1; }
dcmd_call(playerid, params[]) { new number; if (sscanf(params, "d", number)) { UsageMsg(playerid, "USAGE: /call <Phone #>"); HintMsg(playerid,"Available phone numbers: 112 (Emergency) 555 (Taxi)"); } else if(number == 555) { if( GetPlayerMoney(playerid) < MAX_CALL_COST) { pCall[playerid] = 0; PhoneMsg(playerid,"Phone Operator: You don't have enough money to call!"); } else if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) { SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USECELLPHONE); new str[64]; format(str,sizeof(str),"Call Cost: ~r~%i$/min",MAX_CALL_COST); GameTextForPlayer(playerid,str,4000,4); GivePlayerMoney(playerid, -MAX_CALL_COST); //[SKIP] code that checks if there any taxi drivers... It works fine
pCall[playerid] = 555; SystemMsg(playerid,"San Fierro Taxi Company"); PhoneMsg(playerid,"Dispatch: Hello, please tell location to call taxi to."); } else if(IsPlayerInAnyVehicle(playerid)) ErrorMsg (playerid,"You cannot speak in a vehicle.."); else ErrorMsg(playerid,"You can't call at the moment.."); } return 1; }
public OnPlayerText(playerid, text[]) { if(pCall[playerid]==555) { new name[24]; for(new i = 0; i < MAX_PLAYERS; i++) { if(gTeam[i] == TEAM_TAXI) { //[SKIP] This works fine } } pCall[playerid]=0; return 0; } }
if(strcmp(cmdtext,"/h",true)==0 || strcmp(cmdtext,"/hangup",true)==0) { if( pCall[playerid] ) { pCall[playerid] =0; SetPlayerSpecialAction(playerid,SPECIAL_ACTION_STOPUSECELLPHONE); SystemMsg( playerid, "You hang up.." ); }
return 1; }
|
Thanks for help.. I'll check if it works..
EDIT: Yeah it really works... Thanks again
Re: Timers.. Need help..? -
SiJ - 14.07.2009
Another question...
My payment system for cops, medics and others was like this (in first post).. And it was bugged...
So I could fix it by doing everything like pen_†ĥęGun said, to do payment system.. but there is one problem..
I want Cops to get paid 30 minutes after they use command /duty.. But if I'd use method pen_†ĥęGun posted, cops would get money then they use /duty and then after 30 minutes... But I need that they would get money every30 minutes,
but not then they type /duty ..
Example if I'd use pen_†ĥęGun method:
I'm cop, I type /duty and I instantly get payment, and then I get paid every 30 minutes..
So I don't want to get paid instantly when I type /duty
Hope you understood..

Thanks..