• How to get a player country ?
Ex:
How to make this code in Rust Plugin?Code://Covalence Plugin string country = JsonConvert.DeserializeObject<Response>(response).Country; SendReply(player, "The player country is "+ country +"!");
Solved Getting a player's country?
Discussion in 'Rust Development' started by Daat, Apr 8, 2018.
-
Wulf Community Admin
I'd suggest taking a look at the CountryBlock plugin of mine if you're looking for a more complete example.
The example you posted is actually for a Rust plugin technically, you'd just need to add it to a command (see Docs or existing plugins). -
Ok, thanks Wulf
[DOUBLEPOST=1523153202][/DOUBLEPOST]I have, if anyone else is in doubt, it is easy to solve.
First add a using-statement:
-
Code:using Newtonsoft.Json;
Then create a class with JsonProperty:
-
Code:private class Response { [JsonProperty("country")] public string Country { get; set; } }
Then add this in your void:
-
Code:string apiUrl = "http://ip-api.com/json/"; webrequest.EnqueueGet(apiUrl + player.displayName, (code, response) => { if (code != 200 || response == null) { Puts($"WebRequests to {apiUrl} failed!"); return; } string country = JsonConvert.DeserializeObject<Response>(response).Country; }, this);
And that's it, use it to your advantage.Last edited by a moderator: Apr 8, 2018 -