SA-MP Forums Archive
What's wrong with this script? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: What's wrong with this script? (/showthread.php?tid=373186)



What's wrong with this script? - Johnson_Brooks - 29.08.2012

I wanted to create achievements for my racing gamemode .
pawn Код:
OnPlayerUpdate(playerid)
{
    new string[100];
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pname,sizeof(pname));
    if(GetPlayerScore(playerid) >=100)
    {
    format(string,sizeof(string),"%s reached 100 score and received 100,000$",pname);
    SendClientMessageToAll(COLOR_LIGHTBLUE,string);
    GivePlayerMoney(playerid, 100000);
    }
    if(GetPlayerScore(playerid) >=250)
    {
    format(string,sizeof(string),"%s reached 250 score and received 250,000$",pname);
    SendClientMessageToAll(COLOR_LIGHTBLUE,string);
    GivePlayerMoney(playerid, 250000);
    }
    if(GetPlayerScore(playerid) >=500)
    {
    format(string,sizeof(string),"%s reached 500 score and received 500,000$,and VIP status",pname);
    SendClientMessageToAll(COLOR_LIGHTBLUE,string);
    GivePlayerMoney(playerid, 500000);
    }
    if(GetPlayerScore(playerid) >=1000)
    {
    format(string,sizeof(string),"%s reached 1000 score and received 1,000,000$",pname);
    SendClientMessageToAll(COLOR_LIGHTBLUE,string);
    GivePlayerMoney(playerid, 1000000);
    }
    if(GetPlayerScore(playerid) >=2500)
    {
    format(string,sizeof(string),"%s reached 250 score and received 2,500,000$",pname);
    SendClientMessageToAll(COLOR_LIGHTBLUE,string);
    GivePlayerMoney(playerid, 2500000);
    }
    if(GetPlayerScore(playerid) >=5000)
    {
    format(string,sizeof(string),"%s reached 500 score and received 5,000,000$",pname);
    SendClientMessageToAll(COLOR_LIGHTBLUE,string);
    GivePlayerMoney(playerid, 250000);
    }
    if(GetPlayerScore(playerid) >=10000)
    {
    format(string,sizeof(string),"%s reached 10000 score and received 10,000,000%",pname);
    SendClientMessageToAll(COLOR_LIGHTBLUE,string);
    GivePlayerMoney(playerid, 10000000);
    }
        return 1;
}
pawn Код:
CMD:achievements(playerid,params[])
{
    //SendClientMessage(playerid,COLOR_RED,"This page is under construction");
    ShowPlayerDialog(playerid, 95, DIALOG_STYLE_MSGBOX, "Achievement Menu","Achievement - Reward - Special\n100 score - 100,000$\n 250 score - 250,000$ 500 score - 500,000 - VIP\n 1000 score - 1,000,000$\n 2500 score - 2,500,000$\n5000 score - 5,000,000$\n 10000 score - 10,000,000","OK","");
    return 1;
}
I dont know whats wrong but when someone reaches 100 score,the chat is being spammed by the custom messages and he receives his money more than he should to.


Re: What's wrong with this script? - Mr.Anonymous - 29.08.2012

Try using else if statement.


Re: What's wrong with this script? - Zaila - 29.08.2012

if(GetPlayerScore(playerid) >=100)

to

if(GetPlayerScore(playerid) == 100)

Do it on each line.


Re: What's wrong with this script? - HuSs3n - 29.08.2012

LOL why OnPlayerUpdate ?


Re: What's wrong with this script? - Johnson_Brooks - 29.08.2012

Quote:
Originally Posted by HuSs3n
Посмотреть сообщение
LOL why OnPlayerUpdate ?
Where should i put it?
Note: i tried == ,still the same thing,he receives his money every second instant of one time,and the messages spam the chat every second.


Re: What's wrong with this script? - ThePrograme - 29.08.2012

Well if you have the command opening a dialog you should put in under OnDilaogResponse!


Re: What's wrong with this script? - Johnson_Brooks - 29.08.2012

it opens on a msgbox not in a list so there's no need to put it under OnDialogResponse.....
If i there's no solution about the current code,i will request an /achievements script on the script request thread 5


Re: What's wrong with this script? - Misiur - 29.08.2012

Think logically. OnPlayerUpdate is very frequent, and the condition is true on every call. You need to mark that user already got the achievement.


Re: What's wrong with this script? - Johnson_Brooks - 29.08.2012

And how will i do that?
NOTE: Im a scripter so i dont know how.


Re: What's wrong with this script? - Roko_foko - 29.08.2012

Quote:
Originally Posted by Johnson_Brooks
Посмотреть сообщение
And how will i do that?
NOTE: Im a scripter so i dont know how.
When you increase someones score, THEN check what rank they are. Also use == instead of >=