#It's only possible via extensions (dll)

1 messages · Page 1 of 1 (latest)

valid pond
#

Oki, how would I be able to do that? I'm very new to all of this.

surreal geode
#

Do you know C# or C++?

valid pond
#

I know C++ yes

valid pond
surreal geode
#

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

valid pond
# surreal geode To make extensions. You can either make an extension yourself or use an existing...

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.

valid pond
# surreal geode To make extensions. You can either make an extension yourself or use an existing...
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;
};
surreal geode
#

Do you have to use web for this btw? Can't you embed it in the mission or something?

valid pond
#

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.

surreal geode
valid pond
surreal geode
#

Sorry I'm logging off but maybe tomorrow if I remember

valid pond
#

Goodnight!

surreal geode
valid pond
#

Will do

valid pond
#

nvm!

valid pond
# surreal geode Be sure to read its wiki page
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"]]]

valid pond
valid pond
surreal geode
valid pond
# surreal geode 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)

surreal geode
#

select command

#

e.g. _response#1 select [1]

valid pond
#

_rank = (_response select 1) select 0 select 1;?

surreal geode
#

Will return ["Sergeant", "Major"]

valid pond
#

Ah okay

#

so if I use _rank = _response#1 select [1] it will give me Sergeant Major?

surreal geode
#

If you want the first rank it's _response#1#1 the second one (if it exists) is _response#1#2

valid pond
#

it's just one rank though

#

[""object"",[[""rank"",""Sergeant Major""]]]

surreal geode
#

Oh I misread

valid pond
#

okay there's always only one in there so hopefully this will do the trick.

surreal geode
valid pond
#

_rank = _response#1#1;

#

like so

surreal geode
#

Yes

valid pond
#

Okay:)

#

I'll give that a try.

surreal geode
#

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)

valid pond
#

yeah alrighty

#

thanks:)

#

gonna test some stuff out now and will most likely be back haha

surreal geode
surreal geode
valid pond
#

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
surreal geode
#

Maybe it's returning a hashmap?
How old is the extension?

#

I thought it's old so it probably doesn't use hashmap

valid pond
surreal geode
#

Print its typename too typeName _response

valid pond
#

How would I? Very new to sqf.

#

oki

#

ty

#

will do a restart in a sec

surreal geode
#

Print it in diag like other stuff

valid pond
#

ye

valid pond
#

strange

#
 6:30:24 "[RankSystem] API response: [""object"",[[""rank"",""Sergeant Major""]]]"
 6:30:24 "[RankSystem] Response type: STRING"
#

its a string

surreal geode
#

Then you have to parse it first

#

parseSimpleArray _response#1#0#1

valid pond
#

private _parsedResult = parseSimpleArray _response#1#0#1;

#

like that?

surreal geode
#

That's the rank

valid pond
#

oh

#

so that will take the string and turn it into the rank then?

surreal geode
#

It takes the string, converts it to array, then gets the rank out of the array

valid pond
#

ye

#

alrighty

#

Will give it another go.

surreal geode
valid pond
#
 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];
surreal geode
#

So I guess all good then?

valid pond
#

I think so yup.

#

Just gotta find a way to have an icon appear above the head now.

surreal geode
#

drawIcon3D

#

Every frame

valid pond
surreal geode
#

It's probably best to ask your questions in #arma3_scripting now (unless it is about what we've talked about so far)

valid pond
#

It is!

valid pond
# surreal geode It's probably best to ask your questions in <#105462984087728128> now (unless it...

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>
surreal geode
#

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

valid pond
# surreal geode Why do I get a feeling that this is ChatGPT generated?!

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"],
];
valid pond
# surreal geode And also when you're trying to fetch the icon from the map, you should call the ...

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."
surreal geode
#

RankIcon is a bool as the error says

valid pond
#

huh

#

that's strange

#

ye the errors are very unclear to me

valid pond
#

how's that a bool

surreal geode
#

Post the entire code

valid pond
#
// 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;
};
surreal geode
#

Maybe it means something else then

#

One of those true false at the end of the array should be a string

#

Check the wiki

valid pond
#

am doing

#

one moment

surreal geode
#

Also this won't work

valid pond
valid pond
surreal geode
valid pond
valid pond
# surreal geode ^
} 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.

surreal geode
#

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

valid pond
#

Last thing I'll ask you.

valid pond
#

Would I have to make it into an addon?

surreal geode
valid pond
surreal geode
valid pond
surreal geode
valid pond