PDA

View Full Version : This code don't send money


Face9000
30/12/2011, 05:01 PM
Hello,i've this lotto code to sent the jackpot money at the winner,i made some tests in my server and when i pickup the winning number,it shows the winning message but IT DOESN'T GIVE MONEY :confused:

if(winner != -1) //If there was a winner
{
for(new i; i<MAX_PLAYERS; i++) //checks through all players
{
new Pname[24];
GetPlayerName(i, Pname, 24);
new str[128];
SendClientMessageToAll(0x62FF32FF, "****LOTTO INFORMATION****"); //Lotto info
format(str, sizeof(str), "WE HAVE A WINNER! %s (Id: %d) won $%d!!!!", Pname, i, Jackpot);
LottoLog(str);
GivePlayerMoney(i, Jackpot);
SendClientMessageToAll(0x62FF32FF, str); //Lotto info
SendClientMessageToAll(0x62FF32FF, "Make sure you get a ticket for next draw - /lotto [1-30]"); //Lotto info
Jackpot = LOTTO_START; //Resets the jackpot
}
}

What's wrong?

James Coral
30/12/2011, 05:02 PM
Right Code:

if(strcmp(cmd, "/givemoney", true) == 0)
{
new string[128];
new playermoney;
new sendername[MAX_PLAYER_NAME];
new giveplayer[MAX_PLAYER_NAME];
new giveplayerid, moneys;
tmp = strtok(cmdtext, idx);

if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_RED, "USAGE: /givecash <playerid/playername> <amount>");
return 1;
}
giveplayerid = strval(tmp);

tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_RED, "USAGE: /givecash <playerid/playername> <amount>");
return 1;
}
moneys = strval(tmp);

if (IsPlayerConnected(giveplayerid) && giveplayerid != INVALID_PLAYER_ID && giveplayerid != playerid)
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
playermoney = GetPlayerMoney(playerid);

if (moneys > 0 && playermoney >= moneys)
{
GivePlayerMoney(playerid, (0 - moneys));
GivePlayerMoney(giveplayerid, moneys);
format(string, sizeof(string), "You gave %s(%d), Money Amount: $%d.", giveplayer,giveplayerid, moneys);
SendClientMessage(playerid, COLOR_GREEN, string);
format(string, sizeof(string), "You got $%d from %s(%d).", moneys, sendername, playerid);
SendClientMessage(giveplayerid, COLOR_GREEN, string);
PlayerPlaySound(playerid,1084,0.0,0.0,0.0);
printf("%s(%d) has transfered %d to %s(%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
}
else
{
SendClientMessage(playerid, COLOR_RED, "Invalid amount!");
}
}
else
{
format(string, sizeof(string), "ERROR: Player Is Not Connected or Its Yourself!");
SendClientMessage(playerid, COLOR_RED, string);
}
return 1;
}

James Coral
30/12/2011, 05:05 PM
Sorry For Touble Posting But i got that you want /givemoney CODE :D
Sorry for Code btw!

Face9000
30/12/2011, 05:14 PM
Emh what is that?I've already my givemoney cmd,i need only to fix that part of code i provided in first post.

Ash.
30/12/2011, 05:17 PM
Debug the code, print out something after every line. It must be silently exiting somewhere.

James Coral
30/12/2011, 05:20 PM
Lol check other FilterScript i remember i have seen Jackpot FS

James Coral
30/12/2011, 05:22 PM
like i find : http://forum.sa-mp.com/showthread.php?t=35631&highlight=JackPot

USE NEXT TIME SEARCH!
(You can take there a Code)

Face9000
30/12/2011, 05:26 PM
Debug the code, print out something after every line. It must be silently exiting somewhere.

GivePlayerMoney(i, Jackpot);

Is not enough? The lotto system works good,the numbers are draw'ed but the only fault is it don't give the jackpot money to the winner.

like i find : http://forum.sa-mp.com/showthread.php?t=35631&highlight=JackPot

USE NEXT TIME SEARCH!
(You can take there a Code)

Before i made this topic i searched like 5 times.I've coded ALL lotto script and in my gamemode I dont use (and i dont want) others filterscripts,i make my functions so if i have a problem i know where is the fix.

Ash.
30/12/2011, 05:36 PM
like i find : http://forum.sa-mp.com/showthread.php?t=35631&highlight=JackPot

USE NEXT TIME SEARCH!
(You can take there a Code)

This isn't helpful. They want to script it theirselves, rather than become a plagiarist.

GivePlayerMoney(i, Jackpot);

Is not enough? The lotto system works good,the numbers are draw'ed but the only fault is it don't give the jackpot money to the winner.

It should be. Print out what "i" and "Jackpot" are. And, like I say, try printing out every line to see if it's silently exerting.

Face9000
30/12/2011, 05:42 PM
Oh sorry for not explaining.

The "i" is a loop of all players:

for(new i; i<MAX_PLAYERS; i++)
{

the "Jackpot" is a value that store the Jackpot money and gives it to the winner.

Ash.
30/12/2011, 05:50 PM
Replace the code with this and post the results in this thread.

if(winner != -1) //If there was a winner
{
printf("Winner is not -1. It is: %i", winner);
for(new i; i<MAX_PLAYERS; i++) //checks through all players
{
printf("Running for loop -- i == %i", i);
new Pname[24];
GetPlayerName(i, Pname, 24);
printf("Got the player's name (%s)", Pname);
new str[128];
SendClientMessageToAll(0x62FF32FF, "****LOTTO INFORMATION****"); //Lotto info
print("Sent \"****Lot...\" to all players");
format(str, sizeof(str), "WE HAVE A WINNER! %s (Id: %d) won $%d!!!!", Pname, i, Jackpot);
print("Formatted str. str is: %s", str);
LottoLog(str);
print("Logged");
GivePlayerMoney(i, Jackpot);
printf("GivePlayerMoney(%i, %i) ran succesfully.", i, Jackpot);
SendClientMessageToAll(0x62FF32FF, str); //Lotto info
SendClientMessageToAll(0x62FF32FF, "Make sure you get a ticket for next draw - /lotto [1-30]"); //Lotto info
print("Sent two messages.");
Jackpot = LOTTO_START; //Resets the jackpot
print("Reset Jackpot Total");
}
}


That will print out data at all (significant) points. It will also print out what some of the main data is to ensure that it is being handled correctly.

//Edit: Sorry for the indentation, did it in Notepad... :S

Face9000
30/12/2011, 06:22 PM
Strange,now it's working,seems there was a problem with random numer :| Thanks anyway for help!