Jump to content

"onPlayerWasted" problem


Xabi

Recommended Posts

Hi all, I've got a GameMode with some resources forming it. The problem with "onPlayerWasted" is that it gets called in 2 of these resources.

[in vehicles.lua I have this]

function unbindKeysVehicle()

if isKeyBound(source, "num_add", "up", toggleEngine) then

unbindKey(source, "LALT", "up", toggleEngine)

unbindKey(source, "num_add", "up", toggleLights)

end

end

addEventHandler("onPlayerWasted", root, unbindKeysVehicle)

[in medic.lua I have this]

function playerDeath()

local posX, posY, posZ = getElementPosition(source)

local interior = getElementInterior(source)

local dimension = getElementDimension(source)

local ammo = getPedTotalAmmo(source)

local skin = getElementData(source, "rpPlayerSkin")

local uniform = getElementData(source, "rpPlayerUniform")

if getElementData(source, "rpPlayerWorking") == 1 and uniform ~= 0 and getElementData(source, "rpPlayerPoliceName") == false then

skin = uniform

end

if ammo > 1 then

local weapon = getPedWeapon(source)

local model = exports.functions:getWeaponModel(weapon)

local weaponObject = createObject(model, posX, posY, posZ-0.95, 90.0, 0.0, 0.0, true)

local query = dbQuery(connectionHandle, "INSERT INTO weapons (posX, posY, posZ, weapon, ammo, model, interior, dimension) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", posX, posY, posZ, weapon, ammo, model, interior, dimension)

local result, num_affected_rows, last_insert_id = dbPoll(query, -1)

takeWeapon(source, weapon)

setElementInterior(weaponObject, interior)

setElementDimension(weaponObject, dimension)

droppedWeapon = createElement("droppedweapon")

setElementData(droppedWeapon, "weapons.wId", last_insert_id)

setElementData(droppedWeapon, "weapons.wType", weapon)

setElementData(droppedWeapon, "weapons.wAmmo", ammo)

setElementData(droppedWeapon, "weapons.wInterior", interior)

setElementData(droppedWeapon, "weapons.wDimension", dimension)

setElementData(droppedWeapon, "weapons.wObject", weaponObject)

end

setElementData(source, "rpPlayerKilled", killerWeapon)

spawnPlayer(source, posX, posY, posZ, 0, skin, interior, dimension)

end

addEventHandler("onPlayerWasted", root, playerDeath)

So the problem is that, if I write "resourceRoot" in those events the player won't spawn when it gets killed, but if I put "root" it won't unbind ALT and + keys.

Any help, please?

Link to comment

vehicles.lua

function unbindKeysVehicle() 
  if isKeyBound(source, "num_add", "up", toggleEngine) then 
    unbindKey(source, "LALT", "up", toggleEngine) 
    unbindKey(source, "num_add", "up", toggleLights) 
  end 
end 
addEventHandler("onPlayerWasted", root, unbindKeysVehicle) 

medic.lua

function playerDeath() 
  local posX, posY, posZ = getElementPosition(source) 
  local interior = getElementInterior(source) 
  local dimension = getElementDimension(source) 
  local ammo = getPedTotalAmmo(source) 
  local skin = getElementData(source, "rpPlayerSkin") 
  local uniform = getElementData(source, "rpPlayerUniform") 
  if getElementData(source, "rpPlayerWorking") == 1 and uniform ~= 0 and getElementData(source, "rpPlayerPoliceName") == false then 
    skin = uniform 
  end 
  if ammo > 1 then 
    local weapon = getPedWeapon(source) 
    local model = exports.functions:getWeaponModel(weapon) 
    local weaponObject = createObject(model, posX, posY, posZ-0.95, 90.0, 0.0, 0.0, true) 
    local query = dbQuery(connectionHandle, "INSERT INTO weapons (posX, posY, posZ, weapon, ammo, model, interior, dimension) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", posX, posY, posZ, weapon, ammo, model, interior, dimension) 
    local result, num_affected_rows, last_insert_id = dbPoll(query, -1) 
    takeWeapon(source, weapon) 
    setElementInterior(weaponObject, interior) 
    setElementDimension(weaponObject, dimension) 
    droppedWeapon = createElement("droppedweapon") 
    setElementData(droppedWeapon, "weapons.wId", last_insert_id) 
    setElementData(droppedWeapon, "weapons.wType", weapon) 
    setElementData(droppedWeapon, "weapons.wAmmo", ammo) 
    setElementData(droppedWeapon, "weapons.wInterior", interior) 
    setElementData(droppedWeapon, "weapons.wDimension", dimension) 
    setElementData(droppedWeapon, "weapons.wObject", weaponObject) 
  end 
  setElementData(source, "rpPlayerKilled", killerWeapon) 
  spawnPlayer(source, posX, posY, posZ, 0, skin, interior, dimension) 
end 
addEventHandler("onPlayerWasted", root, playerDeath) 

Code unchanged right now, just fixed formatting and indenting to make the code clearer

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