Jump to content
Sign in to follow this  
hamis

Very quick help with random numbers needed

Recommended Posts

Well,i need very quick help in this:

sleep 1;
if (isNil 'CSLA_noRandomNumbers') then {CSLA_noRandomNumbers = false};
if !CSLA_noRandomNumbers then {
_vehiculum = _this;
_via       = '\csla_opn\data\cisla_white_armour\'; if (_vehiculum isKindOf 'AIR') then {_via = '\csla_opn\data\cisla_black_big\'};

_posX      = 1; if (abs((getPos _vehiculum) select 0) > 1) then {_posX = abs((getPos _vehiculum) select 0)};
_posY      = 1; if (abs((getPos _vehiculum) select 1) > 1) then {_posY = abs((getPos _vehiculum) select 1)};
_posZ      = 1; if (abs((getPosASL _vehiculum) select 2) > 1) then {_posZ = abs((getPosASL _vehiculum) select 2)};

_numero    = floor(_posX*_posY*_posZ);
_numero    = toArray(str(_numero MOD 10000));
_numero0   = '0'; if (count(_numero) > 3) then {_numero0 = toString[_numero select 3]};
_numero1   = '0'; if (count(_numero) > 2) then {_numero1 = toString[_numero select 2]};
_numero2   = '0'; if (count(_numero) > 1) then {_numero2 = toString[_numero select 1]};
_numero3   = '0'; if (count(_numero) > 0) then {_numero3 = toString[_numero select 0]};

_vehiculum setObjectTexture [0, _via + _numero0 + '.paa'];
_vehiculum setObjectTexture [1, _via + _numero1 + '.paa'];
_vehiculum setObjectTexture [2, _via + _numero2 + '.paa'];
if (_vehiculum isKindOf 'AIR') then {_vehiculum setObjectTexture [3, _via + _numero3 + '.paa']} else {_vehiculum setObjectTexture [3, _via + 'sign.paa']};
};

; Number Randomizer

_unit = _this select 0

?norandomnumbers: Exit

_unit setObjectTexture [3, "\csla_apc\signs\sign.paa"], goto "n1"


#n1
_nrand = random(100)
?_nrand > 90: _unit setObjectTexture [0, "\csla_apc\signs\9.paa"], goto "n2"
?_nrand > 80: _unit setObjectTexture [0, "\csla_apc\signs\8.paa"], goto "n2"
?_nrand > 70: _unit setObjectTexture [0, "\csla_apc\signs\7.paa"], goto "n2"
?_nrand > 60: _unit setObjectTexture [0, "\csla_apc\signs\6.paa"], goto "n2"
?_nrand > 50: _unit setObjectTexture [0, "\csla_apc\signs\5.paa"], goto "n2"
?_nrand > 40: _unit setObjectTexture [0, "\csla_apc\signs\4.paa"], goto "n2"
?_nrand > 30: _unit setObjectTexture [0, "\csla_apc\signs\3.paa"], goto "n2"
?_nrand > 20: _unit setObjectTexture [0, "\csla_apc\signs\2.paa"], goto "n2"
?_nrand > 10: _unit setObjectTexture [0, "\csla_apc\signs\1.paa"], goto "n2"
?_nrand > 0: _unit setObjectTexture [0, "\csla_apc\signs\0.paa"], goto "n2"

#n2
_nrand = random(100)
?_nrand > 90: _unit setObjectTexture [1, "\csla_apc\signs\9.paa"], goto "n3"
?_nrand > 80: _unit setObjectTexture [1, "\csla_apc\signs\8.paa"], goto "n3"
?_nrand > 70: _unit setObjectTexture [1, "\csla_apc\signs\7.paa"], goto "n3"
?_nrand > 60: _unit setObjectTexture [1, "\csla_apc\signs\6.paa"], goto "n3"
?_nrand > 50: _unit setObjectTexture [1, "\csla_apc\signs\5.paa"], goto "n3"
?_nrand > 40: _unit setObjectTexture [1, "\csla_apc\signs\4.paa"], goto "n3"
?_nrand > 30: _unit setObjectTexture [1, "\csla_apc\signs\3.paa"], goto "n3"
?_nrand > 20: _unit setObjectTexture [1, "\csla_apc\signs\2.paa"], goto "n3"
?_nrand > 10: _unit setObjectTexture [1, "\csla_apc\signs\1.paa"], goto "n3"
?_nrand > 0: _unit setObjectTexture [1, "\csla_apc\signs\0.paa"], goto "n3"

#n3
_nrand = random(100)
?_nrand > 90: _unit setObjectTexture [2, "\csla_apc\signs\9.paa"], Exit
?_nrand > 80: _unit setObjectTexture [2, "\csla_apc\signs\8.paa"], Exit
?_nrand > 70: _unit setObjectTexture [2, "\csla_apc\signs\7.paa"], Exit
?_nrand > 60: _unit setObjectTexture [2, "\csla_apc\signs\6.paa"], Exit
?_nrand > 50: _unit setObjectTexture [2, "\csla_apc\signs\5.paa"], Exit
?_nrand > 40: _unit setObjectTexture [2, "\csla_apc\signs\4.paa"], Exit
?_nrand > 30: _unit setObjectTexture [2, "\csla_apc\signs\3.paa"], Exit
?_nrand > 20: _unit setObjectTexture [2, "\csla_apc\signs\2.paa"], Exit
?_nrand > 10: _unit setObjectTexture [2, "\csla_apc\signs\1.paa"], Exit
?_nrand > 0: _unit setObjectTexture [2, "\csla_apc\signs\0.paa"], Exit

I need to get these to have functionality(mostly "mytime" i think) from this:

private ["_tex", "_number", "_nr", "_mytime"];
// e.g.: init="test=[this, 123] execVM ""\smurfc_era\assignNumber.sqf"";";
_tex = _this select 0;
_number = _this select 1;

if (_number < 0) then
{
_number=(((getpos _tex select 0)+(getpos _tex select 1)*3+(time-(time Mod 5))*17)Mod 1000)-1;
};

// set _mytime to zero to assign the texture once
_mytime=0;

while {true} do {
sleep 0.1;
waitUntil {time != 0};

// if load, time is reset
if (_mytime < 2) then
{

_nr = (_number / 100) Mod 10;
_nr = _nr - (_nr Mod 1);
switch (format ["%1", _nr]) do
{
case "0": { _tex setObjectTexture [3,"\smurfc_era\numbers\zero"];};
case "1": { _tex setObjectTexture [3,"\smurfc_era\numbers\one"];};
case "2": { _tex setObjectTexture [3,"\smurfc_era\numbers\two"];};
case "3": { _tex setObjectTexture [3,"\smurfc_era\numbers\three"];};
case "4": { _tex setObjectTexture [3,"\smurfc_era\numbers\four"];};
case "5": { _tex setObjectTexture [3,"\smurfc_era\numbers\five"];};
case "6": { _tex setObjectTexture [3,"\smurfc_era\numbers\six"];};
case "7": { _tex setObjectTexture [3,"\smurfc_era\numbers\seven"];};
case "8": { _tex setObjectTexture [3,"\smurfc_era\numbers\eight"];};
default { _tex setObjectTexture [3,"\smurfc_era\numbers\nine"];};
};

_nr = (_number / 10) Mod 10;
_nr = _nr - (_nr Mod 1);
switch (format ["%1", _nr]) do
{
case "0": { _tex setObjectTexture [4,"\smurfc_era\numbers\zero"];};
case "1": { _tex setObjectTexture [4,"\smurfc_era\numbers\one"];};
case "2": { _tex setObjectTexture [4,"\smurfc_era\numbers\two"];};
case "3": { _tex setObjectTexture [4,"\smurfc_era\numbers\three"];};
case "4": { _tex setObjectTexture [4,"\smurfc_era\numbers\four"];};
case "5": { _tex setObjectTexture [4,"\smurfc_era\numbers\five"];};
case "6": { _tex setObjectTexture [4,"\smurfc_era\numbers\six"];};
case "7": { _tex setObjectTexture [4,"\smurfc_era\numbers\seven"];};
case "8": { _tex setObjectTexture [4,"\smurfc_era\numbers\eight"];};
default { _tex setObjectTexture [4,"\smurfc_era\numbers\nine"];};
};

_nr = (_number) Mod 10;
_nr = _nr - (_nr Mod 1);
switch (format ["%1", _nr]) do
{
case "0": { _tex setObjectTexture [5,"\smurfc_era\numbers\zero"];};
case "1": { _tex setObjectTexture [5,"\smurfc_era\numbers\one"];};
case "2": { _tex setObjectTexture [5,"\smurfc_era\numbers\two"];};
case "3": { _tex setObjectTexture [5,"\smurfc_era\numbers\three"];};
case "4": { _tex setObjectTexture [5,"\smurfc_era\numbers\four"];};
case "5": { _tex setObjectTexture [5,"\smurfc_era\numbers\five"];};
case "6": { _tex setObjectTexture [5,"\smurfc_era\numbers\six"];};
case "7": { _tex setObjectTexture [5,"\smurfc_era\numbers\seven"];};
case "8": { _tex setObjectTexture [5,"\smurfc_era\numbers\eight"];};
default { _tex setObjectTexture [5,"\smurfc_era\numbers\nine"];};
};
};

_mytime=time;
sleep 1;
};

I hope this time someone will even try to help.

Share this post


Link to post
Share on other sites

It might be a good idea to tell us what your problem is exactly. Any error messages? You want a new feature?

Share this post


Link to post
Share on other sites

The problem is that with first(two part) script random numbering is lost if you load saved game,with third one it doesn't.

Share this post


Link to post
Share on other sites

The only trick included is to move the random number generation outside an endless loop. When a mission reload is performed, the variable time is reset to zero. You have to reapply the textures when you have detected a reset. So, to make it reload secure, I have chosen to make it this way:

// Generate all random numbers you need here


// set _mytime to zero to assign the texture once
_mytime=0;

while {true} do {
sleep 0.1;
waitUntil {time != 0};

// if load, time is reset
if (_mytime < 2) then
{

// Apply the textures here by using the ramdom numbers generated outside the endless loop
};

_mytime=time;
sleep 1;
};

I use the variable _mytime to detect, when the time is reset @ load.

btw.: I think that the correct comparison should be "_mytime < 1", but have not tested this fully, yet.

Share this post


Link to post
Share on other sites

Hi mike,long time no see!Could you convert it to me,i'm absolutely hopeless with scripting?

Share this post


Link to post
Share on other sites
Hi mike,long time no see!Could you convert it to me,i'm absolutely hopeless with scripting?

It is not that hard to do... please give it a try ;)

Because... I am still pretty occupied with other tasks and after some hours of coding/modelling, I perfer someting else to do :)

Share this post


Link to post
Share on other sites

Well,i tried this but got error 7 and ctd:

// Generate all random numbers you need here
if (isNil 'CSLA_noRandomNumbers') then {CSLA_noRandomNumbers = false};
if !CSLA_noRandomNumbers then {
_vehiculum = _this;
_posX      = 1; if (abs((getPos _vehiculum) select 0) > 1) then {_posX = abs((getPos _vehiculum) select 0)};
_posY      = 1; if (abs((getPos _vehiculum) select 1) > 1) then {_posY = abs((getPos _vehiculum) select 1)};
_posZ      = 1; if (abs((getPosASL _vehiculum) select 2) > 1) then {_posZ = abs((getPosASL _vehiculum) select 2)};

_numero    = floor(_posX*_posY*_posZ);
_numero    = toArray(str(_numero MOD 10000));
_numero0   = '0'; if (count(_numero) > 3) then {_numero0 = toString[_numero select 3]};
_numero1   = '0'; if (count(_numero) > 2) then {_numero1 = toString[_numero select 2]};
_numero2   = '0'; if (count(_numero) > 1) then {_numero2 = toString[_numero select 1]};
_numero3   = '0'; if (count(_numero) > 0) then {_numero3 = toString[_numero select 0]};

_vehiculum setObjectTexture [0, _via + _numero0 + '.paa'];
_vehiculum setObjectTexture [1, _via + _numero1 + '.paa'];
_vehiculum setObjectTexture [2, _via + _numero2 + '.paa'];

// set _mytime to zero to assign the texture once
_mytime=0;

while {true} do {
sleep 0.1;
waitUntil {time != 0};

// if load, time is reset
if (_mytime < 2) then
{

// Apply the textures here by using the ramdom numbers generated outside the endless loop
_unit = _this select 0

?norandomnumbers: Exit

_unit setObjectTexture [3, "\csla_apc\signs\sign.paa"], goto "n1"


#n1
_nrand = random(100)
?_nrand > 90: _unit setObjectTexture [0, "\csla_apc\signs\9.paa"], goto "n2"
?_nrand > 80: _unit setObjectTexture [0, "\csla_apc\signs\8.paa"], goto "n2"
?_nrand > 70: _unit setObjectTexture [0, "\csla_apc\signs\7.paa"], goto "n2"
?_nrand > 60: _unit setObjectTexture [0, "\csla_apc\signs\6.paa"], goto "n2"
?_nrand > 50: _unit setObjectTexture [0, "\csla_apc\signs\5.paa"], goto "n2"
?_nrand > 40: _unit setObjectTexture [0, "\csla_apc\signs\4.paa"], goto "n2"
?_nrand > 30: _unit setObjectTexture [0, "\csla_apc\signs\3.paa"], goto "n2"
?_nrand > 20: _unit setObjectTexture [0, "\csla_apc\signs\2.paa"], goto "n2"
?_nrand > 10: _unit setObjectTexture [0, "\csla_apc\signs\1.paa"], goto "n2"
?_nrand > 0: _unit setObjectTexture [0, "\csla_apc\signs\0.paa"], goto "n2"

#n2
_nrand = random(100)
?_nrand > 90: _unit setObjectTexture [1, "\csla_apc\signs\9.paa"], goto "n3"
?_nrand > 80: _unit setObjectTexture [1, "\csla_apc\signs\8.paa"], goto "n3"
?_nrand > 70: _unit setObjectTexture [1, "\csla_apc\signs\7.paa"], goto "n3"
?_nrand > 60: _unit setObjectTexture [1, "\csla_apc\signs\6.paa"], goto "n3"
?_nrand > 50: _unit setObjectTexture [1, "\csla_apc\signs\5.paa"], goto "n3"
?_nrand > 40: _unit setObjectTexture [1, "\csla_apc\signs\4.paa"], goto "n3"
?_nrand > 30: _unit setObjectTexture [1, "\csla_apc\signs\3.paa"], goto "n3"
?_nrand > 20: _unit setObjectTexture [1, "\csla_apc\signs\2.paa"], goto "n3"
?_nrand > 10: _unit setObjectTexture [1, "\csla_apc\signs\1.paa"], goto "n3"
?_nrand > 0: _unit setObjectTexture [1, "\csla_apc\signs\0.paa"], goto "n3"

#n3
_nrand = random(100)
?_nrand > 90: _unit setObjectTexture [2, "\csla_apc\signs\9.paa"], Exit
?_nrand > 80: _unit setObjectTexture [2, "\csla_apc\signs\8.paa"], Exit
?_nrand > 70: _unit setObjectTexture [2, "\csla_apc\signs\7.paa"], Exit
?_nrand > 60: _unit setObjectTexture [2, "\csla_apc\signs\6.paa"], Exit
?_nrand > 50: _unit setObjectTexture [2, "\csla_apc\signs\5.paa"], Exit
?_nrand > 40: _unit setObjectTexture [2, "\csla_apc\signs\4.paa"], Exit
?_nrand > 30: _unit setObjectTexture [2, "\csla_apc\signs\3.paa"], Exit
?_nrand > 20: _unit setObjectTexture [2, "\csla_apc\signs\2.paa"], Exit
?_nrand > 10: _unit setObjectTexture [2, "\csla_apc\signs\1.paa"], Exit
?_nrand > 0: _unit setObjectTexture [2, "\csla_apc\signs\0.paa"], Exit

};

_mytime=time;
sleep 1;
};

Share this post


Link to post
Share on other sites

Very big THANK YOU,mike!:D

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×