callback help (public robbtimer) (bugging)
#1

At my callback, its bugged.

Explaination: When i /robbank, then the wanted level goes to me. then when the robtimer is "DONE" The wanted level goes to ID 0. And the suspect name changed to ID 0 Names. For example your ID 0, Then someone rob the bank, Then when the bank robberry timer is done then it will say "
Код:
format(string, sizeof(string), "[BREAKING NEWS] The suspect %s has successfully rob the money bank", GetPlayerNameEx(playerid));
It Goes to this:
Код:
format(string, sizeof(string), "[BREAKING NEWS] The suspect ID 0 NAME has successfully rob the money bank", GetPlayerNameEx(playerid));
I hope you understand it.

QUESTION: How do i fix it?

Here is my callback codes:

Код:
public robtimer(playerid)
{
		if(RobberBusted[playerid] == 1)
		{
		    SendClientMessageToAll(COLOR_GREEN, "[BREAKING NEWS]: Bank Robberry Failed! Suspect has been BUSTED!");
		    SendClientMessage(playerid, COLOR_YELLOW, "You were busted by the POLICE, Bank Robbery Fail!");
		    RobberBusted[playerid] = 0;
		    pBankRobbing[playerid] = 0;
		    return 1;
		}
		else if(RobberBusted[playerid] == 2)
		{
		    SendClientMessageToAll(COLOR_RED, "[BREAKING NEWS]: Bank Robberry failed! Suspect has been eliminated ((Leaving/Timeout at server))");
		    RobberBusted[playerid] = 0;
		    pBankRobbing[playerid] = 0;
			return 1;
		}
		else
		{
			new string[128];//We are defining a new string for the formatted message that we are displaying later on.
		    new cash = random(2000000);
		    GivePlayerCash(playerid, cash);
	        /*
	    With the fuction above 'new cash = random(200000);
	        GivePlayerMoney(playerid, cash);' we give the player
	    a random amount of money from $0 - $200,000
	    */
	    //Here below we use the string we defined above to format the message itself and display it to the player.
	        format(string, sizeof(string), "You have successfully robbed $%d from the bank!", cash);
	        SendClientMessage(playerid, COLOR_GREEN, string);
	        format(string, sizeof(string), "[BREAKING NEWS] The suspect %s has successfully rob the money bank", GetPlayerNameEx(playerid));
	        SendClientMessageToAll(COLOR_REALRED, string);

	        ++PlayerInfo[playerid][pCrimes];
	  		++PlayerInfo[playerid][pCrimes];
			++PlayerInfo[playerid][pCrimes];

			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);


	        ++PlayerInfo[playerid][pCrimes];
	  		++PlayerInfo[playerid][pCrimes];
			++PlayerInfo[playerid][pCrimes];

			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
		}
		return 1;
}
Reply
#2

I hope it will be now

thanks guys
Reply
#3

bump
Reply
#4

Use this function instead of your GivePlayerNameEx

PHP код:

GetName
(playerid)
{
      new 
fdqkljqfdhqlsdhjf[MAX_PLAYER_NAME+1]; // I used a random name to be sure it won't get created twice in the script
      
GetPlayerName(playeridfdqkljqfdhqlsdhjfsizeof(fdqkljqfdhqlsdhjf));
      return 
fdqkljqfdhqlsdhjf;

then tell if it works or not.

EDIT : Show the timer which calls the function also please.
Reply
#5

Quote:
Originally Posted by S4t3K
Посмотреть сообщение
Use this function instead of your GivePlayerNameEx

PHP код:

GetName
(playerid)
{
      new 
fdqkljqfdhqlsdhjf[MAX_PLAYER_NAME+1]; // I used a random name to be sure it won't get created twice in the script
      
GetPlayerName(playeridfdqkljqfdhqlsdhjfsizeof(fdqkljqfdhqlsdhjf));
      return 
fdqkljqfdhqlsdhjf;

then tell if it works or not.

EDIT : Show the timer which calls the function also please.
I guess, There is no problem at my GetPlayerNameEx Function, right??

Код:
stock GetPlayerNameEx(playerid)
{

	new
		sz_playerName[MAX_PLAYER_NAME],
		i_pos;

	GetPlayerName(playerid, sz_playerName, MAX_PLAYER_NAME);
	while ((i_pos = strfind(sz_playerName, "_", false, i_pos)) != -1) sz_playerName[i_pos] = ' ';
	return sz_playerName;
}
Код:
CMD:robbank(playerid, params[])
{
        if(robpossible == 1) //If the bank can be robbed we continue below
        {
                if(IsPlayerInRangeOfPoint(playerid, 2.0, 2319.2310,-2.0349,26.7496))
                {//Next thing we do is, we check if we are at the bank interior ^^
                
                    if(AdminDuty[playerid] == 1) return SendClientMessage(playerid, COLOR_GRAD1, "You cant rob bank while on duty ^^");
                    
                    if(PlayerInfo[playerid][pCrimes] == 3 && PlayerInfo[playerid][pWantedLevel] == 3) return SendClientMessage(playerid, COLOR_GRAD1, "You cannot /robbank when you have 3+ star! Be cool!");
                    robpossible = 0; //Then we set the bank so it cannot be robbed
                    SetTimer("waittimer", 900000, false); //Normal Mode 5 minutes
                    //SetTimer("waittimer", 65000, false); //Test Mode 65 seconds
                   
                    /* We also run another timer(1 minute) for the function that is
                    actually going to give us the money and a user friendly message.
                    */
                    /*
                    Add a function that would notify the police.
                    */

                    SendClientMessageToAll(COLOR_GREEN,"[BREAKING NEWS] Bank is being robbed, do not come near the bank!");
			        SendClientMessageToAll(0x0080FFFF, "Alerting all POLICE to come at bank As Soon as possible!!!");
			        SendClientMessageToAll(0x0080FFFF, "Lahat ng police PUMUNTA sa BANK ngayon din!!!");

                    SendClientMessage(playerid, 0xFF0000FF, "You are robbing the bank, the police has been notified!");
            		SendClientMessage(playerid, 0x008000FF, "You gotta stay 5 minutes before you get the moneys!!!");
            		
            		++PlayerInfo[playerid][pCrimes];
            		++PlayerInfo[playerid][pCrimes];
            		++PlayerInfo[playerid][pCrimes];
            		
					SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
					SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
					SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
					
					GameTextForPlayer(playerid, "~r~ALERT: BANK IS BEING ROB!", 3, 5000);
				 	SetTimer("robtimer", 300000, false);
				 	
				 	RobberBusted[playerid] = 0;
				 	pBankRobbing[playerid] = 1;
					

                 } else return SendClientMessage(playerid, COLOR_WHITE, "You are not in BANK SAFE!!");
        } else {
            SendClientMessage(playerid, COLOR_WHITE, "You can't rob the bank right now! Already rob or waiting for cool down");
        }
        return 1;
}
Reply
#6

The problem comes from "SetTimer".

If a function hasn't any parameter (so anything between the () ), you use SetTimer.
But the function robtimer has a parameter or more than one, you must use SetTimerEx.

There are two additionnal parameters in SetTimerEx : the parameter format (you must put it between quotes, just like sscanf) and the parameters theirselves.

In your case, it should be

PHP код:

SetTimerEx
("robtimer"300000false"i"playerid); 
Use i or d for integers, f for floats, or b for a boolean.

Using strings and array isn't possible yet with SetTimer, but if you use y_timers, it becomes possible.
Reply
#7

Quote:
Originally Posted by S4t3K
Посмотреть сообщение
The problem comes from "SetTimer".

If a function hasn't any parameter (so anything between the () ), you use SetTimer.
But the function robtimer has a parameter or more than one, you must use SetTimerEx.

There are two additionnal parameters in SetTimerEx : the parameter format (you must put it between quotes, just like sscanf) and the parameters theirselves.

In your case, it should be

PHP код:

SetTimerEx
("robtimer"300000false"i"playerid); 
Use i or d for integers, f for floats, or b for a boolean.

Using strings and array isn't possible yet with SetTimer, but if you use y_timers, it becomes possible.
Greetings!

Thanks for your reply!


Can you please explain why there "i" at SetTimerEx?

What should i put there? Thanks!
Reply
#8

i stands for "integer", a whole number as parameter.

When you declare your function, you had to put "playerid" as a parameter. It stands for the playerid when the player is In Game, so it's an integer.

If it was a position, you had to put "f" instead and making the parameter corresponding to a floating point number.
Reply
#9

Quote:
Originally Posted by PawnOX
Посмотреть сообщение
Greetings!

Thanks for your reply!


Can you please explain why there "i" at SetTimerEx?

What should i put there? Thanks!
Special format indicating the types of values the timer will pass. "i" stands for the integer, which is a decimal number (you can also use "d" instead of the "i". It will cause the same result). "i" operator will provide a timer the player's ID to the function that is supposed to be called.

edit://
Too late.
Reply
#10

Quote:
Originally Posted by Riddick94
Посмотреть сообщение
Special format indicating the types of values the timer will pass. "i" stands for the integer, which is a decimal number (you can also use "d" instead of the "i". It will cause the same result). "i" operator will provide a timer the player's ID to the function that is supposed to be called.

edit://
Too late.
Thanks bro! It works!

One more thing,
I have 1 problem again

Here:
OnPlayerDeath

Код:
OnPlayerDisconnect
			if(pBankRobbing[giveplayerid] == 1)
			{
			    RobberBusted[giveplayerid] = 1;
			    SetTimerEx("robtimer", 0 , false, "i", playerid);
			    pBankRobbing[giveplayerid] = 0;
			}
The
Код:
public robtimer
doesnt work. it should be return 1 if
Код:
RobberBusted[playerid] == 1
is that possible? Because i tried but the robberry is still success

Код:
public robtimer(playerid)
{
		if(RobberBusted[playerid] == 1)
		{
		    SendClientMessageToAll(COLOR_GREEN, "[BREAKING NEWS]: Bank Robberry Failed! Suspect has been BUSTED!");
		    SendClientMessage(playerid, COLOR_YELLOW, "You were busted by the POLICE, Bank Robbery Fail!");
		    RobberBusted[playerid] = 0;
		    pBankRobbing[playerid] = 0;
		    return 1;
		}
		else if(RobberBusted[playerid] == 2)
		{
		    SendClientMessageToAll(COLOR_RED, "[BREAKING NEWS]: Bank Robberry failed! Suspect has been eliminated ((Leaving/Timeout at server))");
		    RobberBusted[playerid] = 0;
		    pBankRobbing[playerid] = 0;
			return 1;
		}
		else
		{
			new string[128];//We are defining a new string for the formatted message that we are displaying later on.
		    new cash = random(2000000);
		    GivePlayerCash(playerid, cash);
	        /*
	    With the fuction above 'new cash = random(200000);
	        GivePlayerMoney(playerid, cash);' we give the player
	    a random amount of money from $0 - $200,000
	    */
	    //Here below we use the string we defined above to format the message itself and display it to the player.
	        format(string, sizeof(string), "You have successfully robbed $%d from the bank!", cash);
	        SendClientMessage(playerid, COLOR_GREEN, string);
	        format(string, sizeof(string), "[BREAKING NEWS] The suspect %s has successfully rob the money bank", GetPlayerNameEx(playerid));
	        SendClientMessageToAll(COLOR_REALRED, string);

	        ++PlayerInfo[playerid][pCrimes];
	  		++PlayerInfo[playerid][pCrimes];
			++PlayerInfo[playerid][pCrimes];

			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);


	        ++PlayerInfo[playerid][pCrimes];
	  		++PlayerInfo[playerid][pCrimes];
			++PlayerInfo[playerid][pCrimes];

			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
			SetPlayerWantedLevel(playerid, ++PlayerInfo[playerid][pWantedLevel]);
		}
		return 1;
}
Thanks again!


EDIT: I use the RobberBusted var OnPlayerDisconnect and OnPlayerDeath, QUESTION: Should i try the pVarInt?
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)