Merge pull request #3971 from acemod/dogtags-player-ssn

Generate SSN of unit from their name
This commit is contained in:
Nicolás Badano 2016-06-21 20:46:57 -03:00 committed by GitHub
commit 3fa17580c4
3 changed files with 33 additions and 3 deletions

View File

@ -9,4 +9,5 @@ PREP(getDogtagData);
PREP(getDogtagItem); PREP(getDogtagItem);
PREP(sendDogtagData); PREP(sendDogtagData);
PREP(showDogtag); PREP(showDogtag);
PREP(ssn);
PREP(takeDogtag); PREP(takeDogtag);

View File

@ -23,9 +23,7 @@ private _targetName = [_target, false, true] call EFUNC(common,getName);
private _dogTagData = [ private _dogTagData = [
_targetName, _targetName,
str(floor random 10) + str(floor random 10) + str(floor random 10) + "-" + _targetName call FUNC(ssn),
str(floor random 10) + str(floor random 10) + "-" +
str(floor random 10) + str(floor random 10) + str(floor random 10),
_targetName call FUNC(bloodType) _targetName call FUNC(bloodType)
]; ];
// Store it // Store it

View 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 "-"