mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #3971 from acemod/dogtags-player-ssn
Generate SSN of unit from their name
This commit is contained in:
commit
3fa17580c4
@ -9,4 +9,5 @@ PREP(getDogtagData);
|
||||
PREP(getDogtagItem);
|
||||
PREP(sendDogtagData);
|
||||
PREP(showDogtag);
|
||||
PREP(ssn);
|
||||
PREP(takeDogtag);
|
||||
|
@ -23,9 +23,7 @@ private _targetName = [_target, false, true] call EFUNC(common,getName);
|
||||
|
||||
private _dogTagData = [
|
||||
_targetName,
|
||||
str(floor random 10) + str(floor random 10) + str(floor random 10) + "-" +
|
||||
str(floor random 10) + str(floor random 10) + "-" +
|
||||
str(floor random 10) + str(floor random 10) + str(floor random 10),
|
||||
_targetName call FUNC(ssn),
|
||||
_targetName call FUNC(bloodType)
|
||||
];
|
||||
// Store it
|
||||
|
31
addons/dogtags/functions/fnc_ssn.sqf
Normal file
31
addons/dogtags/functions/fnc_ssn.sqf
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Author: SilentSpike
|
||||
* Reports a social security number generated from the units name.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Name of a unit <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* A random three/two/four format social security number <STRING>
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_name"];
|
||||
private _length = count _name;
|
||||
private _chars = toArray _name;
|
||||
|
||||
// For short names, reuse characters
|
||||
if (_length < 9) then {
|
||||
// Iterates every second character, swapping odd/even with each loop
|
||||
for [{_i = 0},{_i < 2*(9 - _length)},{_i = _i + 2}] do {
|
||||
_chars pushBack (_chars select floor((_i + (_i/_length % 2)) % _length));
|
||||
};
|
||||
};
|
||||
|
||||
// Offset array slice for long names to make generation more unique
|
||||
private _slice = [0, _length % 9] select (_length > 9);
|
||||
private _nums = (_chars select [_slice, 9]) apply { _x % 10 };
|
||||
|
||||
([_nums select [0,3],_nums select [3,2], _nums select [5,4]] apply { _x joinString "" }) joinString "-"
|
Loading…
Reference in New Issue
Block a user