Amnesiaplayer
Senior Member
Posts: 539
Threads: 105
Joined: Jun 2014
Reputation:
0
|
RE: RandInt ?!
(07-07-2015, 08:29 PM)Daemian Wrote: Having: Area1, Area2, Area3... 5:
int n = RandInt(1,5); TeleportPlayer( "Area"+n );
That basic idea can be applied to similar situations like you mention.
Note: To teleport the player, the area must be a StartLocation type.
Or use SetPlayerPos
Thanks!
But what I meant was the parts, not the players haha
There are 3 parts, and each part, have 2 locations. meaning that there are 6 locations, 2 of each part.
Basically what I meant was Part 1 on the first 2 locations, and part 2, on third and fourth location, and part 3, on the last 2 locations
int n = RandInt(1,5);
is 1,5 50%??
|
|
07-08-2015, 09:14 PM |
|
Rahmerh
Member
Posts: 66
Threads: 7
Joined: Jun 2015
Reputation:
3
|
RE: RandInt ?!
no that means it takes a number from 1-5. That means 1, 2, 3, 4 or 5.
|
|
07-08-2015, 09:16 PM |
|
DnALANGE
Banned
Posts: 1,549
Threads: 73
Joined: Jan 2012
|
RE: RandInt ?!
That would be 20%
1 of 5 (100% \ 5 = 20% eatch )
int n = RandInt(1,3); = 33% change
These are examples how it works.
|
|
07-08-2015, 09:17 PM |
|
Amnesiaplayer
Senior Member
Posts: 539
Threads: 105
Joined: Jun 2014
Reputation:
0
|
RE: RandInt ?!
Oh, so 50% is 1.2 ?!
Sorry if this was wrong xD
Btw, Thanks
Do I need that in my void (Function) sentence?!?!
Like
Void SpawnPart1_1(blablabla);
{
RandIntetcetc
SetEntityAcyive("Part1" etcetc...
}
If so, How am I supposed to do, what I want to happen, because then I need 2 func, and for that it may be possible that both parts spawn at both locations... what Is not what I want..
|
|
07-08-2015, 09:42 PM |
|
Romulator
Not Tech Support ;-)
Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation:
195
|
RE: RandInt ?!
Name all your ScriptAreas where the parts could potentially spawn Area_ followed by 1 to 6 (Area_1, Area_2, Area_3 ... Area_6).
Then try this:
void OnStart() { CreateEntityAtArea("<name_of_part_1>", "entity.ent", "Area_"+RandInt(1, 2), false); CreateEntityAtArea("<name_of_part_2>", "entity.ent", "Area_"+RandInt(3, 4), false); CreateEntityAtArea("<name_of_part_3>", "entity.ent", "Area_"+RandInt(5, 6), false); }
However:
1. Don't have your parts already placed in the level. This will create them. If you have two doors both called "door" in game, the game crashes because it does not know which door is which. Make sure to rename the first string to suit your code as well.
2. "entity.ent" should be changed to whatever the entity is that your part will be using.
If the game crashes with an "Expected ;" error, place it after the RandInt() but before the comma in each routine. I keep forgetting if it is required when calling it within a line itself.
Furthermore, a simple way to test if all is working, is to move the ScriptAreas in front of where the player spawns. Note where each part drops and make sure that every now and then (since it's a 1/2 * 1/2 * 1/2) they alter. Then you can move your ScriptAreas around.
Discord: Romulator#0001
(This post was last modified: 07-08-2015, 10:34 PM by Romulator.)
|
|
07-08-2015, 10:25 PM |
|
Amnesiaplayer
Senior Member
Posts: 539
Threads: 105
Joined: Jun 2014
Reputation:
0
|
RE: RandInt ?!
(07-08-2015, 10:25 PM)Romulator Wrote: Name all your ScriptAreas where the parts could potentially spawn Area_ followed by 1 to 6 (Area_1, Area_2, Area_3 ... Area_6).
Then try this:
void OnStart() { CreateEntityAtArea("<name_of_part_1>", "entity.ent", "Area_"+RandInt(1, 2), false); CreateEntityAtArea("<name_of_part_2>", "entity.ent", "Area_"+RandInt(3, 4), false); CreateEntityAtArea("<name_of_part_3>", "entity.ent", "Area_"+RandInt(5, 6), false); }
However:
1. Don't have your parts already placed in the level. This will create them. If you have two doors both called "door" in game, the game crashes because it does not know which door is which. Make sure to rename the first string to suit your code as well.
2. "entity.ent" should be changed to whatever the entity is that your part will be using.
If the game crashes with an "Expected ;" error, place it after the RandInt() but before the comma in each routine. I keep forgetting if it is required when calling it within a line itself.
Thanks!!
Only, 1 thing looks strange.
"Area_"+RandInt(1, 2), false);
what do you exactly mean by (1, 2)
The first thing I thought was the area 1,2
But where is it stated that it is going to spawn on one of those palce "50%"
CreateEntityAtArea("<name_of_part_1>", "entity.ent", "Area_"+RandInt(1, 2), false);
if I look to this script, It creates "entity.ent" (what basically is, a part I am going to use)
on the Area_ (basically 1, or 2. +Randint (1, 2) <Will that tell the script to spawn OR 1, or 2?!
So or it is going to spawn area_1 or area_2
So does that state the 50%?!
Thanks
(07-08-2015, 10:25 PM)Romulator Wrote: Name all your ScriptAreas where the parts could potentially spawn Area_ followed by 1 to 6 (Area_1, Area_2, Area_3 ... Area_6).
Then try this:
void OnStart() { CreateEntityAtArea("<name_of_part_1>", "entity.ent", "Area_"+RandInt(1, 2), false); CreateEntityAtArea("<name_of_part_2>", "entity.ent", "Area_"+RandInt(3, 4), false); CreateEntityAtArea("<name_of_part_3>", "entity.ent", "Area_"+RandInt(5, 6), false); }
However:
1. Don't have your parts already placed in the level. This will create them. If you have two doors both called "door" in game, the game crashes because it does not know which door is which. Make sure to rename the first string to suit your code as well.
2. "entity.ent" should be changed to whatever the entity is that your part will be using.
If the game crashes with an "Expected ;" error, place it after the RandInt() but before the comma in each routine. I keep forgetting if it is required when calling it within a line itself.
Thanks!!
Only, 1 thing looks strange.
"Area_"+RandInt(1, 2), false);
what do you exactly mean by (1, 2)
The first thing I thought was the area 1,2
But where is it stated that it is going to spawn on one of those palce "50%"
CreateEntityAtArea("<name_of_part_1>", "entity.ent", "Area_"+RandInt(1, 2), false);
if I look to this script, It creates "entity.ent" (what basically is, a part I am going to use)
on the Area_ (basically 1, or 2. +Randint (1, 2) <Will that tell the script to spawn OR 1, or 2?!
So or it is going to spawn area_1 or area_2
So does that state the 50%?!
Thanks
(This post was last modified: 07-08-2015, 10:33 PM by Amnesiaplayer.)
|
|
07-08-2015, 10:33 PM |
|
Romulator
Not Tech Support ;-)
Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation:
195
|
RE: RandInt ?!
RandInt(1, 2) chooses a random number between 1 and 2.
Since it is an Int, it can only be 1 or 2.
Therefore, it is 50% of being 1, and 50% of being 2.
The same thing happens to (3, 4) and (5, 6).
Think of it like this. You flip a coin. It can be either heads, or tails.
Since there is no other possible outcome (unless it lands on its side o.0), its a 50/50 chance of being either heads or tails.
The three RandInt's are doing the same thing. A coin flip.
Discord: Romulator#0001
|
|
07-08-2015, 10:39 PM |
|
Amnesiaplayer
Senior Member
Posts: 539
Threads: 105
Joined: Jun 2014
Reputation:
0
|
RE: RandInt ?!
(07-08-2015, 10:39 PM)Romulator Wrote: RandInt(1, 2) chooses a random number between 1 and 2.
Since it is an Int, it can only be 1 or 2.
Therefore, it is 50% of being 1, and 50% of being 2.
The same thing happens to (3, 4) and (5, 6).
Think of it like this. You flip a coin. It can be either heads, or tails.
Since there is no other possible outcome (unless it lands on its side o.0), its a 50/50 chance of being either heads or tails.
The three RandInt's are doing the same thing. A coin flip.
k Thanks
|
|
07-08-2015, 10:44 PM |
|
Mudbill
Muderator
Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation:
179
|
RE: RandInt ?!
If you want a 50% chance of something, this should do:
if(RandInt(0, 100) < 50) { //do something }
The "50" can be changed to any percentage you want. If you need decimal percentages, you must use RandFloat instead.
|
|
07-09-2015, 12:54 PM |
|
|