The online racing simulator
Cruise coding!
I need help with some codes in Cruise inSim.

1.So I wanted to get the command that disable all buttons on screen. For example I write !hide and all buttons are hiddden like cash, cars, Kms.

2. How can I make these jobs to go random places? They are all to 1 place only.
case "!job":
if (StrMsg.Length == 1)
{
if (Connections[GetConnIdx(MSO.UCID)].JobToKinderGarten == 1 || Connections[GetConnIdx(MSO.UCID)].JobToFrank == 1 || Connections[GetConnIdx(MSO.UCID)].JobToLarry == 1 || Connections[GetConnIdx(MSO.UCID)].JobToJosh == 1 || Connections[GetConnIdx(MSO.UCID)].JobToPeter == 1)
{
InSim.Send_MTC_MessageToConnection("^1 Vienlaikus tu vari darit tikai vienu darbu!", Connections[GetConnIdx(MSO.UCID)].UniqueID, 0);
}
else if (Connections[GetConnIdx(MSO.UCID)].InShop == 1)
{
int Jobnum = new Random().Next(1, 8);
if (Jobnum == 1 || Jobnum == 5)
{
InSim.Send_MST_Message("/msg ^6> ^1 " + (Connections[GetConnIdx(MSO.UCID)].PlayerName) + " ^6Apstiprina darbu!");
InSim.Send_MTC_MessageToConnection("^6> Nogadat picu uz Simpsonu maju!", Connections[GetConnIdx(MSO.UCID)].UniqueID, 0);
Connections[GetConnIdx(MSO.UCID)].JobToJosh = 1;
}
if (Jobnum == 2 || Jobnum == 6)
{
InSim.Send_MST_Message("/msg ^6> ^1 " + (Connections[GetConnIdx(MSO.UCID)].PlayerName) + " ^6Apstiprina darbu!");
InSim.Send_MTC_MessageToConnection("^6> Nogadat picu uz ^2Autoservisu!", Connections[GetConnIdx(MSO.UCID)].UniqueID, 0);
Connections[GetConnIdx(MSO.UCID)].JobToPeter = 1;
}
if (Jobnum == 3 || Jobnum == 7)
{
InSim.Send_MST_Message("/msg ^6> ^1 " + (Connections[GetConnIdx(MSO.UCID)].PlayerName) + " ^6Apstiprina darbu!");
InSim.Send_MTC_MessageToConnection("^6> Nogadat picu uz KEN BLOCK DRIFT LAUKUMU!!", Connections[GetConnIdx(MSO.UCID)].UniqueID, 0);
Connections[GetConnIdx(MSO.UCID)].JobToFrank = 1;
}
if (Jobnum == 4 || Jobnum == 8)
{
InSim.Send_MST_Message("/msg ^6> ^1 " + (Connections[GetConnIdx(MSO.UCID)].PlayerName) + " ^6Apstiprina darbu!");
InSim.Send_MTC_MessageToConnection("^6> Nogadat picu uz striptiza namu!", Connections[GetConnIdx(MSO.UCID)].UniqueID, 0);
Connections[GetConnIdx(MSO.UCID)].JobToLarry = 1;
}
}
else if (Connections[GetConnIdx(MSO.UCID)].InFrank == 1 || Connections[GetConnIdx(MSO.UCID)].InJosh == 1 || Connections[GetConnIdx(MSO.UCID)].InPeter == 1 || Connections[GetConnIdx(MSO.UCID)].InLarry == 1)
{
InSim.Send_MST_Message("/msg ^6> ^1 " + (Connections[GetConnIdx(MSO.UCID)].PlayerName) + " ^6Apstiprina darbu!");
InSim.Send_MTC_MessageToConnection("^6> Nogadat bernu uz Esential Clubu!", Connections[GetConnIdx(MSO.UCID)].UniqueID, 0);
Connections[GetConnIdx(MSO.UCID)].JobToKinderGarten = 1;
}
}
else
{
InSim.Send_MTC_MessageToConnection("^1Nepareiza komada. Ludzu skaties ^2!help^7 komandu saraksta", MSO.UCID, 0);
}
break;

Waiting for answers
#1

First identify C.HideGUI in ClsConnection or whatever.


if (C.HideGUI == 1)
{
InSim.Send_BTN_CreateButton("", Flags.ButtonStyles.ISB_LIGHT, 6, 27, 184, 2, 0, C.UniqueID, 2, false);
InSim.Send_BTN_CreateButton("^7blah blah: ^2" + C.blah blah/ 800 + "%" + " ^7blah blah: ^2" + C.blah blah + "%", Flags.ButtonStyles.ISB_DARK, 4, 25, 185, 3, 1, C.UniqueID, 2, false);
if (TrackName == "blah blah")
{
InSim.Send_BTN_CreateButton("^0[^7UGC^0]^7UnderGround Event", Flags.ButtonStyles.ISB_C4, 10, 40, 190, 1, 2, C.UniqueID, 2, false);
}
else
{
InSim.Send_BTN_CreateButton("^0[^7UGC^0]^7UnderGround Cruise", Flags.ButtonStyles.ISB_C4, 10, 40, 190, 1, 2, C.UniqueID, 2, false);
}
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 2, C.UniqueID);

}

Im not sure if it works but its just a example.
Quote from edza1188 :

int Jobnum = new Random[COLOR="Red"][B]()[/B][/COLOR].Next(1, 8);



int Jobnum = new Random.Next(1, 8);

This should work... i have no C# Knowledge so... give it a try and let me know?
Quote from mariuba2 :#1

First identify C.HideGUI in ClsConnection or whatever.

Im not sure if it works but its just a example.

I cant get all errors away.
Can you make a code and tell what i need to write in clsConnection? These are buttons i want to hide:
// Car Button

InSim.Send_BTN_CreateButton("" + TempCars1, Flags.ButtonStyles.ISB_DARK, 4, 75, 0, 34, 140, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);

// Cash Button
if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash > 0)
{
InSim.Send_BTN_CreateButton("^7$" + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash, Flags.ButtonStyles.ISB_DARK, 5, 12, 0, 109, 5, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
}
if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash < 0)
{
InSim.Send_BTN_CreateButton("^1$" + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash, Flags.ButtonStyles.ISB_DARK, 5, 12, 0, 109, 5, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
}

// Total Distance Button
InSim.Send_BTN_CreateButton("^7" + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000d + " km", Flags.ButtonStyles.ISB_DARK, 3, 12, 0, 121, 162, (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID), 2, false);


// Distance Bonus Button
InSim.Send_BTN_CreateButton("" + bonusStr, Flags.ButtonStyles.ISB_LIGHT | Flags.ButtonStyles.ISB_LEFT, 2, 25, 1, 141, 18, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
InSim.Send_BTN_CreateButton("" + bonusStr, Flags.ButtonStyles.ISB_LIGHT | Flags.ButtonStyles.ISB_LEFT, 2, 25, 1, 141, 12, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
InSim.Send_BTN_CreateButton("^7Bonus: ", Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_LEFT, 4, 34, 0, 133, 13, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);

Quote from Fire_optikz001 :

int Jobnum = new Random.Next(1, 8);

This should work... i have no C# Knowledge so... give it a try and let me know?

That doesnt work \

if (C.HideGUI == 1)
{
// Car Button
InSim.Send_BTN_CreateButton("" + TempCars1, Flags.ButtonStyles.ISB_DARK, 4, 75, 0, 34, 140, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
// Cash Button
if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash > 0)
{
InSim.Send_BTN_CreateButton("^7$" + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash, Flags.ButtonStyles.ISB_DARK, 5, 12, 0, 109, 5, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
}
if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash < 0)
{
InSim.Send_BTN_CreateButton("^1$" + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash, Flags.ButtonStyles.ISB_DARK, 5, 12, 0, 109, 5, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
}
// Total Distance Button
InSim.Send_BTN_CreateButton("^7" + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000d + " km", Flags.ButtonStyles.ISB_DARK, 3, 12, 0, 121, 162, (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID), 2, false);

// Distance Bonus Button
InSim.Send_BTN_CreateButton("" + bonusStr, Flags.ButtonStyles.ISB_LIGHT | Flags.ButtonStyles.ISB_LEFT, 2, 25, 1, 141, 18, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
InSim.Send_BTN_CreateButton("" + bonusStr, Flags.ButtonStyles.ISB_LIGHT | Flags.ButtonStyles.ISB_LEFT, 2, 25, 1, 141, 12, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
InSim.Send_BTN_CreateButton("^7Bonus: ", Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_LEFT, 4, 34, 0, 133, 13, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
}
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 140, C.UniqueID);
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 5, C.UniqueID);
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 162, C.UniqueID);
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 18, C.UniqueID);
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 12, C.UniqueID);
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 13, C.UniqueID);
}
ClsConnections.cs
public byte HideGUI;

Not sure if it works cause i used notepad to make it, but last thing you need to do is make a command for it to close the buttons
All you do is the see how new Random().next(0, 3) works for you for example


if (Jobnum == 0 || Jobnum == 2)
{
}
if (Jobnum == 1 || Jobnum == 3)
{
}

that means its only randomizing 2 samples of the job
Is there any specific reason why you have two jobnums in each condition? I'd rather do it like this:

jobnum = new Random().Next(0,3);

switch(jobnum)
{
case 0:
something
break;
case 1:
something else
break;
case 2:
something completely different
break;
case 3:
I ran out of vocabulary
break;
}

#8 - PoVo
Quote from MadCatX :Is there any specific reason why you have two jobnums in each condition? I'd rather do it like this:

He wants to make it as random as possible, so he has 1-4 instead of 1-2. Theorically it may make it randomer, but in reality, he should have more jobs (and numbers) to make it random.
If you a have random value from 0 to 3 and each value triggers a different action, probability that a certain action will be triggered is 25%.
If you have a random value from 0 to 7 and each two values trigger a different action, probability that a certain action will be triggered is 25% too
#10 - PoVo
Yes but it's not the probability we are talking about, it's the randomness.
That won't make it more random.

To make it more random, you should not create a new instance of the Random class each time, instead make a single instance and call the Next() each time you need a number. This will reduce the number of collisions in the random number generator.

Thing is though with such a small sample of numbers you will get a lot of collisions naturally. You can simply add some logic to the code to stop it picking the same two random numbers in a row. This will make it appear more random than it is because it won't repeat so much. Here is some badly written example code.

Random random = new Random();
int? lastRandomNumber;

int GetRandomNumber(int min, int max)
{
// Keep picking numbers until we get a new one.
int randomNumber = 0;
do
{
randomNumber = random.Next(min, max);
}
while (randomNumber == (lastRandomNumber ?? -1));

// Store last random for next check.
lastRandomNumber = randomNumber;

return randomNumber;
}

I don't want to hijack this thread, but what's the difference? I mean, if you have a bag with a total of 8 balls and two of these balls are blue, you have a 25% chance of pulling out a blue ball. Now make it just 4 balls with only one blue ball, probability of pulling out a blue ball stays 25%, right?
Of course this is valid only if each ball in the bag has the same probability of being pulled out.
I don't see why would this example not apply in edza's app. If you have a good pseudorandom numbers generator algorithm, it's pretty much safe to assume that the numbers will generate will be spread evenly throughout given range of allowed values.

EDIT: Too slow
Quote from mariuba2 :

if (C.HideGUI == 1)
{
// Car Button
InSim.Send_BTN_CreateButton("" + TempCars1, Flags.ButtonStyles.ISB_DARK, 4, 75, 0, 34, 140, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
// Cash Button
if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash > 0)
{
InSim.Send_BTN_CreateButton("^7$" + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash, Flags.ButtonStyles.ISB_DARK, 5, 12, 0, 109, 5, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
}
if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash < 0)
{
InSim.Send_BTN_CreateButton("^1$" + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash, Flags.ButtonStyles.ISB_DARK, 5, 12, 0, 109, 5, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
}
// Total Distance Button
InSim.Send_BTN_CreateButton("^7" + Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000d + " km", Flags.ButtonStyles.ISB_DARK, 3, 12, 0, 121, 162, (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID), 2, false);

// Distance Bonus Button
InSim.Send_BTN_CreateButton("" + bonusStr, Flags.ButtonStyles.ISB_LIGHT | Flags.ButtonStyles.ISB_LEFT, 2, 25, 1, 141, 18, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
InSim.Send_BTN_CreateButton("" + bonusStr, Flags.ButtonStyles.ISB_LIGHT | Flags.ButtonStyles.ISB_LEFT, 2, 25, 1, 141, 12, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
InSim.Send_BTN_CreateButton("^7Bonus: ", Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_LEFT, 4, 34, 0, 133, 13, Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID, 2, false);
}
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 140, C.UniqueID);
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 5, C.UniqueID);
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 162, C.UniqueID);
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 18, C.UniqueID);
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 12, C.UniqueID);
InSim.Send_BFN_DeleteButton(Enums.BtnFunc.BFN_DEL_BTN, 13, C.UniqueID);
}
ClsConnections.cs
public byte HideGUI;

Not sure if it works cause i used notepad to make it, but last thing you need to do is make a command for it to close the buttons

There are a lot of errors that same lines are not in context and all below that command turned like it all is wrong
Quote from PoVo :Yes but it's not the probability we are talking about, it's the randomness.

Quote from edza1188 :There are a lot of errors that same lines are not in context and all below that command turned like it all is wrong

yea as i said i never tested it i was on rush to go to school.
Quote from edza1188 :There are a lot of errors that same lines are not in context and all below that command turned like it all is wrong

You can't expect that a code you just copy-pasted into your app will work right away. Mariuba gave you a good pointer about using the "InSim.Send_BFN_DeleteButton()" method. Use it to delete all buttons you want to hide. If you want to show them again, you'll have to recreate them.
Quote from MadCatX :You can't expect that a code you just copy-pasted into your app will work right away. Mariuba gave you a good pointer about using the "InSim.Send_BFN_DeleteButton()" method. Use it to delete all buttons you want to hide. If you want to show them again, you'll have to recreate them.

it was just a little example, but nice to see you understand my point =]

Cruise coding!
(18 posts, started )
FGED GREDG RDFGDR GSFDG