The online racing simulator
#1 - sun
A Simple KM bonus System
hey,

I'm still wondering how to give a bonus when a certain kiloMeter has been driven. I'm willing to give you my code below.
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]
if (100 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 19155;
}
if (200 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 29000;
}
if (300 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 30000;
}
if (400 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 40000;
}
if (500 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 50000;
}
if (600 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 60000;
}
if (700 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 70000;
}
if (800 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 80000;
}
if (900 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 90000;
}
if (1000 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 100000;
}
[/COLOR][/SIZE][/COLOR][/SIZE]

The only problem with this is that, it keeps on giving you money constantly, every second. I really dont know whats wrong.

Can anyone help me?
Quote from sun :hey,

I'm still wondering how to give a bonus when a certain kiloMeter has been driven. I'm willing to give you my code below.
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]
if (100 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 19155;
}
if (200 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 29000;
}
if (300 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 30000;
}
if (400 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 40000;
}
if (500 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 50000;
}
if (600 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 60000;
}
if (700 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 70000;
}
if (800 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 80000;
}
if (900 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 90000;
}
if (1000 < Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000)
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 100000;
}
[/COLOR][/SIZE][/COLOR][/SIZE]

The only problem with this is that, it keeps on giving you money constantly, every second. I really dont know whats wrong.

Can anyone help me?

it keeps on giving you money all the time because 100 < totaldistance means if there distance is bigger than 100 do that action so everytime it checks there distance its gunna just do that first action which is 100 < Totaldistance because its got no maximum Value you should do if totaldistance > 100 & totaldistance < 199.. etc that should work
#3 - sun
Ah, thanks i'll give it a try
Quote from Robbo01 :because its got no maximum Value you should do if totaldistance > 100 & totaldistance < 199.. etc that should work

Your reasoning is correct but your solution wrong. Yours will still give cash "every second" while in the smaller range.

One solution is to have a cash_award_level integer that you increment whenever cash is awarded. Then by checking this, you could come up with some logic to only award each cash bonus once. You could go further and use this integer to index into distance and cash award arrays, to save all the repeat code. At the very least, you'll need to reverse the order of the checks and use some else statements.
... I'm sorry... wouldn't "==" be a better operator.. cuz you want someone once they are at that distance... to have a 1 time bonus or am I on drugs?
In theory, but I'm assuming distance driven is floating point and would increment by irregular values, so chances are it would skip over an equal comparison.
I don't understand that programming language but couldnt you do something like this...


If Distance is between X and Y
Counter = 0
Do Untill the counter = 1
Award Bonus
Counter = Counter + 1
Loop
Else If Distance is Between Z and A
Counter = 0
Do Untill the counter = 1
Award Bonus
Counter = Counter + 1
Loop

..... And So on....
#8 - sun
Wait a minute... When I use the code, It gives me 1000 when its on 100km. and if i'm correct, it will stop at 199km. so if there was a way to only give 100 out once, Then i think it would work.
do what dawesdust_12 said then use if total distance == 100
#10 - sun
So you mean something like this

[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000] (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000 == 100)[/COLOR]
{
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 19155;
}
[/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE]


yes try it
#12 - sun
nope it still goes up.
#14 - sun
The Money. seems its in an infinite loop.
If currentmiles > milestone
and if milestonecompleted !=true
reward, and set that milestone as done.

Don't forget to clear the milestone done, if they leave the track.
#16 - sun
Quote from Krammeh :and set that milestone as done.

Don't forget to clear the milestone done, if they leave the track.

Thats the kind of part I get stuck on. On my Job command, When someone types in the command to get a job, it turns a variable to true. then where the bank is I've set it so when the user goes to the bank ( part of the job ) it will give them cash. and it sets jobs = false; But it still keeps on giving them money.

Now after alot of thinking I had 2 options. One just using a new variable for example...

].KmBonus = 1);

Or i could just use what rob said. But edited.

if (totaldistance > 100 & totaldistance < 100)
{
//award bonus
}

I think i've done something like this in my later applications, when it gets to 100, it gives cash, but it cant give anymore because its supposed to stop at 100 to.

i'm not sure if I'm thinking on the right line. But I'm 67& sure that it may work.
Just a sample code from my system:

if (Player.DroveKM.Session == 10)
{
Send.Player.Cash += 500;
Reset = Player.DroveKM.Session;
}

if (Player.DroveKM.Session == 30)
{
Send.Player.Cash += 1000;
Reset = Player.DroveKM.Session;
}

if (Player.DroveKM.Ses......

Hope i can help you

Regarts Heiko1
-
(JasonJ) DELETED by JasonJ
I might just mess with the code, get it working and post it. Not that I would use it as since when do race servers have cash?
This might be a dumb idea, but you could just keep track of what the TotalDistance was last time you checked.

if (player.TotalDistance >= 100 && player.LastTotalDistance < 100)
{
player.Cash += 19155;
}
else if (player.TotalDistance >= 200 && player.LastTotalDistance < 200)
{
player.Cash += 29000;
}

player.LastTotalDistance = player.TotalDistance;

you could make it like this

if (player.leftpitkm >= 10000)
{
player.Cash += 100;
InSim.Send_MST_Message("player.PlayerName + " ^7recieved ^2$100^7 for driving 10km.");
}
if (player.leftpitkm >= 20000)
{
player.Cash += 200;
InSim.Send_MST_Message("player.PlayerName + " ^7recieved ^2$200^7 for driving 20km.");
}

and so on hope this helps as i havent tried it.
@Azzano62

That won't help because it will just evaluate (player.leftpitkm >= 10000) as TRUE, every loop through after they player passes 10000(meters?)

This is the problem that SUN (OP) has in the firstplace.
yes stupid me i didnt think when i wrote it up ill make one that works then and post it later
hi i have tried to do this also with this code
but it still spams the money

int onehundredkmreached = 0;
int onehundredkmreachedbefore = 0;
int km = Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].TotalDistance / 1000;
if (onehundredkmreachedbefore == 0 && km == 100)
{
onehundredkmreached = 1;
if (onehundredkmreached == 1)
{
onehundredkmreached = 0;
onehundredkmreachedbefore = 1;
Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Cash += 19155;
}
}

been a few years since ive coded so sorry if there is a stupid error
hm.... The Km bonus Counters doesnt work on my insim ????

can any 1 help me ?
#25 - KuHS
Here you go my code, simple and working. It's in my updatecheck void:

if ((C.InitialBonus) >= 100) // 100 is the proc, so you can have bars and lines with this
{
C.OLap += 20;
C.OBonus += 2000;
C.InitialBonus = 0;
InSim.Send_MTC_MessageToConnection("^3You've got " + (C.OBonus) + "$ a bonus for " + (C.OLap) + " laps on the track", (C.UniqueID), 0);
C.Cash += (C.OBonus);

if ((C.BDistance) >= 1760) // At 1,76 km you will get +1 bonus proc, you can change it
{
C.BDistance -= 1760;
C.InitialBonus += 1;
}

Conn.BDistance += Convert.ToInt32(SpeedMS); // And dont forget this
}

1

FGED GREDG RDFGDR GSFDG