| Blockland Forums > Modification Help |
| Vehicle Script Assistance |
| (1/4) > >> |
| Midway Sentinel:
Hey, could someone possibly throw together a script for me? If so, I need a function that: When the vehicle is Accelerating over 5mph or so: -check if a variable called "isAccel" is 0. if so: -set it to 1 -mount an image called DMTVJetStreamImage1 and one called DMTVJetStreamImage2 -play a thread called "toFly" and then when below that speed: -check if the variable is 1. if so: -set the variable to 0 -unmount the image called DMTVJetStreamImage1 and the one called DMTVJetStreamImage2 -play a thread called "toIdle" this is probably a lot to ask of people... but i cant get mine to work: --- Code: ---function vehicle::onSpawn(%obj,%velocity) { if(vectorLen(%obj.getVelocity()) > 1) { %obj.mountImage(DMTVJetStreamImage1,0); %obj.mountImage(DMTVJetStreamImage2,1); %obj.playThread(0,"toFly"); return %p; } if(vectorLen(%obj.getVelocity()) < 1) { %obj.unMountImage(DMTVJetStreamImage1,0); %obj.unMountImage(DMTVJetStreamImage2,1); %obj.playThread(0,"toIdle"); return %p; } } --- End code --- I copied various code sections from other add-ons to fill the places i needed, but that's probably why it didn't work :P i didn't even have the variable in the script, but that's my crappy scripting knowledge for you. |
| Headcrab Zombie:
The biggest problem is that you're only checking it once when the vehicle is created. A few other smaller problems: Using vehicle::onSpawn will affect every vehicle. In the script below, change <YourVehicleDatablockName> to, well, you vehicle datablock name You have a check for > 1, and a check for < 1, with no check for exactly one. I changed it to >= 1 and < 1. This is not an issue here as the velocity is extremely unlikely to be exactly 1 for any noticable amount of time, but just keep it in mind for future scripts. Untested: --- Code: ---function <YourVehicleDatablockName>::onSpawn(%this) { %this.checkVelocity(); } function <YourVehicleDatablockName>::checkVelocity(%this) { cancel(%this.checkVelocitySchedule); if(!isthisect(%this)) return; if(vectorLen(%this.getVelocity()) >= 1 && !%this.isFly) { %this.mountImage(DMTVJetStreamImage1,0); %this.mountImage(DMTVJetStreamImage2,1); %this.playThread(0,"toFly"); %this.isFly = 1; } if(vectorLen(%this.getVelocity()) < 1 && %this.isFly) { %this.unMountImage(DMTVJetStreamImage1,0); %this.unMountImage(DMTVJetStreamImage2,1); %this.playThread(0,"toIdle"); %this.isFly = 0; } %this.checkVelocitySchedule = %this.schedule(100,checkVelocity); } --- End code --- I'm unsure if those are the correct arguments for onSpawn as I couldn't find any source. I also changed a few things to match my own coding style. Also, get in the habit of proper indenting. It makes code a lot easier to read. |
| Midway Sentinel:
thanks man. once again i owe you one :) -edit: it unfortunately didn't work ingame, although from the looks of it it should have. do you think if i sent you the whole of the script that it would help? |
| Headcrab Zombie:
Trying add %obj.checkVelocity() to the onAdd function, and remove the onSpawn function |
| Midway Sentinel:
thanks, ill try it straight away! |
| Navigation |
| Message Index |
| Next page |