Stijger Posted January 14, 2012 Share Posted January 14, 2012 Hey guys, I am really new to the whole scripting thing, but really would like to use it. I got this script where the car in racemode would be undamageable. It works fine when I use the onClientMarkerHit handler, but i don't want that. function resource_starts () local vehicles = getElementsByType ( "vehicle" ) -- get a table of all the Vehicles in the server for theKey,theVehicle in ipairs(vehicles) do -- use a generic for loop to step through each vehicle if ( isVehicleOnGround ( theVehicle ) ) then -- if the vehicle is on the ground, announce it outputChatBox ( getVehicleName ( theVehicle ) .. " is on the ground and made GOD-like" ) setVehicleDamageProof ( theVehicle, true ) else -- if the vehicle isn't on the ground, announce that it is in the air outputChatBox ( getVehicleName ( theVehicle ) .. " is in the air and made GOD-like" ) setVehicleDamageProof ( theVehicle, true ) end end end addEventHandler ( "onClientMarkerHit", getRootElement(), resource_starts ) (sorry for the whole outputchatbox thingy, but just want to be sure the script is working) I would like to have it working at the start of the race. And so it seems cause the outputchatbox thing works, only the setVehicleDamageproof don't. function resource_starts () local vehicles = getElementsByType ( "vehicle" ) -- get a table of all the Vehicles in the server for theKey,theVehicle in ipairs(vehicles) do -- use a generic for loop to step through each vehicle if ( isVehicleOnGround ( theVehicle ) ) then -- if the vehicle is on the ground, announce it outputChatBox ( getVehicleName ( theVehicle ) .. " is on the ground and made GOD-like" ) setVehicleDamageProof ( theVehicle, true ) else -- if the vehicle isn't on the ground, announce that it is in the air outputChatBox ( getVehicleName ( theVehicle ) .. " is in the air and made GOD-like" ) setVehicleDamageProof ( theVehicle, true ) end end end addEventHandler ( "onClientResourceStart", getRootElement(), resource_starts ) and.. addEventHandler('onClientResourceStart', resourceRoot, function() local vehicles = getElementsByType ( "vehicle" ) -- get a table of all the Vehicles in the server for theKey,theVehicle in ipairs(vehicles) do -- use a generic for loop to step through each vehicle if ( isVehicleOnGround ( theVehicle ) ) then -- if the vehicle is on the ground, announce it outputChatBox ( getVehicleName ( theVehicle ) .. " is on the ground and made GOD-like" ) setVehicleDamageProof ( theVehicle, true ) else -- if the vehicle isn't on the ground, announce that it is in the air outputChatBox ( getVehicleName ( theVehicle ) .. " is in the air and made GOD-like" ) setVehicleDamageProof ( theVehicle, true ) end end end ) Any ideas what i am doing wrong? Many thanks in advance. Link to comment
Castillo Posted January 14, 2012 Share Posted January 14, 2012 -- server side: addEventHandler ( "onVehicleEnter", root, function () if ( isVehicleOnGround ( source ) ) then -- if the vehicle is on the ground, announce it outputChatBox ( getVehicleName ( source ) .. " is on the ground and made GOD-like" ) setVehicleDamageProof ( source, true ) else -- if the vehicle isn't on the ground, announce that it is in the air outputChatBox ( getVehicleName ( source ) .. " is in the air and made GOD-like" ) setVehicleDamageProof ( source, true ) end end) That'll be triggered when you enter a vehicle, which is when the race starts, because you get warped to a vehicle. Link to comment
Stijger Posted January 16, 2012 Author Share Posted January 16, 2012 Hey Solidsnake14, Thanks for your reply, but the same thing happens the text is displaying fine but for some reason the vehicle is not made damageproof. In the debugscript there is also no error. Link to comment
Stijger Posted January 16, 2012 Author Share Posted January 16, 2012 like i said there is no error the text is displaying, but when i hit a wall or anything it still takes damage. Link to comment
SDK Posted January 16, 2012 Share Posted January 16, 2012 Try testing the script with the default freeroam mode, it could be that race is messing with it. (Also, one small improvement, but it won't change your problem) addEventHandler ( "onVehicleEnter", root, function () setVehicleDamageProof ( source, true ) if ( isVehicleOnGround ( source ) ) then outputChatBox (getVehicleName ( source ) .. " is on the ground and made GOD-like") else outputChatBox (getVehicleName ( source ) .. " is in the air and made GOD-like") end end) Edit: I checked and race overrides your setVehicleDamageProof every time you get unfrozen after spawning, and there's no easy way to work around it. Better would be to cancel the onVehicleDamage event: addEventHandler("onVehicleDamage", source, function() cancelEvent() end) Link to comment
Stijger Posted January 16, 2012 Author Share Posted January 16, 2012 Hey SDK, thanks for your input, will test in a minute. And another question, how did you test or found out that race is overriding the function? (for my debugging methodes in the future) Link to comment
SDK Posted January 16, 2012 Share Posted January 16, 2012 I've got experience with the race resource, so I already knew where to look. I searched the race script with n++'s "Search in files" feature for "setVehicleDamageProof". Found this in race\modes\base.lua: -------------------------------------- -- For use when starting or respawing -------------------------------------- function RaceMode.playerUnfreeze(player, bDontFix) if not isValidPlayer(player) then return end toggleAllControls(player,true) clientCall( player, "updateVehicleWeapons" ) local vehicle = RaceMode.getPlayerVehicle(player) if not bDontFix then fixVehicle(vehicle) end setVehicleDamageProof(vehicle, false) setVehicleEngineState(vehicle, true) setElementFrozen(vehicle, false) -- Remove things added for freeze only Override.setCollideWorld( "ForVehicleJudder", vehicle, nil ) Override.setCollideOthers( "ForVehicleSpawnFreeze", vehicle, nil ) Override.setAlpha( "ForRespawnEffect", {player, vehicle}, nil ) Override.flushAll() end And another question, how did you test or found out that race is overriding the function? (for my debugging methodes in the future) It's easier to debug without other (not important) resources running. Make sure your script works, then test it out with other resources. The best way to find out if/which resource is interfering, is to stop them all (or the one's you think will give you problems) so you know there's nothing wrong with your script. Then enable them one by one and test to find it. Link to comment
Stijger Posted January 16, 2012 Author Share Posted January 16, 2012 Hey SDK, This is what i got with your code. http://i.imgur.com/VcAcr.jpg and tried something of my own, being this: addEventHandler("onVehicleDamage", getRootElement(), cancelEvent ) and then i got this: http://i.imgur.com/JkEtQ.jpg Any ideas? cause i really just started with scripting, so don't know and get everything of it. Link to comment
SDK Posted January 16, 2012 Share Posted January 16, 2012 My code was meant to replace the setVehicleDamageProof line in the solution by solidsnake. But since your making a map, it's easier to do this: addEventHandler("onVehicleDamage", root, function() cancelEvent() end) Root means all vehicles Link to comment
Stijger Posted January 16, 2012 Author Share Posted January 16, 2012 And the race script is why it does work with the maker ofcourse, cause that after the unfreeze. (maybe a bit obvious, but still learning ) isn't there a command to start it after the countdown? could that work? And thanks for explaining how you debug, it's pretty standard actually, almost the same with electronics debugging (more my area) Link to comment
SDK Posted January 16, 2012 Share Posted January 16, 2012 You mean an event? I don't think there's one that can be used here. Like I said, for a map it's easier to just disable damage for all vehicles all the time. Link to comment
Stijger Posted January 16, 2012 Author Share Posted January 16, 2012 Hey SDK, Awesome, it works after taking one hit. Made it into this. addEventHandler("onVehicleDamage", root, function() cancelEvent() outputChatBox ( getVehicleName ( source ) .. " was damaged and made god-like" ) setVehicleDamageProof ( source, true ) end) Thank you very much. For helping with the script and the explaining about scripting, you really helped a lot. Link to comment
Stijger Posted March 21, 2012 Author Share Posted March 21, 2012 For people that are interested: function handling ( ) for _,veh in pairs(getElementsByType("vehicle")) do if getElementModel(veh) == 495 then setVehicleHandling(veh, "collisionDamageMultiplier", 0) end end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), handling ) This makes the sandking (id: 495) godlike for all collisions. Right from the start. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now