-
-
Notifications
You must be signed in to change notification settings - Fork 171
deathpickups: some improvements #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,103 @@ | ||
local timers = {} -- timers for existing pickups | ||
|
||
local function onDeathPickupHit ( player, matchingDimension ) | ||
if matchingDimension then | ||
killTimer ( timers[source] ) | ||
timers[source] = nil | ||
removeEventHandler ( "onPickupHit", source, onDeathPickupHit ) | ||
local weapid = getPickupWeapon ( source ) | ||
local weapammo = getPickupAmmo ( source ) | ||
destroyElement ( source ) | ||
giveWeapon ( player, weapid, weapammo, false ) | ||
local pickupTimers = {} | ||
local expireTime = get("timeout") | ||
local onlyCurrentWeapon = get("only_current") | ||
local dropRadius = get("radius") | ||
|
||
local function destroyDeathPickup(pickupElement) | ||
if isElement(pickupElement) then | ||
destroyElement(pickupElement) | ||
end | ||
end | ||
|
||
local function dropAllWeapons(posX, posY, posZ, droppedWeapons) | ||
local weaponsCount = #droppedWeapons | ||
|
||
for wID = 1, weaponsCount do | ||
local weaponData = droppedWeapons[wID] | ||
local weaponID = weaponData[1] | ||
local weaponAmmo = weaponData[2] | ||
local pickupX = posX + dropRadius * math.cos((wID - 1) * 2 * math.pi/weaponsCount) | ||
local pickupY = posY + dropRadius * math.sin((wID - 1) * 2 * math.pi/weaponsCount) | ||
local pickupElement = createPickup(pickupX, pickupY, posZ, 2, weaponID, expireTime, weaponAmmo) | ||
|
||
pickupTimers[pickupElement] = setTimer(destroyDeathPickup, expireTime, 1, pickupElement) | ||
end | ||
end | ||
|
||
local function destroyDeathPickup ( pickup ) | ||
timers[pickup] = nil | ||
removeEventHandler ( "onPickupHit", pickup, onDeathPickupHit ) | ||
destroyElement ( pickup ) | ||
function onDeathPickupHit(playerElement) | ||
cancelEvent() | ||
giveWeapon(playerElement, getPickupWeapon(source), getPickupAmmo(source), false) | ||
destroyDeathPickup(source) | ||
end | ||
addEventHandler("onPickupHit", resourceRoot, onDeathPickupHit) | ||
|
||
function onPlayerWasted() | ||
local posX, posY, posZ = getElementPosition(source) | ||
|
||
if onlyCurrentWeapon then | ||
local playerWeapon = getPedWeapon(source) | ||
local validWeapon = playerWeapon and playerWeapon ~= 0 | ||
|
||
addEventHandler ( "onPlayerWasted", getRootElement (), | ||
function ( source_ammo, killer, killer_weapon, bodypart ) | ||
local pX, pY, pZ = getElementPosition ( source ) | ||
local timeout = get("timeout") | ||
|
||
if get("only_current") then | ||
local source_weapon = getPedWeapon ( source ) | ||
if ( source_weapon and source_weapon ~= 0 and source_ammo ) then | ||
local pickup = createPickup ( pX, pY, pZ, 2, source_weapon, timeout, source_ammo ) | ||
addEventHandler ( "onPickupHit", pickup, onDeathPickupHit ) | ||
timers[pickup] = setTimer ( destroyDeathPickup, timeout, 1, pickup ) | ||
if validWeapon then | ||
local totalAmmo = getPedTotalAmmo(source) | ||
local pickupElement = createPickup(posX, posY, posZ, 2, playerWeapon, expireTime, totalAmmo) | ||
|
||
pickupTimers[pickupElement] = setTimer(destroyDeathPickup, expireTime, 1, pickupElement) | ||
end | ||
else | ||
local droppedWeapons = {} | ||
|
||
for weaponSlot = 0, 12 do | ||
local playerWeapon = getPedWeapon(source, weaponSlot) | ||
local validWeapon = playerWeapon ~= 0 | ||
|
||
if validWeapon then | ||
local ammoInSlot = getPedTotalAmmo(source, weaponSlot) | ||
|
||
droppedWeapons[#droppedWeapons + 1] = {playerWeapon, ammoInSlot} | ||
end | ||
else | ||
local droppedWeapons = {} | ||
for slot=0, 12 do | ||
local ammo = getPedTotalAmmo(source, slot) | ||
if (getPedWeapon(source, slot) ~= 0) then | ||
local weapon = getPedWeapon(source, slot) | ||
local ammo = getPedTotalAmmo(source, slot) | ||
table.insert(droppedWeapons, {weapon, ammo}) | ||
end | ||
end | ||
|
||
dropAllWeapons(posX, posY, posZ, droppedWeapons) | ||
end | ||
end | ||
addEventHandler("onPlayerWasted", root, onPlayerWasted) | ||
|
||
function onElementDestroyPickup() | ||
local validElement = isElement(source) | ||
|
||
if validElement then | ||
local pickupType = getElementType(source) == "pickup" | ||
|
||
if pickupType then | ||
local pickupTimer = pickupTimers[source] | ||
|
||
if pickupTimer then | ||
killTimer(pickupTimer) | ||
pickupTimers[source] = nil | ||
end | ||
DropAllWeapons(droppedWeapons) | ||
end | ||
end | ||
) | ||
|
||
function DropAllWeapons ( droppedWeapons ) | ||
local radius = get("radius") | ||
local numberDropped = #droppedWeapons | ||
for i, t in ipairs(droppedWeapons) do | ||
local pX, pY, pZ = getElementPosition ( source ) | ||
local x = pX + radius * math.cos((i-1) * 2 * math.pi / numberDropped) | ||
local y = pY + radius * math.sin((i-1) * 2 * math.pi / numberDropped) | ||
local timeout = get("timeout") | ||
local pickup = createPickup(x, y, pZ, 2, t[1], timeout, t[2]) | ||
addEventHandler ( "onPickupHit", pickup, onDeathPickupHit ) | ||
timers[pickup] = setTimer ( destroyDeathPickup, timeout, 1, pickup ) | ||
end | ||
addEventHandler("onElementDestroy", resourceRoot, onElementDestroyPickup) | ||
|
||
function onSettingChange(settingName, _, newValue) | ||
local expireSetting = settingName == "*deathpickups.timeout" | ||
|
||
if expireSetting then | ||
expireTime = fromJSON(newValue) | ||
end | ||
|
||
local weaponSetting = settingName == "*deathpickups.only_current" | ||
|
||
if weaponSetting then | ||
onlyCurrentWeapon = fromJSON(newValue) | ||
end | ||
|
||
local radiusSetting = settingName == "*deathpickups.radius" | ||
|
||
if radiusSetting then | ||
dropRadius = fromJSON(newValue) | ||
end | ||
end | ||
addEventHandler("onSettingChange", resourceRoot, onSettingChange) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<meta> | ||
<info author="erorr404" type="script" version="1.0.1" /> | ||
<script src="deathpickups.lua" /> | ||
<info author="erorr404" type="script" version="1.1"/> | ||
<script src="deathpickups.lua" type="server"/> | ||
<settings> | ||
<setting name="*timeout" value="[30000]"/> | ||
<setting name="*only_current" value="[false]"/> | ||
<setting name="*radius" value="[1]"/> | ||
</settings> | ||
</meta> | ||
</meta> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.