Cookies
#1

I have a street sweeping job which players can earn money by cleaning streets. They get X money for every meter they clean.

I want also to give cookies, but i want to give 1 cookie every 1000 meters (1km) cleaned, how i can do it?

This is the reward code after a player finishes to clean streets:

pawn Код:
if(oldstate == PLAYER_STATE_DRIVER && SweeperJob[playerid])
    {
        new money = floatround(SweeperDistance[playerid] * MONEY_PER_METER), string[80];
        format(string, sizeof(string), "~n~~n~~w~Distance Cleaned: ~b~~h~~h~%d Meters~n~~w~Earned ~g~~h~~h~%d$", SweeperDistance[playerid], money);
        GameTextForPlayer(playerid, string, 3000, 3);
        new buf[200];
        format(buf, sizeof(buf), "~r~%s (%d) ~w~cleaned ~g~%d meters ~w~with Sweeper and earned ~g~%d$.", ReturnPlayerName(playerid), playerid, SweeperDistance[playerid], money);
        SendBoxMessage(playerid, buf);
        Player[playerid][Cookies] ++;
        GivePlayerMoney(playerid, money);
        Player[playerid][PSweeperDistance] += SweeperDistance[playerid];
        Player[playerid][SweeperMoney] += money;
        ResetSweeperInfo(playerid, true);
    }
Reply
#2

PHP код:
if(SweeperDistance[playerid] >= 1000)// 1000M = 1KM
       

       
// Code...
       

Reply
#3

You don't get it. I want to multiply number of cookies to give for every 1000 meters (1x1000)

Example: Player cleans 5000 meters, give him 5 cookies.
Reply
#4

You could try something like this:
PHP код:

if(SweeperDistance[playerid] = 1000)// 1000M = 1KM 
       
{  
       
GiveCookie etc
       
}  
else if(
SweeperDistance[playerid] = 2000)// 2000M
       
{
       
GiveCookie etc
       
}
etc etc 
Sadly this means you will have to set a limit.
Reply
#5

Just divide the distance by 1000 and round it down to an integer value. That will give the number of cookies earned.

Код:
new cookies = floatround(distance / 1000.0, floatround_floor);
If you want to reward the players while they are working, you must keep track of how many cookies they got so far. Once the amount from the calculation above is different from the stored value, give another cookie and update the variable.
Reply
#6

Nas, can you make me an example?
Reply
#7

I would solve this with a while loop, where you for each 1000 meter, give 1 cookie
PHP код:
if(oldstate == PLAYER_STATE_DRIVER && SweeperJob[playerid])
{
    new 
money floatround(SweeperDistance[playerid] * MONEY_PER_METER), string[80];
    
format(stringsizeof(string), "~n~~n~~w~Distance Cleaned: ~b~~h~~h~%d Meters~n~~w~Earned ~g~~h~~h~%d$"SweeperDistance[playerid], money);
    
GameTextForPlayer(playeridstring30003);
    new 
buf[200];
    
format(bufsizeof(buf), "~r~%s (%d) ~w~cleaned ~g~%d meters ~w~with Sweeper and earned ~g~%d$."ReturnPlayerName(playerid), playeridSweeperDistance[playerid], money);
    
SendBoxMessage(playeridbuf);
    
Player[playerid][Cookies] ++;
    
GivePlayerMoney(playeridmoney);
    
Player[playerid][PSweeperDistance] += SweeperDistance[playerid];
    
Player[playerid][SweeperMoney] += money;
    while(
SweeperDistance[playerid] % 1000 == && SweeperDistance[playerid] != && SweeperDistance[playerid] > 0)
    {
        
Player[playerid][Cookies/*Whatever variable name you have here*/] ++;
        
SweeperDistance[playerid] -= 1000;
    }
    
ResetSweeperInfo(playeridtrue);

Reply
#8

Quote:
Originally Posted by Tord
Посмотреть сообщение
I would solve this with a while loop, where you for each 1000 meter, give 1 cookie
PHP код:
if(oldstate == PLAYER_STATE_DRIVER && SweeperJob[playerid])
{
    new 
money floatround(SweeperDistance[playerid] * MONEY_PER_METER), string[80];
    
format(stringsizeof(string), "~n~~n~~w~Distance Cleaned: ~b~~h~~h~%d Meters~n~~w~Earned ~g~~h~~h~%d$"SweeperDistance[playerid], money);
    
GameTextForPlayer(playeridstring30003);
    new 
buf[200];
    
format(bufsizeof(buf), "~r~%s (%d) ~w~cleaned ~g~%d meters ~w~with Sweeper and earned ~g~%d$."ReturnPlayerName(playerid), playeridSweeperDistance[playerid], money);
    
SendBoxMessage(playeridbuf);
    
Player[playerid][Cookies] ++;
    
GivePlayerMoney(playeridmoney);
    
Player[playerid][PSweeperDistance] += SweeperDistance[playerid];
    
Player[playerid][SweeperMoney] += money;
    while(
SweeperDistance[playerid] % 1000 == && SweeperDistance[playerid] != && SweeperDistance[playerid] > 0)
    {
        
Player[playerid][Cookies/*Whatever variable name you have here*/] ++;
        
SweeperDistance[playerid] -= 1000;
    }
    
ResetSweeperInfo(playeridtrue);

Not a good solution, why a while loop if one operation can solve it.
Apart from that, modulo isn't available for Float values!


@Despacito

Here's your code with the line added. You only had to add that and remove your old line for giving the cookie.

Код:
if(oldstate == PLAYER_STATE_DRIVER && SweeperJob[playerid])
	{
	    new money = floatround(SweeperDistance[playerid] * MONEY_PER_METER), string[80];
	    format(string, sizeof(string), "~n~~n~~w~Distance Cleaned: ~b~~h~~h~%d Meters~n~~w~Earned ~g~~h~~h~%d$", SweeperDistance[playerid], money);
	    GameTextForPlayer(playerid, string, 3000, 3);
	    new buf[200];
		format(buf, sizeof(buf), "~r~%s (%d) ~w~cleaned ~g~%d meters ~w~with Sweeper and earned ~g~%d$.", ReturnPlayerName(playerid), playerid, SweeperDistance[playerid], money);
		SendBoxMessage(playerid, buf);
	    GivePlayerMoney(playerid, money);
	    Player[playerid][PSweeperDistance] += SweeperDistance[playerid];
	    Player[playerid][SweeperMoney] += money;
	    ResetSweeperInfo(playerid, true);

	    Player[playerid][Cookies] += floatround(Player[playerid][PSweeperDistance] / 1000.0, floatround_floor);
	}
Reply
#9

Quote:
Originally Posted by NaS
Посмотреть сообщение
Not a good solution, why a while loop if one operation can solve it.
Apart from that, modulo isn't available for Float values!


@Despacito

Here's your code with the cookie code I provided. You just had to add the line to it :P

Код:
if(oldstate == PLAYER_STATE_DRIVER && SweeperJob[playerid])
	{
	    new money = floatround(SweeperDistance[playerid] * MONEY_PER_METER), string[80];
	    format(string, sizeof(string), "~n~~n~~w~Distance Cleaned: ~b~~h~~h~%d Meters~n~~w~Earned ~g~~h~~h~%d$", SweeperDistance[playerid], money);
	    GameTextForPlayer(playerid, string, 3000, 3);
	    new buf[200];
		format(buf, sizeof(buf), "~r~%s (%d) ~w~cleaned ~g~%d meters ~w~with Sweeper and earned ~g~%d$.", ReturnPlayerName(playerid), playerid, SweeperDistance[playerid], money);
		SendBoxMessage(playerid, buf);
	    GivePlayerMoney(playerid, money);
	    Player[playerid][PSweeperDistance] += SweeperDistance[playerid];
	    Player[playerid][SweeperMoney] += money;
	    ResetSweeperInfo(playerid, true);

	    Player[playerid][Cookies] += floatround(Player[playerid][PSweeperDistance] / 1000.0, floatround);
	}
You're absolutely right, I hadn't considered it as a float value - my bad. Thanks for correcting me
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)