Jump to content

Checking the player who was killed


Lergen

Recommended Posts

Hello again. I've been playing around with the GTW scripts as they're open source, but I discovered a small problem. Whenever an enemy player dies inside a turf, the player who got the kill receives some money. However, a player can also kill themselves with a grenade or vehicle and still receive the money as if they had killed an enemy. Is there any way to check that the player who just died wasn't themself so they won't receive payment?

function player_Wasted(ammo, attacker, weapon, bodypart)
	if isElement(source) and isElement(attacker) and getElementType(attacker) == "player" then
		if(getPlayerTeam(source) == getTeamFromName(team_criminals) or getPlayerTeam(source) == getTeamFromName(team_lnr)) or getPlayerTeam(source) == getTeamFromName(team_gangsters) and
		(getPlayerTeam(attacker) == getTeamFromName(team_criminals) or getPlayerTeam(attacker) == getTeamFromName(team_lnr)) or getPlayerTeam(attacker) == getTeamFromName(team_gangsters) and
		getElementData(source, "Group") ~= getElementData(attacker, "Group") and
		not isTimer(cooldown[attacker]) and getElementData(source,"isInTurf") then
			local victim_money = getPlayerMoney(source)
			if victim_money > money_pickpocket_max then
				victim_money = money_pickpocket_max
			elseif victim_money < money_pickpocket_min then
				victim_money = money_pickpocket_min
			end
			local money = math.floor(victim_money*(math.random(10,25)/25))

			givePlayerMoney(attacker, math.floor(money))

 

Link to comment
  • Scripting Moderators
1 hour ago, Lergen said:

Hello again. I've been playing around with the GTW scripts as they're open source, but I discovered a small problem. Whenever an enemy player dies inside a turf, the player who got the kill receives some money. However, a player can also kill themselves with a grenade or vehicle and still receive the money as if they had killed an enemy. Is there any way to check that the player who just died wasn't themself so they won't receive payment?


function player_Wasted(ammo, attacker, weapon, bodypart)
	if isElement(source) and isElement(attacker) and getElementType(attacker) == "player" then
		if(getPlayerTeam(source) == getTeamFromName(team_criminals) or getPlayerTeam(source) == getTeamFromName(team_lnr)) or getPlayerTeam(source) == getTeamFromName(team_gangsters) and
		(getPlayerTeam(attacker) == getTeamFromName(team_criminals) or getPlayerTeam(attacker) == getTeamFromName(team_lnr)) or getPlayerTeam(attacker) == getTeamFromName(team_gangsters) and
		getElementData(source, "Group") ~= getElementData(attacker, "Group") and
		not isTimer(cooldown[attacker]) and getElementData(source,"isInTurf") then
			local victim_money = getPlayerMoney(source)
			if victim_money > money_pickpocket_max then
				victim_money = money_pickpocket_max
			elseif victim_money < money_pickpocket_min then
				victim_money = money_pickpocket_min
			end
			local money = math.floor(victim_money*(math.random(10,25)/25))

			givePlayerMoney(attacker, math.floor(money))

 

Condition which check if attacker is not equal to victim?

if attacker ~= source then
	--
end

 

Link to comment
19 hours ago, majqq said:

Condition which check if attacker is not equal to victim?


if attacker ~= source then
	--
end

 

Yeah, that's what I'm trying to do, make sure the attacker isn't the person who died. I tried this, but still couldn't get it working. Am I forgetting something here or doing something wrong?

function player_Wasted(ammo, attacker, weapon, bodypart)
	if isElement(source) and isElement(attacker) and getElementType(attacker) == "player" then
	if attacker ~= source then
    end
	else
		if(getPlayerTeam(source) == getTeamFromName(team_criminals) or getPlayerTeam(source) == getTeamFromName(team_lnr)) or getPlayerTeam(source) == getTeamFromName(team_gangsters) and
		(getPlayerTeam(attacker) == getTeamFromName(team_criminals) or getPlayerTeam(attacker) == getTeamFromName(team_lnr)) or getPlayerTeam(attacker) == getTeamFromName(team_gangsters) and
		getElementData(source, "Group") ~= getElementData(attacker, "Group") and
		not isTimer(cooldown[attacker]) and getElementData(source,"isInTurf") then
			local victim_money = getPlayerMoney(source)
			if victim_money > money_pickpocket_max then
				victim_money = money_pickpocket_max
			elseif victim_money < money_pickpocket_min then
				victim_money = money_pickpocket_min
			end
			local money = math.floor(victim_money*(math.random(10,25)/25))

 

Link to comment
  • Scripting Moderators
5 hours ago, Lergen said:

Yeah, that's what I'm trying to do, make sure the attacker isn't the person who died. I tried this, but still couldn't get it working. Am I forgetting something here or doing something wrong?


function player_Wasted(ammo, attacker, weapon, bodypart)
	if isElement(source) and isElement(attacker) and getElementType(attacker) == "player" then
	if attacker ~= source then
    end
	else
		if(getPlayerTeam(source) == getTeamFromName(team_criminals) or getPlayerTeam(source) == getTeamFromName(team_lnr)) or getPlayerTeam(source) == getTeamFromName(team_gangsters) and
		(getPlayerTeam(attacker) == getTeamFromName(team_criminals) or getPlayerTeam(attacker) == getTeamFromName(team_lnr)) or getPlayerTeam(attacker) == getTeamFromName(team_gangsters) and
		getElementData(source, "Group") ~= getElementData(attacker, "Group") and
		not isTimer(cooldown[attacker]) and getElementData(source,"isInTurf") then
			local victim_money = getPlayerMoney(source)
			if victim_money > money_pickpocket_max then
				victim_money = money_pickpocket_max
			elseif victim_money < money_pickpocket_min then
				victim_money = money_pickpocket_min
			end
			local money = math.floor(victim_money*(math.random(10,25)/25))

 

What did you wrong is that i left comment to complete your code in it. But it would be easier for you using what @DNL291 suggested.

Edited by majqq
  • Thanks 1
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...