Jump to content

Photo
- - - - -

Very quick help with random numbers needed


  • Please log in to reply
8 replies to this topic

#1 hamis

hamis

    Master Gunnery Sergeant

  • Members
  • 1015 posts

Posted 23 June 2009 - 04:36 PM

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.

#2 -)rStrangelove

-)rStrangelove

    Sergeant Major

  • Members
  • 1760 posts

Posted 25 June 2009 - 01:03 PM

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

#3 hamis

hamis

    Master Gunnery Sergeant

  • Members
  • 1015 posts

Posted 26 June 2009 - 02:37 PM

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

#4 modEmMaik

modEmMaik

    Gunnery Sergeant

  • Members
  • 433 posts

Posted 26 June 2009 - 05:53 PM

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.

#5 hamis

hamis

    Master Gunnery Sergeant

  • Members
  • 1015 posts

Posted 26 June 2009 - 06:27 PM

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

#6 modEmMaik

modEmMaik

    Gunnery Sergeant

  • Members
  • 433 posts

Posted 30 June 2009 - 02:04 PM

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 :)

#7 hamis

hamis

    Master Gunnery Sergeant

  • Members
  • 1015 posts

Posted 30 June 2009 - 06:19 PM

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;
};



#8 modEmMaik

modEmMaik

    Gunnery Sergeant

  • Members
  • 433 posts

Posted 01 July 2009 - 10:10 AM

Good try :)

This way, I am able to give it a try to fix the bugs. ;)

I have tried to improve your code: http://pastebin.com/m1feef1b0

BR,
mike

#9 hamis

hamis

    Master Gunnery Sergeant

  • Members
  • 1015 posts

Posted 01 July 2009 - 04:34 PM

Very big THANK YOU,mike!:D