Processing Payday Code For Everybody Problem(Timer,playerid) -
grymtn - 06.04.2017
Hello friend im trying to process a payday timer but apparently it doesnt give payday to everybody. Only i seem to get it as id 0 so id 1 and others dont get it.. Also same problem exists with command /id which only can show id 0 but not id 1 and others..
My Codes:
Код:
SetTimer("payday", 30000 ,1); //on game mode init
forward payday(playerid);
public payday(playerid)
{
new savingsmoney,Text[200],bankmoney;
if (!INGAME[playerid][LOGIN]) {
format(Text,sizeof(Text),"You Need To Login Before Doing Anything.");
SendClientMessage(playerid,COLOR_RED,Text);
}
else {
USER[playerid][EXP] = USER[playerid][EXP]+1;
savingsmoney = (USER[playerid][SAVINGS]/100)*5;
bankmoney = (USER[playerid][BANK]/100)*2;
USER[playerid][SAVINGS] = USER[playerid][SAVINGS]+savingsmoney;
USER[playerid][BANK] = USER[playerid][BANK]+bankmoney;
format(Text,sizeof(Text),"---------------------------------------------");
SendClientMessage(playerid, -1, Text);
format(Text,sizeof(Text),"You Have Earned 1 Experience Point On PayDay");
SendClientMessage(playerid, -1, Text);
format(Text,sizeof(Text),"Your New Bank Balance Is: %d",USER[playerid][BANK]);
SendClientMessage(playerid, -1, Text);
format(Text,sizeof(Text),"Your New Savings Balance Is: %d",USER[playerid][SAVINGS]);
SendClientMessage(playerid, -1, Text);
format(Text,sizeof(Text),"---------------------------------------------");
SendClientMessage(playerid, -1, Text);
}
return 1;
}
CMD:id(playerid, params[])
{
new id,string[150],name[24],pname[24];
if(sscanf(params, "u", name)) return SendClientMessage(playerid,-1,"Usage: /id [name]");
id = GetPlayerID(name);
GetPlayerName(id,pname,24);
format(string,sizeof(string),"%d %s",id,pname);
SendClientMessage(playerid,COLOR_LIGHTGRAY,string);
return 1;
}
stock GetPlayerID(const Name[])
{
for(new i; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new pName2[MAX_PLAYER_NAME];
GetPlayerName(i, pName2, sizeof(pName2));
if(strcmp(Name, pName2, true)==0)
{
return i;
}
}
}
return -1;
}
Any Help Is Appreciated
Re: Processing Payday Code For Everybody Problem(Timer,playerid) -
DarkSkull - 06.04.2017
That is because you are only giving it to the first player id. You need to loop through all the players in the game.
Re: Processing Payday Code For Everybody Problem(Timer,playerid) -
grymtn - 06.04.2017
I dont really know how to process a loop tho do you know a tutorial link for it or maybe if you can give a simple example loop (i have loop on id command with GetPlayerID(name) but it still doesnt seem like working)
Re: Processing Payday Code For Everybody Problem(Timer,playerid) -
DarkSkull - 06.04.2017
PHP код:
forward payday();
public payday()
{
new savingsmoney,Text[200],bankmoney;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if (!INGAME[i][LOGIN]) {
format(Text,sizeof(Text),"You Need To Login Before Doing Anything.");
SendClientMessage(i,COLOR_RED,Text);
}
else {
USER[i][EXP] = USER[i][EXP]+1;
savingsmoney = (USER[i][SAVINGS]/100)*5;
bankmoney = (USER[i][BANK]/100)*2;
USER[i][SAVINGS] = USER[i][SAVINGS]+savingsmoney;
USER[i][BANK] = USER[i][BANK]+bankmoney;
format(Text,sizeof(Text),"---------------------------------------------");
SendClientMessage(i, -1, Text);
format(Text,sizeof(Text),"You Have Earned 1 Experience Point On PayDay");
SendClientMessage(i, -1, Text);
format(Text,sizeof(Text),"Your New Bank Balance Is: %d",USER[i][BANK]);
SendClientMessage(i, -1, Text);
format(Text,sizeof(Text),"Your New Savings Balance Is: %d",USER[i][SAVINGS]);
SendClientMessage(i, -1, Text);
format(Text,sizeof(Text),"---------------------------------------------");
SendClientMessage(i, -1, Text);
}
}
}
return 1;
}
Try this.
Re: Processing Payday Code For Everybody Problem(Timer,playerid) -
DarkSkull - 06.04.2017
Also, You don't need the payday(playerid)
Change:
PHP код:
forward payday(playerid);
public payday(playerid)
To:
PHP код:
forward payday();
public payday()
Re: Processing Payday Code For Everybody Problem(Timer,playerid) -
grymtn - 06.04.2017
thank you so much still as i said id has a loop already but it doesnt seem like working can you check hat too like if i have problem with loop there?
Edit: rep given i just learned how loop works
Re: Processing Payday Code For Everybody Problem(Timer,playerid) -
DarkSkull - 06.04.2017
PHP код:
stock GetPlayerID(playername[])
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new playername2[MAX_PLAYER_NAME];
GetPlayerName(i, playername2, sizeof(playername2));
if(strcmp(playername2, playername, true, strlen(playername)) == 0)
{
return i;
}
}
}
return INVALID_PLAYER_ID;
}
Try this.
You also need to check if the player is connected in your id command.
PHP код:
CMD:id(playerid, params[])
{
new id,string[150],name[24],pname[24];
if(sscanf(params, "u", name)) return SendClientMessage(playerid,-1,"Usage: /id [name]");
id = GetPlayerID(name);
if(id=INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Player not connected!");
GetPlayerName(id,pname,24);
format(string,sizeof(string),"%d %s",id,pname);
SendClientMessage(playerid,COLOR_LIGHTGRAY,string);
return 1;
}
Re: Processing Payday Code For Everybody Problem(Timer,playerid) -
grymtn - 06.04.2017
tried it returns like "65535" instead of "1 Chaves"
Re: Processing Payday Code For Everybody Problem(Timer,playerid) -
DarkSkull - 06.04.2017
Did you update the id command as well?
Re: Processing Payday Code For Everybody Problem(Timer,playerid) -
grymtn - 06.04.2017
i did now it always returns that player id is not online to id 0 too