|
Post by GH Games on Jan 30, 2017 14:58:08 GMT
Open world just got an upgrade! - I say this because this script can make an OW game pretty cool. Especially one like GTA.Hey everyone. I'm feeling as good as new and back on my feet, so to kick off my being back I have created/modified a Script (originally by Famer) that allows you to give a car fuel and have the player pay for more when it's all gone. I have made a video on it because I don't want to hurt your eyes by making you read loads and loads of instructions on what to change and how. (Download link below video). For those advanced with Scripting you can add more functions for the player to gain money etc. I'll be doing tutorials on scripting soon for those who don't know how to script yet so you can improve the script and make it do some even cooler things! Side Note: I didn't want to make a completely new thread for this so I'll just add it here, I'm going to be releasing a small Beta for 3DRSA 2.0 soon and I need one or two lovely people to try it out. If your interested leave a comment below and I will PM you the details. Attachments: Fuel with Payment Script.zipLeave feedback and any comments you have below for me Enjoy!
|
|
|
Post by Power Supersport on Jan 30, 2017 16:09:26 GMT
Great tutorial! I have some comments about the script itself... Using iObjectStart / Stop () is a terrible idea in this situation... When you run out of fuel in real life you don't get your steering wheel blocked and your brakes... Like, that would be terrible... iObjectStart / Stop functions aren't meant to be used in a fuel scenario... So, what I suggest using is simply setting acceleration to 0... Another thing that bothers me is how the "gas" key is detected... Using a key input for this is not a good idea at all... Imagine that the car is moving backwards... That can save a ton of fuel if you think a little bit... Better use the acceleration detector (IN_4 - Throttle state)... When the throttle is above 0, then the "gas" key is active... A third thing is why are you using a gas key at all? Fuel in real life goes down all the time when the car's engine is started... A more intelligent way of doing it would be the fuel to go according to the speed of the car... The faster you drive, the more fuel it will take... And also, why do you restrict people of refuelling when the fuel is above 0? You must give them the ability to refuel before getting out of fuel... Of course, all of what I said would be empty if I don't suggest some kind of script... Here's my solution... Please test it out... I didn't do the text messages, but you already do these on your own very well... float fuel = 0; float maxFuel = 100; float dropRate = 0.02; float acceleration = 2; float cash = 300; float cost = 1; void Main () { if (iInitializing ()) { fuel = maxFuel; }
fuel -= IN_0 * dropRate + IN_4 * 0.1;
if (fuel <= 0) { fuel = 0; OUT_4 = 0; } else { OUT_4 = acceleration; }
if (fuel >= maxFuel) fuel = maxFuel;
if (iKeyDown (iKeyCode ("DIK_P"))) { Refill (); }
OUT_22 = fuel; OUT_44 = cash; } void Refill () { float totalCost = (maxFuel - fuel) * cost; // Calculate the cost for refilling if ((fuel < 100) && (cash >= totalCost)) { cash -= totalCost; fuel = maxFuel; } } I hope this suggestion is helpful for further tutorials...
|
|
|
Post by GH Games on Jan 30, 2017 16:30:10 GMT
I know the iObjectStart is bad I just noticed how bad it is sorry about that. It can easily be removed. I also thought of the real life physics part of this when I was making it and thought the same thing's you just said exactly the same in fact. However I thought that for what it is and does it was... okay. Thanks for the feedback Power
|
|
|
Post by Famer on Jan 30, 2017 17:33:04 GMT
This was what I originally designed, but not working...:
//////////Fuel and cost script////////// int [] time(1); float fuel; int maxfuel = 100; float cash; int initialcash = 100;
void Main() { ///Fuel
fuel = maxfuel;
if (iKeyDown(iKeyCode("DIK_UP"))) { ExecutedConsumption; } else if (iKeyDown(iKeyCode("DIK_DOWN"))) { ExecutedConsumption; } else { NormalConsumption; } OUT_22 = fuel; if (fuel =< 0) fuel = 0;
///Fuel
cash = initialcash; cost = (maxfuel - fuel) * 2; if (iKeyDown(iKeyCode("DIK_f"))){ cash -= cost; } if (cash < cost){ fuel += cash / 2; cash = 0; } if (cash = 0) && (fuel = 0){ iObjectStop(OBJ_X); iObjectShow(OBJ_X); }
}
void ExecutedConsumption() {
time[0]; = 0; fuel -= 0.5; }
void NormalConsumption() { time[0] = 0; fuel -= 0.1; }
|
|
|
Post by NicusorN5 on Jan 30, 2017 18:43:58 GMT
When calling a function you should always use these : ();
For example :
float DoNotGiveNullPlzIDontWannaErrors(int n) { if (n != null) return n; if (n == null) return 0; }
//And When calling it :
void Main() //Called every frame { int a; //Defines a variable with no value float b = DoNotGiveNullPlzIDontWannaErrors(a); // b = 0 }
Please do not use this code , it too useless to exist , it's just a example
|
|
|
Post by TinSoldier on Jan 30, 2017 21:51:31 GMT
try this version, i found numerous errors, all should work now, except the OUT_X because it needs a link to whatever OBJ_* to work.
//////////Fuel and cost script////////// int[] time(1); // theres no need to use an array for time if only 1 array is used int maxfuel=100; int iCash = 100;
float fuel=0.0f; float cash=0.0f; float cost=0.0f;
void Main(){
if(iInitializing()){ fuel = maxfuel; //Fuel }
if(iKeyDown(iKeyCode("DIK_UP"))){ ExecutedConsumption(); }else{ if(iKeyDown(iKeyCode("DIK_DOWN"))){ ExecutedConsumption(); }else{ NormalConsumption(); } } OUT_22 = fuel; if(fuel <= 0) fuel = 0;
//Fuel cash = iCash; cost = (maxfuel - fuel) * 2; if(iKeyDown(iKeyCode("DIK_F"))){ cash -= cost; } if(cash < cost){ fuel += cash / 2; cash = 0; } if(cash == 0 && fuel == 0){ //iObjectStop(OBJ_X); //iObjectShow(OBJ_X); } }
void ExecutedConsumption(){ time[0] = 0; fuel -= 0.5; }
void NormalConsumption(){ time[0] = 0; fuel -= 0.1; }
|
|