[Tutorial] Christmas tree with a reward!
#1

Christmas Tree with a reward!

Since Christmas is coming, i decided to create something different ;p

You will need:

You will need these COLOR defines! (Add them above/below to your other #defines.)
* #define COLOR_GREEN 0x33AA33AA
* #define COLOR_RED 0xAA3333AA
* #define COLOR_PINK 0xFFC0CBAA

Alright, after you've done with the #include and #define stuff, you will need to add this to the enum
pawn Код:
enum pInfo
{
    Your other enum info here.
    pReward//christmas enum
}
Alright, now on "GameModeInit" you will want to add these codes(They are the maps..)

pawn Код:
CreateObject(19076, -946.34711, -2353.33032, 58.38636,   0.00000, 0.00000, 0.00000);
    CreateObject(19054, -946.71075, -2351.16333, 59.29447,   0.00000, 0.00000, 0.00000);
    CreateObject(19055, -945.34058, -2354.35840, 59.16312,   0.00000, 0.00000, 62.00000);
    CreateObject(19057, -948.36517, -2352.48682, 59.38760,   0.00000, 0.00000, 120.00000);
    CreateObject(19058, -947.32227, -2353.96802, 59.29070,   0.00000, 0.00000, -164.00000);
    CreateObject(19055, -945.13593, -2352.45605, 59.16310,   0.00000, 0.00000, -40.00000);
    CreateObject(19076, -2189.20996, -1853.89319, 220.24968,   0.00000, 0.00000, 0.00000);
    CreateObject(19054, -2189.45313, -1852.35242, 220.31758,   4.00000, 18.00000, 47.00000);
    CreateObject(19054, -2187.96143, -1854.71277, 221.06360,   -11.00000, 0.00000, 98.00000);
    CreateObject(19055, -2191.70093, -1852.27332, 220.53413,   0.00000, 0.00000, 0.00000);
    CreateObject(19057, -2190.60498, -1855.23853, 221.26430,   -14.00000, 0.00000, 47.00000);
    CreateObject(19315, -2183.29028, -1853.40369, 220.43680,   0.00000, 0.00000, 47.00000);
    CreateObject(19315, -2166.66748, -1852.70630, 219.76862,   0.00000, -33.00000, 244.00000);
    CreateObject(19076, -2404.43408, -1618.88440, 514.97394,   -5.00000, 0.00000, 0.00000);
    CreateObject(19054, -2401.79907, -1620.84705, 516.20172,   -12.00000, 0.00000, 0.00000);
    CreateObject(19055, -2403.82739, -1616.35608, 514.80792,   0.00000, 7.00000, 84.00000);
    CreateObject(19058, -2407.35132, -1616.77612, 516.03430,   0.00000, 18.00000, 33.00000);
    CreateObject(19057, -2402.52686, -1618.66724, 515.47900,   0.00000, 21.00000, 76.00000);
    CreateObject(19076, 1256.15234, -2028.62988, 57.86828,   0.00000, 0.00000, 0.00000);
    CreateObject(19054, 1255.22070, -2026.92334, 58.99360,   0.00000, 0.00000, 104.00000);
    CreateObject(19054, 1254.16138, -2028.70288, 58.99360,   0.00000, 0.00000, 25.00000);
    CreateObject(19055, 1258.19727, -2029.95288, 58.96250,   0.00000, 0.00000, -69.00000);
    CreateObject(19057, 1254.96619, -2030.25781, 59.09870,   0.00000, 0.00000, -33.00000);
    CreateObject(19058, 1257.25598, -2028.11853, 58.84606,   0.00000, 0.00000, 0.00000);
    CreateObject(19315, 1261.96313, -2019.41223, 58.70100,   0.00000, 0.00000, 244.00000);
    CreateObject(19315, 1243.98804, -2044.52710, 59.10608,   0.00000, 0.00000, 26.00000);
    CreateObject(19057, 1256.66602, -2033.13818, 59.03652,   0.00000, 0.00000, 4.00000);
    CreateObject(19055, 1256.74658, -2033.18311, 60.18052,   0.00000, 0.00000, -69.00000);
    CreateObject(19055, 1257.06934, -2031.25256, 58.96250,   0.00000, 0.00000, -69.00000);
    CreateObject(19058, 1257.94202, -2032.91553, 58.84606,   0.00000, 0.00000, 0.00000);
    CreateObject(19076, 2487.81030, -1665.24573, 12.19823,   0.00000, 0.00000, 0.00000);
    CreateObject(19054, 2487.39697, -1667.08740, 12.81403,   0.00000, 0.00000, 0.00000);
    CreateObject(19054, 2486.17529, -1665.59949, 12.81400,   0.00000, 0.00000, 69.00000);
    CreateObject(19057, 2488.78638, -1664.39929, 12.81860,   0.00000, 0.00000, -25.00000);
    CreateObject(19058, 2489.41992, -1665.86194, 12.78070,   0.00000, 0.00000, 0.00000);
    CreateObject(19055, 2487.26807, -1663.83179, 12.84320,   0.00000, 0.00000, 25.00000);
    CreateObject(19058, 2489.36108, -1646.16174, 13.48483,   0.00000, 0.00000, 0.00000);
    CreateObject(19054, 2490.32373, -1690.95557, 14.21994,   0.00000, 0.00000, 0.06000);
    CreateObject(19054, 2488.88086, -1667.51062, 12.81400,   0.00000, 0.00000, 40.00000);
    CreateObject(19055, 2485.69409, -1663.76208, 12.84320,   0.00000, 0.00000, -76.00000);
    CreateObject(19058, 2487.75024, -1668.63013, 12.78070,   0.00000, 0.00000, 0.00000);
    CreateObject(19057, 2485.45410, -1666.91138, 12.81860,   0.00000, 0.00000, 25.00000);
    CreateObject(19057, 2484.27686, -1665.02930, 12.81860,   0.00000, 0.00000, -91.00000);

They aren't 100% needed, but still, if you're lazy, then they are for you!
Now, on "OnPlayerConnect" you will need to add this
pawn Код:
PlayerInfo[playerid][pReward] = 0;//christmas enum
Sadly I'm not so good at explaining enums, Y_INI etc.. but this will ensure that it's set to 0 before logging in(Useful for /stats commands..)
Now, at "OnPlayerDisconnect", at INI_WriteInt, add this:
pawn Код:
INI_WriteInt(File,"Reward",PlayerInfo[playerid][pReward]);//christmas enum
This will save the Reward, for an example - If the player has found a Christmas tree, it will be saved as "1", but if he hasn't, it will be saved as "0".


Next up, on "OnDialogResponse" @ your REGISTER case, add this:
pawn Код:
//other INI_WriteInt stuff.
                    INI_WriteInt(File,"Reward",0);
                   //Possibly INI_Close ...
This will write/add this line, also setting his "pReward" to 0..

At LoadUser_data, add this line:
pawn Код:
//Other INI_Int stuff here
    INI_Int("Reward",PlayerInfo[playerid][pReward]);//Christmas enum
    //return 1;
This will happen when the player logins (LoadUser..), if it detects(reads) that his Reward is "1", it will set it to 1, but if it detects(reads) that his Reward is "0", it will set it to 0.

Now, here's a big part.
pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
//christmas enum
    if(PlayerInfo[playerid][pReward] == 0)
    {
        new mrand = random(150);
        new pname[MAX_PLAYER_NAME];
        GetPlayerName(playerid,pname,sizeof(pname));
        new string[114];
        SetPlayerScore(playerid, GetPlayerScore(playerid) +mrand);
        format(string, sizeof(string), "* %s[%d] has found a Christmas tree!", pname, playerid);
        SendClientMessageToAll(COLOR_GREEN, string);
        format(string, sizeof(string), "* As a reward, %s gets %i score!",pname, mrand);
        SendClientMessageToAll(COLOR_GREEN, string);
        DisablePlayerCheckpoint(playerid);
        PlayerInfo[playerid][pReward] = 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "* You've already received your gift!");
        DisablePlayerCheckpoint(playerid);
    }
    return 1;
}

Alright, let me try to explain it all to you.
pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
//christmas enum
    if(PlayerInfo[playerid][pReward] == 0)
    {
When a player enter the checkpoint, and if he has NOT found a Christmas tree yet.
pawn Код:
new mrand = random(150); //Random score, from 0 to 150
        new pname[MAX_PLAYER_NAME];//Gets player name
        GetPlayerName(playerid,pname,sizeof(pname));//^
        new string[114];//string for message
        SetPlayerScore(playerid, GetPlayerScore(playerid) +mrand);//Adds the mrand(Random score) to the player
        format(string, sizeof(string), "* %s[%d] has found a Christmas tree!", pname, playerid);//formats a message that will be sent to everyone
        SendClientMessageToAll(COLOR_GREEN, string);
        format(string, sizeof(string), "* As a reward, %s gets %i score!",pname, mrand);//formats a message that will be sent to everyone
        SendClientMessageToAll(COLOR_GREEN, string);//For an example - As a reward, ChristmasTree[0] gets 51score!
        DisablePlayerCheckpoint(playerid);//Disabled players checkpoint
        PlayerInfo[playerid][pReward] = 1;//Sets his enum to 1, meaning that he HAS found a christmas tree
}
* new mrand = random(150); Will give out random amount of score, from 0 to 150.
NOTE: If you want the random score amount to be bigger, change it from "= random(150)" to "= random(300)", now 300 will be the max score a player can receive from that Checkpoint.

* new pname[MAX_PLAYER_NAME]; We will need this for the %s(player name)
* GetPlayerName(playerid,pname,sizeof(pname)); Actually gets the player name..

* new string[114]; String, for formating..

* SetPlayerScore(playerid, GetPlayerScore(playerid) +mrand); Adds the mrand(Random score) to the player.

* format(string, sizeof(string), "* %s[%d] has found a Christmas tree!", pname, playerid); formats a message that will be sent to everyone
* SendClientMessageToAll(COLOR_GREEN, string); Sends the message that was formatted above
* format(string, sizeof(string), "* As a reward, %s gets %i score!",pname, mrand); formats another message that will be sent to everyone
* SendClientMessageToAll(COLOR_GREEN, string); Sends the message that was formatted above.

* DisablePlayerCheckpoint(playerid); Disabled players checkpoint
* PlayerInfo[playerid][pReward] = 1; Sets his enum to 1, meaning that he HAS found a christmas

But, if his enum(PlayerInfo[playerid][pReward]) is == 1, then this will happen:

pawn Код:
else //If his enum(pReward) is == 1
    {
        SendClientMessage(playerid, COLOR_RED, "* You've already received your gift!"); //This message is shown
        DisablePlayerCheckpoint(playerid); //Disables his checkpoint
    }
    return 1;
}
* else If his enum(pReward) == 1, meaning that he has found a christmas tree
* SendClientMessage(playerid, COLOR_RED, "* You've already received your gift!"); He will receive this message.
* DisablePlayerCheckpoint(playerid); The checkpoint will be disabled for him..

Now, "OnPlayerUpdate" you will add this, so the player can actually see the Checkpoint!

pawn Код:
//OnPlayerUpdate
//Christmas stuff
    if(IsPlayerInRangeOfPoint(playerid, 25.0, -945.2987,-2350.4517,59.6948))
    {
        if(PlayerInfo[playerid][pReward] == 0)
        {
            SetPlayerCheckpoint(playerid, -945.2987,-2350.4517,59.6948, 2.5);
        }
    }
    else if(IsPlayerInRangeOfPoint(playerid, 25.0, -2187.0222,-1852.4990,221.1656))
    {
        if(PlayerInfo[playerid][pReward] == 0)
        {
            SetPlayerCheckpoint(playerid, -2187.0222,-1852.4990,221.1656, 2.5);
        }
    }
    return 1;
}
* if(IsPlayerInRangeOfPoint(playerid, 25.0, -945.2987,-2350.4517,59.6948)) If the player is at range of 25m of the location -945.2987,-2350.4517,59.6948.

* if(PlayerInfo[playerid][pReward] == 0) If he has NOT found a christmas tree

* SetPlayerCheckpoint(playerid, -945.2987,-2350.4517,59.6948, 2.5); An checkpoint will show for him, at the location -945.2987,-2350.4517,59.6948, with the size of 2.5



* else if(IsPlayerInRangeOfPoint(playerid, 25.0, -2187.0222,-1852.4990,221.1656)) But, if the player has found another checkpoint(While he is closer than 25m away from the location -2187.0222,-1852.4990,221.1656)

* if(PlayerInfo[playerid][pReward] == 0 And if he hasn't found the christmas tree at Mt. Chilliad

* SetPlayerCheckpoint(playerid, -2187.0222,-1852.4990,221.1656, 2.5); An checkpoint will show for him, at the location -2187.0222,-1852.4990,221.1656, with the size 2.5

NOTE #1 - If the player HAS found a Christmas tree( pReward == 1 ), the checkpoint will NOT show for him!
NOTE #2 - You can change the coordinates, by replacing "-2187.0222,-1852.4990,221.1656" etc... with any position you like(/save in-game probably :p), but you will need to move the mapped objects too..




Extra info for people who have the command 'stats'

pawn Код:
if(PlayerInfo[id][pReward] == 1)//if he has found a christmas tree
    {
    format(string, sizeof(string), "                 |   ..:: %s[%d] has found a Christmas-tree! ::...   |", targetid, id);
    SendClientMessage(playerid, COLOR_PINK, string); //it will send him the message that is formatted above
    }
    else
    {
    if(PlayerInfo[id][pReward] == 0)//If he hasn't found a christmas tree.
    format(string, sizeof(string), "                |   ..:: %s[%d] hasn't found a Christmas-tree! ::...   |", targetid, id);
    SendClientMessage(playerid, COLOR_PINK, string);//it will send him the message formatted above.
    }
    return 1;
}

I hope that i explained everything, cause i was kinda sleepy while i wrote this..

[ame]http://www.youtube.com/watch?v=XA9WUQV9VzY[/ame]
Reply
#2

EXCELLENT! +REP!
Reply
#3

Well scripted and useful. Thanks for releasing it.

IT SUCKS
Reply
#4

Nicely scripted.
Reply
#5

Quote:
Originally Posted by Kyance
Посмотреть сообщение
Sadly I'm not so good at explaining enums, Y_INI etc..
Sadly, yeah. Or do you know what they are?


Quote:
Originally Posted by Kyance
Посмотреть сообщение
At LoadUser_data, add this line:
Whats LoadUser_data?

You didn't mention anywhere that you are required to have a register system on your script before starting this.

Anyways I don't want to ruin your christmas mood, but you should consider editing the script so it wont use the register system that someone has already made, or atleast link the register script here.

Anyways, I like the idea, as its under christmas.


EDIT: Correct me if I'm wrong, so I can apologize.
Reply
#6

Nice Tutorial
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)