13.07.2009, 17:18
EDIT: SKIP TO THE LAST POST
Hey,
I had to close my server because of this BUG
Here's the code:
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..
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;
}
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..