achievement_send_challenge(playerid, challengeid, score, type, message)
Argument | Description |
---|---|
playerid | The unique ID of the player to challenge. |
challengeid | The unique challenge ID (as found on the provider dashboard). |
score | The score to beat. |
type | the type of challenge to be issued - one of two constants given below. |
message | The message to attach to the challenge. |
Returns: N/A
This function will send a challenge across the network to the chosen player. You can get the playerid using the achievement_load_friends or the achievement_load_leaderboard functions and you must also supply the challengeid which is the unique value given the challenge when you created it on your iTunes Connect or Google Play dashboard. You must also supply a score, and a short text message as well as set the challenge type. This can be one of the following constants:
- achievement_type_score_challenge - A challenge based on the score value.
- achievement_type_achievement_challenge - A challenge based on an achievement.
This function will trigger a callback
Social Asynchronous Event for the player that is to receive the
challenge, and in this event you will have a ds_map referenced in
the variable async_load. The id key of this
ds_map is used to identify the correct callback (there can
be more than one trigger function for any given asynchronous
event), and will be paired with the constant
achievement_challenge_received as well as a number of
other key/value pairs for each player. The exact contents of the
map are shown below:
NOTE: that the user can also receive toast notifications
for challenges received, but this will depend on the values you
have chosen using the function achievement_show_challenge_notifications.
- "id" - For this function it should be achievement_leaderboard_info
- "playerid" - The player ID for the challenge.
- "issuerid" - The issuer ID for the challenge.
- "state" - The state of the challenge, which will have a value of 0 - 3 (as a string) for invalid, pending, completed or declined.
- "message" - The text message for challenge.
- "completeddate" - The completion date for challenge.
- "issueddate" - The issue date for challenge.
- "type" - The type of challenge given. Can be one of two constants:
- achievement_type_score_challenge - A challenge based on the score value.
- achievement_type_achievement_challenge - A challenge based on an achievement.
- "identifier" - The identifying string for the challenge, as set on the provider dashboard
- "score" - The score tied in with the challenge (if applicable).
To send a challenge over the network you would have this code:
achievement_send_challenge(global.playerid[0], global.challengeid[0], score, achievement_type_score_challenge, "Beat that sucker!");
This request will then trigger the Social Event in your game for the player that the challenge was directed at, and this can be dealt with in the following way:
var ident = ds_map_find_value(async_load,
"id");
if ident == achievement_challenge_received
{
player_id = ds_map_find_value(async_load,
"playerid");
issuer_id = ds_map_find_value(async_load,
"issuerid");
state = ds_map_find_value(async_load,
"state");
message = ds_map_find_value(async_load,
"message");
date_completed = ds_map_find_value(async_load,
"completeddate");
date_issued = ds_map_find_value(async_load,
"issueddate");
ach_type = ds_map_find_value(async_load,
"type");
ach_ident = ds_map_find_value(async_load,
"identifier");
ach_score = ds_map_find_value(async_load,
"score");
}
The above code checks the returned ds_map in the Social Asynchronous Event and if its "id" matches the constant being checked, it then extracts the relevant values for each of the keys in the map and stores them in variables for future use.