Jump to content

God like car


Stijger

Recommended Posts

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

-- 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

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

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

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

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 :D)

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

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
  • 2 months later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...