#It's only possible via extensions (dll)
1 messages · Page 1 of 1 (latest)
Do you know C# or C++?
I know C++ yes
Why?
To make extensions. You can either make an extension yourself or use an existing one
iirc there was one for this purpose. Let me search
Alrighty, I'll tell you a bit of what I've done so far so you can get a better grasp of it.
Going to url "http://<hidden>:3000/get-rank/steamid" will give you this:
{"rank":"Sergeant Major"}
Now what I want to do is have init.sqf retrieve their (a player who joined) rank based on their steamid. I've already written the stuff for retrieving the steamid in game and that works. But retrieving their rank does not.
diag_log "[RankSystem] init.sqf is running.";
// url
private _apiBaseUrl = "http://95.179.239.176:3000/get-rank/";
// start player check loop
while {true} do {
diag_log "[RankSystem] Entered the player check loop."; // Confirm loop entry
{
private _unit = _x;
if (isPlayer _unit) then {
diag_log format ["[RankSystem] Found player: %1", _unit]; // check if there are players
// get player SteamID
private _steamID = getPlayerUID _unit;
diag_log format ["[RankSystem] Player SteamID: %1", _steamID]; // log the player's SteamID
// construct url
private _url = _apiBaseUrl + _steamID;
diag_log format ["[RankSystem] API URL: %1", _url]; // log URL being called
// display name + steamid
private _playerName = name _unit;
systemChat format ["Player: %1, Rank: %2", _playerName, _stemaID]; // test chat message
};
} forEach allPlayers;
// sleep for 10 seconds before running again
diag_log "[RankSystem] Sleeping for 10 seconds.";
sleep 10;
};
Do you have to use web for this btw? Can't you embed it in the mission or something?
Well that's the thing, the "api" I made retrieves data from a Google Spreadsheet.
So I'd have to find a way to have the data embed automatically into the mission for every change, which wouldn't be viable I believe.
Here's one I found but this isn't the one I was looking for. Still it's something to get you started:
https://github.com/playnet-public/ArmA3URLFetch
I'll look into it, if you do find the one you were looking for lmk!
Sorry I'm logging off but maybe tomorrow if I remember
Yeah all good! Hope the URLFetch you sent works out:)
Goodnight!
Be sure to read its wiki page
Will do
diag_log "[RankSystem] init.sqf is running.";
// url
private _apiBaseUrl = "http://95.179.239.176:3000/get-rank/";
// start player check loop
while {true} do {
diag_log "[RankSystem] Entered the player check loop."; // Confirm loop entry
{
private _unit = _x;
if (isPlayer _unit) then {
diag_log format ["[RankSystem] Found player: %1", _unit]; // check if there are players
// get player SteamID
private _steamID = getPlayerUID _unit;
diag_log format ["[RankSystem] Player SteamID: %1", _steamID]; // log the player's SteamID
// construct url
private _url = _apiBaseUrl + _steamID;
diag_log format ["[RankSystem] API URL: %1", _url]; // log the API URL being called
// test
private _response = [
_url, // The complete URL
"GET", // The HTTP method
[], // No additional parameters needed
true // Decode JSON response
] call a3uf_common_fnc_request;
// display name + steamid
private _playerName = name _unit;
systemChat format ["Player: %1, Rank: %2", _playerName, _response]; // test chat message
};
} forEach allPlayers;
// sleep for 10 seconds before running again
diag_log "[RankSystem] Sleeping for 10 seconds.";
sleep 10;
};
This is my code and every 10 seconds it correctly types out the rank in chat.
Now I want to be able to get the rank out of the result which is just causing issues for me for whatever reason.
This is the result ["object",[["rank","Private"]]]
Without making any changes to my current code it just decided to stop working:))))))
Lmk when you're back, got some stuff to ask ya!
It seems that it's working then
Rank is just _response#1#1
It broke somehow, I changed it and it outputs this now:
5:20:25 "[RankSystem] Entered the player check loop."
5:20:25 "[RankSystem] Found player: Zues1"
5:20:25 "[RankSystem] Player SteamID: 76561198106610356"
5:20:25 "[RankSystem] API URL: http://95.179.239.176:3000/get-rank/76561198106610356"
5:20:25 CallExtension loaded: arma3urlfetch (@ArmA3URLFetch\arma3urlfetch.dll) [0.7.5]
5:20:27 "[RankSystem] API response: [""object"",[[""rank"",""Sergeant Major""]]]"
Is there a way to get the sergeant major out of that result? (rank)
_rank = (_response select 1) select 0 select 1;?
Will return ["Sergeant", "Major"]
No
If you want the first rank it's _response#1#1 the second one (if it exists) is _response#1#2
Yes it will give you as many ranks there are in the array
Oh I misread
okay there's always only one in there so hopefully this will do the trick.
Then just this
Yes
To be safe you can do it like this:
_rank = _response param [1, []] param [1, ""];
In case the response is corrupted or something and it's missing array elements (that would cause your script to stop working)
yeah alrighty
thanks:)
gonna test some stuff out now and will most likely be back haha
Sorry I misread the response
It should be _response#1#0#1
This was correct 
When I run that I get errors though.
5:20:27 "[RankSystem] API response: [""object"",[[""rank"",""Sergeant Major""]]]"
5:20:27 Error in expression <erName = name _unit;
_rank = (_response select 1) select 0 select 1;
diag_log f>
5:20:27 Error position: <select 1) select 0 select 1;
diag_log f>
5:20:27 Error Generic error in expression
Maybe it's returning a hashmap?
How old is the extension?
I thought it's old so it probably doesn't use hashmap
last release was 2019 on github and 2017 on steam
Print its typename too typeName _response
Print it in diag like other stuff
ye
huh
strange
6:30:24 "[RankSystem] API response: [""object"",[[""rank"",""Sergeant Major""]]]"
6:30:24 "[RankSystem] Response type: STRING"
its a string
That's the rank
It takes the string, converts it to array, then gets the rank out of the array
_rank = parseSimpleArray _response param [1, []] param [0, []] param [1, ""];
Is the thing you should use in the end
6:38:48 "[RankSystem] API URL: http://95.179.239.176:3000/get-rank/76561198106610356"
6:38:49 "[RankSystem] API response: [""object"",[[""rank"",""Sergeant Major""]]]"
6:38:49 "[RankSystem] Response type: STRING"
6:38:49 "[RankSystem] Extracted Rank: Sergeant Major"
6:38:49 "[RankSystem] Sleeping for 10 seconds."
^
diag_log format ["[RankSystem] API response: %1", _response]; // response
diag_log format ["[RankSystem] Response type: %1", typeName _response]; // response type
private _rank = parseSimpleArray _response#1#0#1;
private _playerName = name _unit;
diag_log format ["[RankSystem] Extracted Rank: %1", _rank];
So I guess all good then?
You able to help for a min?
It's probably best to ask your questions in #arma3_scripting now (unless it is about what we've talked about so far)
It is!
I'm trying to add a little map to map the icons:
private _rankIconMap = [
["Private", "icons/E2-private-second-class.paa"],
["Private First Class", "icons/E3-private-first-class.paa"],
["Corporal", "icons/E4-corporal.paa"],
["Sergeant", "icons/E5-sergeant.paa"],
["Staff Sergeant", "icons/E6-staff-sergeant.paa"],
["Sergeant First Class", "icons/E7-sergeant-first-class.paa"],
["Master Sergeant", "icons/E8-master-sergeant.paa"],
["First Sergeant", "icons/E8b-first-sergeant.paa"],
["Sergeant Major", "icons/E9-sergeant-major.paa"],
["Command Sergeant Major", "icons/E9b-command-sergeant-major.paa"],
["Second Lieutenant", "icons/O1-second-lieutenant.paa"],
["First Lieutenant", "icons/O2-first-lieutenant.paa"],
["Major", "icons/O4-major.paa"],
["Lieutenant Colonel", "icons/O5-lieutenant-colonel.paa"],
];
This folder is inside the mission folder (pbo file).
Then I'd have a function like this:
private _getIconForRank = {
params ["_rank"];
private _icon = "";
// find matching icon for rank
{
if (_x select 0 == _rank) then {
_icon = _x select 1;
breakOut "forEach";
};
} forEach _rankIconMap;
// default icon
if (_icon == "") then {
_icon = "icons/E2-private-second-class.paa";
};
_icon
};
and I would use that for this part of my main script:
private _response = [
_url,
"GET",
[],
true
] call a3uf_common_fnc_request;
private _rank = "";
if (isNil "_response") then {
diag_log "[RankSystem] Error: No response from API.";
} else {
diag_log format ["[RankSystem] API response: %1", _response]; // response
diag_log format ["[RankSystem] Response type: %1", typeName _response]; // response type
private _rank = parseSimpleArray _response#1#0#1;
private _playerName = name _unit;
diag_log format ["[RankSystem] Extracted Rank: %1", _rank];
// get corresponding icon for player rank
private _rankIcon = _getIconForRank _rank;
diag_log format ["[RankSystem] Rank Icon: %1", _rankIcon];
};
I tried to use this but it did not work!
14:48:25 Error in expression <", "icons/O5-lieutenant-colonel.paa"],
];
private _getIconForRank = {
params >
14:48:25 Error position: <];
private _getIconForRank = {
params >
14:48:25 Error Missing [
14:48:25 File mpmissions\__cur_mp.isladuala3\init.sqf..., line 23
14:48:25 "[RankSystem] init.sqf is running."
14:48:25 Error in expression <00/get-rank/";
private _rankIconMap = [
["Private", "icons/E2-private-second-c>
14:48:25 Error position: <[
["Private", "icons/E2-private-second-c>
Why do I get a feeling that this is ChatGPT generated?!
Anyway, what you have is not a map, it's just an array. You must convert it to a hashmap
And also you have a trailing comma at the end of that array
And also when you're trying to fetch the icon from the map, you should call the function. You've just squished 2 variables together which is a syntax error
You can ditch that function tho. Just use the hashmap directly
Also path separator in SQF is backslash not forward slash
Partly, this is:
private _rankIconMap = [
["Private", "icons/E2-private-second-class.paa"],
["Private First Class", "icons/E3-private-first-class.paa"],
["Corporal", "icons/E4-corporal.paa"],
["Sergeant", "icons/E5-sergeant.paa"],
["Staff Sergeant", "icons/E6-staff-sergeant.paa"],
["Sergeant First Class", "icons/E7-sergeant-first-class.paa"],
["Master Sergeant", "icons/E8-master-sergeant.paa"],
["First Sergeant", "icons/E8b-first-sergeant.paa"],
["Sergeant Major", "icons/E9-sergeant-major.paa"],
["Command Sergeant Major", "icons/E9b-command-sergeant-major.paa"],
["Second Lieutenant", "icons/O1-second-lieutenant.paa"],
["First Lieutenant", "icons/O2-first-lieutenant.paa"],
["Major", "icons/O4-major.paa"],
["Lieutenant Colonel", "icons/O5-lieutenant-colonel.paa"],
];
Looked at the documentation
iconPos = player getPos [10, 0] vectorAdd [0,0,2];
drawIcon3D [
_rankIcon,
[1, 1, 1, 1],
iconPos,
1,
1,
0,
"",
0,
0.03,
"",
true,
false
];
why is that not working?
6:18:25 "[RankSystem] Entered the player check loop."
6:18:25 "[RankSystem] Found player: Zues1"
6:18:25 "[RankSystem] Player SteamID: 76561198106610356"
6:18:25 "[RankSystem] API URL: http://95.179.239.176:3000/get-rank/76561198106610356"
6:18:26 "[RankSystem] API response: [""object"",[[""rank"",""Sergeant Major""]]]"
6:18:26 "[RankSystem] Response type: STRING"
6:18:26 "[RankSystem] Extracted Rank: Sergeant Major"
6:18:26 "[RankSystem] Rank Icon: icons\\E9-sergeant-major.paa"
6:18:26 Error in expression <ayer getPos [10, 0] vectorAdd [0,0,2];
drawIcon3D [
_rankIcon,
[1, 1, 1, 1>
6:18:26 Error position: <drawIcon3D [
_rankIcon,
[1, 1, 1, 1>
6:18:26 Error Type Bool, expected String
6:18:26 File mpmissions\__cur_mp.isladuala3\init.sqf..., line 72
6:18:26 "[RankSystem] Sleeping for 10 seconds."
RankIcon is a bool as the error says
6:18:26 "[RankSystem] Rank Icon: icons\\E9-sergeant-major.paa"
how's that a bool
Post the entire code
// start player check loop
while {true} do {
diag_log "[RankSystem] Entered the player check loop."; // Confirm loop entry
{
private _unit = _x;
if (isPlayer _unit) then {
diag_log format ["[RankSystem] Found player: %1", _unit]; // Check if there are players
// get player SteamID
private _steamID = getPlayerUID _unit;
diag_log format ["[RankSystem] Player SteamID: %1", _steamID]; // steamid
// construct URL
private _url = _apiBaseUrl + _steamID;
diag_log format ["[RankSystem] API URL: %1", _url]; // url
// API request
private _response = [
_url, // The complete URL
"GET", // The HTTP method
[], // No additional parameters needed
true // Decode JSON response
] call a3uf_common_fnc_request;
private _rank = "";
if (isNil "_response") then {
diag_log "[RankSystem] Error: No response from API.";
} else {
diag_log format ["[RankSystem] API response: %1", _response]; // response
diag_log format ["[RankSystem] Response type: %1", typeName _response]; // response type
private _rank = parseSimpleArray _response#1#0#1;
private _playerName = name _unit;
diag_log format ["[RankSystem] Extracted Rank: %1", _rank];
private _rankIcon = _rankIconMap get _rank;
if (isNil "_rankIcon") then {
_rankIcon = "icons\\E2-private-second-class.paa";
};
diag_log format ["[RankSystem] Rank Icon: %1", _rankIcon];
iconPos = player getPos [10, 0] vectorAdd [0,0,2];
drawIcon3D [
_rankIcon,
[1, 1, 1, 1],
iconPos,
1,
1,
0,
"",
0,
0.03,
"",
true,
false
];
};
};
} forEach allPlayers;
// Sleep for 10 seconds before running again
diag_log "[RankSystem] Sleeping for 10 seconds.";
sleep 10;
};
Maybe it means something else then
One of those true false at the end of the array should be a string
Check the wiki
Also this won't work
why?
I removed the true and false and it's no longer giving errors but also doesn't display an icon
^
uhh, what do I change there then?
} else {
diag_log format ["[RankSystem] API response: %1", _response]; // response
diag_log format ["[RankSystem] Response type: %1", typeName _response]; // response type
private _rank = parseSimpleArray _response#1#0#1;
private _playerName = name _unit;
diag_log format ["[RankSystem] Extracted Rank: %1", _rank];
private _rankIcon = _rankIconMap get _rank;
if (isNil "_rankIcon") then {
_rankIcon = "icons\\E2-private-second-class.paa";
};
diag_log format ["[RankSystem] Rank Icon: %1", _rankIcon];
iconPos = player getPos [10, 0] vectorAdd [0,0,2];
addMissionEventHandler ["draw3D",
{
drawIcon3D [
_rankIcon,
[1, 1, 1, 1],
iconPos,
1,
1,
0,
"",
0,
0.03,
""
];
}];
};
Did it like this but it aint showing.
First of all you MUST call this script on the SERVER. If the server is dedicated it won't have a display. If you want the clients to see their ranks you have to send it to them.
Second of all, you should add an event handler only once, not in a loop.
Third of all, event handlers don't see local variables from outer scopes. You either need a global/obj space variable, or use the event handler args
And like I said before, this thread is done. Ask in the main channel now. I won't answer to any other questions here
ye it is called on the server
One final question and then I'll leave you alone please. How would I do this: "If you want the clients to see their ranks you have to send it to them."
Last thing I'll ask you.
Would I have to make it into an addon?
By RemoteExecing a function
Is there anything needed, client-side?
The function that you call plus the event handler thad draws the icons are client side
So that needs to be put on the client's pc right? In form of like an addon.
Like I said no more questions. Ask in #arma3_scripting
You could just answer that one last question ya know. I know you're not entitled to responding but it's genuinely my final question lol