Jump to content
Sign in to follow this  
jeppelykke

Var and random  not working :(

Recommended Posts

Hey Hey,

Am working on a random spawns on my DM map, how ever i seems to run into a problem that my "random 10" do not work, what am doing wrong, this is my entire script.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#start

westspawn = random 10

eastspawn = random 10

? westspawn == 1 : "respawn_west" setMarkerPos getMarkerPos "respawn1"

? westspawn == 2 : "respawn_west" setMarkerPos getMarkerPos "respawn2"

? westspawn == 3 : "respawn_west" setMarkerPos getMarkerPos "respawn3"

? westspawn == 4 : "respawn_west" setMarkerPos getMarkerPos "respawn4"

? westspawn == 5 : "respawn_west" setMarkerPos getMarkerPos "respawn5"

? westspawn == 6 : "respawn_west" setMarkerPos getMarkerPos "respawn6"

? westspawn == 7 : "respawn_west" setMarkerPos getMarkerPos "respawn7"

? westspawn == 8 : "respawn_west" setMarkerPos getMarkerPos "respawn8"

? westspawn == 9 : "respawn_west" setMarkerPos getMarkerPos "respawn9"

? westspawn == 10 : "respawn_west" setMarkerPos getMarkerPos "respawn10"

? eastspawn == 1 : "respawn_east" setMarkerPos getMarkerPos "respawn1"

? eastspawn == 2 : "respawn_east" setMarkerPos getMarkerPos "respawn2"

? eastspawn == 3 : "respawn_east" setMarkerPos getMarkerPos "respawn3"

? eastspawn == 4 : "respawn_east" setMarkerPos getMarkerPos "respawn4"

? eastspawn == 5 : "respawn_east" setMarkerPos getMarkerPos "respawn5"

? eastspawn == 6 : "respawn_east" setMarkerPos getMarkerPos "respawn6"

? eastspawn == 7 : "respawn_east" setMarkerPos getMarkerPos "respawn7"

? eastspawn == 8 : "respawn_east" setMarkerPos getMarkerPos "respawn8"

? eastspawn == 9 : "respawn_east" setMarkerPos getMarkerPos "respawn9"

? eastspawn == 10 : "respawn_east" setMarkerPos getMarkerPos "respawn10"

~10

goto "start"

Yes, I have markers named spawn 1 to 10, and respawn markers also made. How ever i tryed even replaceing the marker setpos with:

? westspawn == 1 : hint "1"

? westspawn == 2 : hint "2"

ect..... But they don't work,

So what am doing wrong  sad_o.gif

Best Regards

Jeppe Lykke, Denmark

Share this post


Link to post
Share on other sites

random 10 gives you any float value between 0 and 10. It will be a one in a million shot that it will ever be exactly 1 or 2 or 3 etc.

You could do with <= or >= and have Goto statements at the end of each ?().

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#start

westspawn = random 10

eastspawn = random 10

westspawn=westspawn-(westspawn%1)

eastspawn=eastspawn-(eastspawn%1)

_w=format["respawn%1",westspawn]

_e=format["respawn%1",eastspawn]

"respawn_west" setMarkerPos getMarkerPos _w

"respawn_east" setMarkerPos getMarkerPos _e

~10

goto "start"

But there can be both respawns at the same place in the same time.  rock.gif

Share this post


Link to post
Share on other sites

or

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

respawns=["respawn1","respawn2","respawn3","respawn4","respawn5","respawn6","respawn7","respawn8","respawn9","respawn10"];

#start

westspawn = random 10

eastspawn = random 10

"respawn_west" setMarkerPos getMarkerPos (respawns select (westspawn - 0.5))

"respawn_east" setMarkerPos getMarkerPos (respawns select (eastspawn - 0.5))

~10

goto "start"

Share this post


Link to post
Share on other sites

Why not use the mod command?

So do'er like this:

_wholeInteger = _number mod 1

Then you will have a whole integer to work with, I.E 1, 2, 3, 4...

edit

To make it easier for you:

_wholeIntegerWestSpawn = westspawn mod 1

Share this post


Link to post
Share on other sites
Why not use the mod command?

So do'er like this:

_wholeInteger = _number mod 1

Then you will have a whole integer to work with, I.E 1, 2, 3, 4...

edit

To make it easier for you:

_wholeIntegerWestSpawn = westspawn mod 1

0.999 mod 1 = 0.999

1.5 mod 1 = 0.5

9.25 mod 1 = 0.25

10 mod 1 = 0

Share this post


Link to post
Share on other sites

Have you tested that in OFP?

Because # mod 1 has worked for me in the past...

Share this post


Link to post
Share on other sites

just replace == in every line with <= and your script will work.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

? westspawn <= 1 : "respawn_west" setMarkerPos getMarkerPos "respawn1"

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_num = random 20

_rest = _num mod 1

_num = _num - _rest

that's what u need...

Share this post


Link to post
Share on other sites

I think the lesson from this thread is there are numerous ways to solve this problem, and this member has probably solved his a long time ago. wink_o.gif

Share this post


Link to post
Share on other sites

maybe...

but with my version he can use his old script. smile_o.gif

Share this post


Link to post
Share on other sites
Have you tested that in OFP?

Because # mod 1 has worked for me in the past...

Yes, I tested it in OFP.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

a mod b

Operand types:

   a: Number

   b: Number

Type of returned value:

   Number

Description:

   remainder of a divided by b. Note remainer is calculated in real domain.

Example:

   3 mod 2 , result is 1

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  

×