Need help with my payday function.
#1

I've made this callback:

Код:
public PayDay()
{
	for(new i; i < MAX_PLAYERS && IsPlayerConnected(i); i++)
	{
		//Calculating the payday
		new string[256],
		query2[256],
		user_payload = floatround(0.000003 * playerVariables[i][pLevel] * playerVariables[i][pBankMoney]),
		user_rent_price = houseVariables[ playerVariables[i][pHouseRented] ][hRent],
		user_tax = floatround(user_payload / 100 * 10),
		hours = floatround(3600 / playerVariables[i][pSeconds]),
		user_premium_bonus;
		if(playerVariables[i][pDonate] == 1) user_premium_bonus = 50000;
		new user_total_payload = user_payload + user_premium_bonus - user_rent_price - user_tax;
		SCM(i, COLOR_GREY, "PayDay:");
		SCM(i, -1, "Your paycheck has arrived, visit the bank or atm to withdraw your money.");
		format(string, sizeof(string), "Payload: $%s | Rent: $%s | Tax: $%s (10 percent) | Bonus: $%s (Premium) | Total Payload: $%s", NumberFormat(user_payload), NumberFormat(user_rent_price), NumberFormat(user_tax), NumberFormat(user_premium_bonus), NumberFormat(user_total_payload));
		SCM(i, -1, string);	
		playerVariables[i][pBankMoney] += user_total_payload;

		//Licences
		if(playerVariables[i][pDriveLicense] > 0)
		{
			playerVariables[i][pDriveLicense] -= 1;
			if(playerVariables[i][pDriveLicense] == 0) return SS(i, -1, "Your drivings licence has expired. Visit de DMV to renew it.", "Licenta ta de condus a expirat. Visiteaza DMV-ul pentru a da de permis.");
		}
		if(playerVariables[i][pGunLicense] > 0)
		{
			playerVariables[i][pGunLicense] -= 1;
			if(playerVariables[i][pGunLicense] == 0) return SS(i, -1, "Your gun licence has expired. Contact an instructor to renew it.", "Licenta ta de port arma a expirat. Contacteaza un instructor pentru a lua una noua.");
		}	
		if(playerVariables[i][pFlyLicense] > 0)
		{
			playerVariables[i][pFlyLicense] -= 1;
			if(playerVariables[i][pFlyLicense] == 0) return SS(i, -1, "Your flying licence has expired. Contact an instructor to renew it.", "Licenta ta de pilot a expirat. Contacteaza un instructor pentru a lua una noua.");
		}	
		if(playerVariables[i][pBoatLicense] > 0)
		{
			playerVariables[i][pBoatLicense] -= 1;
			if(playerVariables[i][pBoatLicense] == 0) return SS(i, -1, "Your sailing licence has expired. Contact an instructor to renew it.", "Licenta ta de barca a expirat. Contacteaza un instructor pentru a lua una noua.");
		}

		//Counting down the hours
		if(playerVariables[i][pSeconds] >= 1800)
		{
			if(playerVariables[i][pLang] == 0)
			{
				format(string, sizeof(string), "Ai jucat %d minute din ultima ora.", floatround(playerVariables[i][pSeconds] / 60));
				SCM(i, -1, string);
			}
			else
			{
				format(string, sizeof(string), "You have played %d minutes from the last hour.", floatround(playerVariables[i][pSeconds] / 60));
				SCM(i, -1, string);
			}
			playerVariables[i][pGiftHours] --;
		}	
		else return SS(i, -1, "You haven't played 31 minutes to gain a full hour.", "Nu ai jucat 31 de minute pentru a primi o ora completa.");

		if(playerVariables[i][pHelper] > 0)
		{
			playerVariables[i][pBankMoney] += 50000;
			SS(i, -1, "You have received $50,000 as salary for being a helper.", "Ai primit $50,000 deoarece esti un helper.");
		}
		
		if(playerVariables[i][pGroupRank] == 7)
		{
			playerVariables[i][pBankMoney] += 50000;
			SS(i, -1, "You have received $50,000 as salary for being a leader.", "Ai primit $50,000 deoarece esti un lider.");
		}	

		//Other
		playerVariables[i][pRobPoints]++;
	    playerVariables[i][pRPoints]++;
	    if(playerVariables[i][pFPunish] > 0)
		{
			playerVariables[i][pFPunish]--;
		}

		format(query2, sizeof(query2), "INSERT INTO `user_activity` (`user_hours`, `user_id`) VALUES ('%d', '%d')", hours, playerVariables[i][pInternalID]);
		mysql_tquery(handle, query2);

		playerVariables[i][pSeconds] = 0;

		savePlayerData(i);
																				
	}
	return 1;
}
Whenever this callback is called, it only calls like the half of it.
The query doesn't work, and the helper and leader salary's aren't called either.
There is no output in the mysql log, neither in the server log.
Also, the part where pSeconds is set to 0, isn't called either.
The calculation doesn't work either. It returns 0 everywhere in the text, so basically I don't get any money.
Reply
#2

is pSeconds @ floatround(3600 / playerVariables[i][pSeconds]) 0 ?

Also, try actually debugging variables with logs.
Reply
#3

This whole loop is wrong.

Код:
for(new i; i < MAX_PLAYERS && IsPlayerConnected(i); i++)
If ID 0 isn't connected, no one gets payday!
You need to pass that cycle with continue when a player isn't connected.

Other than that, sounds like a crash, run crashdetect plugin with your code and come back with results if any.
Reply
#4

Quote:
Originally Posted by PrawkC
Посмотреть сообщение
is pSeconds @ floatround(3600 / playerVariables[i][pSeconds]) 0 ?

Also, try actually debugging variables with logs.
No, it's not 0, it depends on how many seconds you stay on the server.
Reply
#5

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
This whole loop is wrong.

Код:
for(new i; i < MAX_PLAYERS && IsPlayerConnected(i); i++)
If ID 0 isn't connected, no one gets payday!
You need to pass that cycle with continue when a player isn't connected.

Other than that, sounds like a crash, run crashdetect plugin with your code and come back with results if any.
Changed that, and it stil doesn't work. Also, crashdetect doesn't display anything.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)