jens198 0 Posted July 24, 2005 Hi, got this little script that drives me nuts! I simply want to create a car by random. Right now nothing hapens. Can anyone help me? Thanks ! Jens <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_r = random 5 ~1 ? _r = 5 : goto "bluecar" ~0.1 ? _r = 4 : goto "greencar" ~0.1 ? _r = 3 : goto "redcar" ~0.1 ? _r = 2 : goto "truck_c" ~0.1 ? _r = 1 : goto "Car" exit #bluecar pos = getMarkerPos "vehicle_origin_1" bluecar = "SkodaBlue" createvehicle pos bluecar setdir 90 exit #greencar pos = getMarkerPos "vehicle_origin_1" greencar = "SkodaGreen" createvehicle pos greencar setdir 90 exit #redcar pos = getMarkerPos "vehicle_origin_1" redcar = "SkodaRed" createvehicle pos redcar setdir 90 exit #truck_c pos = getMarkerPos "vehicle_origin_1" truck_c = "TruckV3SCivil" createvehicle pos truck_c setdir 90 exit #Car pos = getMarkerPos "vehicle_origin_1" car = "Skoda" createvehicle pos car setdir 90 exit Share this post Link to post Share on other sites
Arne 0 Posted July 24, 2005 getMarkerPos gives you a 2D position, but you need a 3D position. Try making a [x,y,z] like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> my2DPosition = getMarkerPos "whatever" my3DPosition = [my2DPosition select 0, my2DPosition select 1, 0] I confess that I don't know if that's the problem! Share this post Link to post Share on other sites
j-man 0 Posted July 24, 2005 It's probably the way you check the variable "_r" at the begining of the script. Try something like this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _r = random 5 ~1 ?( _r <= 5) && (_r > 4) : goto "bluecar" ~0.1 ?( _r <= 4) && (_r > 3) : goto "greencar" ~0.1 ? (_r <= 3) && (_r > 2) : goto "redcar" ~0.1 ? (_r <= 2) && (_r > 1) : goto "truck_c" ~0.1 ?( _r <= 1) && (_r > 0) : goto "Car" exit Share this post Link to post Share on other sites
crashdome 3 Posted July 24, 2005 j-man's right... a random number is between 0 and n.. so 'Random 5' could be 3.23442 you could use j-mans script or simply add: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _r = (_r+0.5) - ((_r+0.5) % 1) after the first line. This will round the number up if above x.5 or round down if x.499999 Share this post Link to post Share on other sites
RED 0 Posted July 25, 2005 Also you syntax is incorrect here: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ? _r = 5 : goto "bluecar" ~0.1 ? _r = 4 : goto "greencar" ~0.1 ? _r = 3 : goto "redcar" ~0.1 ? _r = 2 : goto "truck_c" ~0.1 ? _r = 1 : goto "Car" <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ? _r == 5 : goto "bluecar" ~0.1 ? _r == 4 : goto "greencar" ~0.1 ? _r == 3 : goto "redcar" ~0.1 ? _r == 2 : goto "truck_c" ~0.1 ? _r == 1 : goto "Car" RED Share this post Link to post Share on other sites
jens198 0 Posted July 25, 2005 Thanks a lot guys. Got it working with j-man's soulution. Jens Share this post Link to post Share on other sites