Jump to content

Rhino: Making it more fragile


Recommended Posts

I have a server that is INTENDED to become a army vs. criminals server. But the army's rhino is just indestructible except for flame damage. Is it possible to make it a lot more vulnerable to specific weapon kinds? F.e. Rockets and Hunter's machinegun for a bit?

Link to comment

the event "onVehicleDamage" MIGHT help, but I'm not sure if it registers as damage unless you do use fire... worth a shot. Of course, specializing it to one or two weps only will take some doing, but if I'm not mistaken, explosions should work too?

Link to comment

Hmmm... I'll try. But I think there will still be a problem concerning what RobHol said: "but I'm not sure if it registers as damage unless you do use fire..."

Honestly, I don't think so. But never shot, never hit. So I'll try.

EDIT: I fear I was right... It doesn't get any damage at all, only from flames that get out of rockets when fired at close range, flamethrower/molotov or bad driving... Even satchel charges can't destroy a Rhino. So anyone got another idea?

Edited by Guest
Link to comment

I can't find out how I can let it check for if a rocket launcher hits it. It's projectile as well as weapon don't seem to function with onClientPlayerWeaponFire.

And what if it detected it has been hit? How do I let that vehicle(rhino) get damage?

Link to comment

I'm confused. Your're right about it doesn't work - but it does sometimes ? I put this in server-side:

  
addEventHandler("onVehicleDamage",getRootElement(), 
    function(loss) 
        setElementHealth(source,0) 
    end 
) 
  

and I can punch a tank to make it instantly burn. I can hit it with a rocket but only at close quarter; I can't hit it with an AK47 at all ? Is this event bugged or does it only consistently work for car collisions ? (i.e. not being shot at). Or is this problematic because firing is essentially client-side and this event is server-side ?

Link to comment

TMA's code indeed is a little... Sensitive xD Luckily it is still invulnerable to Miniguns, what I would like to keep. They just need to get damage from the rockets. Not being destroyed with 1 rocket... That's pretty retarded. xD So anyone got an idea of making it a little less retarded? And for Rhino only? Thanks.

Link to comment

Something like this would double the damage on the rhino (untested):

  
addEventHandler("onVehicleDamage",getRootElement(), 
    function(loss) 
        if getVehicleID(source) == 432 then 
            setElementHealth(source,getElementHealth(source) - loss) 
        end 
    end 
) 
  

Link to comment
Something like this would double the damage on the rhino (untested):
  
addEventHandler("onVehicleDamage",getRootElement(), 
    function(loss) 
        if getVehicleID(source) == 432 then 
            setElementHealth(source,getElementHealth(source) - loss) 
        end 
    end 
) 
  

Great! Now the flames atleast can stop it in notime! Only problem now still is how to make it destructable for other weapons...

Thanks anyway, the server will atleast improve a quite a bit from this. Thanks. :D But still looking for another script though. ;)

And of the setVehicleDamageProof: it didn't work...

Link to comment
  • 1 month later...

I now understand how they did it in battlefield 69. A bit of a laugh though... LOL.

ab87cecefd61420fe06825f9437a6ca4d2cd8f1d.jpg

They pasted a RC cam on the tank... Here's the (partial) code:

addEventHandler ("onVehicleEnter", root, function ( player, seat, jacked ) 
    if getVehicleID(source) == 476 then 
        triggerClientEvent (player, "rustlerEnter", player ) 
        local x, y, z = getElementPosition(source) 
        local rotX, rotY, rotZ = getVehicleRotation(source) 
        bomb1 = createObject( 3790, x, y, z - 1, rotZ - 90, rotY, rotZ) 
        attachElementToElement (bomb1, source, 0, 0, -1.2, 0, 0, -1.5 ) 
    elseif getVehicleID(source) == 432 then 
        local x, y, z = getElementPosition (source) 
        if not (pot[source]) then 
            pot[source] = createVehicle (594, x + 3, y, z) 
            attachElementToElement (pot[source], source, 0, 4, 0.5, 0, 0, 0) 
            setElementParent (pot[source], source) 
            setElementHealth (pot[source], 2000) 
            setElementHealth (source, 2000) 
            setElementAlpha (pot[source], 0) 
        end 
        triggerClientEvent (getVehicleOccupant(source), "damageVehicle", source ) 
        triggerClientEvent (getVehicleOccupant(source), "enterRhino", source ) 
    elseif getVehicleID(source) == 520 or getVehicleID(source) == 425 then 
        triggerClientEvent (getVehicleOccupant(source), "enterRhino", source ) 
    elseif getVehicleID(source) == 578 then 
        if getTeamName(getPlayerTeam(player)) == "Ally" then 
            for k,v in pairs(axisBlip) do 
                setElementVisibleTo(v, root, true) 
            end 
        elseif getTeamName(getPlayerTeam(player)) == "Axis" then 
            for k,v in pairs(allyBlip) do 
                setElementVisibleTo(v, root, true) 
            end 
        end  
    end 
end) 

addEventHandler ("onVehicleDamage", getRootElement(), function (loss) 
    if getVehicleID(source) == 594 then 
        local tank = getElementParent (source) 
        if ( getVehicleOccupant(tank) ~= false ) then 
            triggerClientEvent (getVehicleOccupant(tank), "damageVehicle", source, loss )  
        end 
        setElementHealth (tank, getElementHealth(source)) 
    end 
end) 

Also the solution to how to let the Rhino's front lights work... LOL.

Link to comment

Here's a simple alternative to make a rhino receive damage from explosions.

  
EFFECTIVE_RANGE = 10 
EXPLOSION_DAMAGE = 5 
  
function onClientExplosion(x, y, z, type) 
  local tX, tY, tZ = 0, 0, 0 
  local distance3D = 0 
  local health = 0 
  local damage = 0 
  for _, vehicle in ipairs((getElementsByType("vehicle", getRootElement()) or {})) do 
    if (getVehicleID(vehicle) == 432) then 
      tX, tY, tZ = getElementPosition(vehicle) 
      health = getElementHealth(vehicle) or 0 
      distance3D = getDistanceBetweenPoints3D(x, y, z, tX, tY, tZ) or 0 
      if (distance3D < EFFECTIVE_RANGE) then 
        damage = EXPLOSION_DAMAGE * (EFFECTIVE_RANGE - distance3D) 
        if (health - damage > 0) then 
          setElementHealth(vehicle, health - damage) 
        end 
      end 
    end 
  end 
end 
  
addEventHandler("onClientExplosion", getRootElement(), onClientExplosion, true) 
  

Link to comment

I was going to say, isnt that easy? you just put a triggerServerSide before setElementHealth.

but that would be very bad, if there were 20 people nearby one explosion :P

maybe you could put a cooldown serverside to ignore all the extra incoming clients.

Link to comment

Forget what I said earlier. This code might actually work since the onClientExplosion event seems to trigger for the creators' view port only and setElementHealth is synchronized for both client and server code.

EDIT:

I did some testing (with 2 computers) and the damage factor is applied only once because the explosion event is not triggered when the creator is not the local player (or at least initiator).

Link to comment
So that means..?

This means that when a player is firing a rocket at the tank it will receive damage once (from that particular rocket). And damage caused by an explosion is synchronized meaning that you do not need an explicit server side call to set the tanks' health.

EDIT:

So basically this is all the code you need to provide very basic support for controlled tank damage.

Client

  
EFFECTIVE_RANGE = 10 
EXPLOSION_DAMAGE = 5 
BULLET_DAMAGE = 10 
  
function onClientExplosion(x, y, z, type) 
  local tX, tY, tZ = 0, 0, 0 
  local distance3D = 0 
  local health = 0 
  local damage = 0 
  for _, vehicle in ipairs((getElementsByType("vehicle", getRootElement()) or {})) do 
    if (getVehicleID(vehicle) == 432) then 
      tX, tY, tZ = getElementPosition(vehicle) 
      health = getElementHealth(vehicle) or 0 
      distance3D = getDistanceBetweenPoints3D(x, y, z, tX, tY, tZ) or 0 
      if (distance3D < EFFECTIVE_RANGE) then 
        damage = EXPLOSION_DAMAGE * (EFFECTIVE_RANGE - distance3D) 
        if (health - damage > 0) then 
          setElementHealth(vehicle, health - damage) 
        end 
      end 
    end 
  end 
end 
  
function onClientPlayerWeaponFire(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
  local health = 0 
  if (isElement(hitElement)) then 
    if (getElementType(hitElement) == "vehicle") then 
      if (getVehicleID(hitElement) == 432) then 
        health = getElementHealth(hitElement) or 0 
        if (health - BULLET_DAMAGE > 0) then 
          setElementHealth(hitElement, health - BULLET_DAMAGE) 
        end 
      end 
    end 
  end 
end 
  
addEventHandler("onClientExplosion", getRootElement(), onClientExplosion, true) 
addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), onClientPlayerWeaponFire, false) 
  

Server

  
DAMAGE_LOSS = 5 
  
function onVehicleDamage(loss) 
  local health = 0 
  if (isElement(source)) then 
    health = getElementHealth(source) or 0 
    if (health - DAMAGE_LOSS > 0) then 
      setElementHealth(hitElement, health - DAMAGE_LOSS) 
    end 
  end 
end 
  
addEventHandler("onVehicleDamage", getRootElement(), onVehicleDamage, true) 
  

Link to comment
  • 2 months later...

Ok so I have been using this for a while now, but now since I do it on a public server, I see it doesn't work most of the time... The rhino's can only damage themselves on this server, while on my own it worked correctly...

I've been trying to edit things, resetting to default, reediting again, resetting, editing and nothing actually helped... Any ideas? =/

I'm also doing different damage per type, but well that's not a thing to worry about... I more would like to know why this doesn't work... =/

Link to comment
Ok so I have been using this for a while now, but now since I do it on a public server, I see it doesn't work most of the time... The rhino's can only damage themselves on this server, while on my own it worked correctly...

I've been trying to edit things, resetting to default, reediting again, resetting, editing and nothing actually helped... Any ideas? =/

I'm also doing different damage per type, but well that's not a thing to worry about... I more would like to know why this doesn't work... =/

Yeah, I feel your pain. I think I know what the problem is. It seems like (but I am not 100% sure) onClientExplosion is only triggered if you are the creator of the explosion (which in a way does make sense). I never thought about it.

Edited by Guest
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...