• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Support] My "kill punishment" script not working

Michael Orsino

Premium User
Staff member
Premium User
Support Team
Joined
Nov 15, 2007
Messages
864
Solutions
10
Reaction score
452
Location
Western Australia
Having some trouble with a small script I am trying to write.
The basic idea of it is, if a high level kills a noob, he will lose the entire exp that the lower leveled player has gained.
Not sure why exactly it wont work
Hopefully you guys can help, thank you

Code:
function onKill(cid, target, lastHit)

local killerLevel = getPlayerLevel(cid)
local victimLevel = getPlayerLevel(target)
local pkCalc = (10 - getPlayerFrags(cid))

if victimLevel < 80 and victimLevel < (0.5 * killerLevel) then
doPlayerAddExperience(cid, -(getPlayerExperience(target)))
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"You have been punished for killing a noob! You lost " .. getPlayerExperience(target) .. " EXP. You have " .. pkCalc .. " kills left till Red Skull.")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"Good kill. You have " .. pkCalc .. " kills left till Red Skull.")
return TRUE
end
end

I thought it would be rather simple, but it does not seem to be working at all right now

Any help is appreciated,
Thank you

Michael
 
Any error message?

I have compared with other scripts, and you made the if turn true instead of the function.

Instead of return true (in the if ---- function) make return true in the function onKill function?
Also try to write true instead of TRUE (with caps). Perhaps it is case sensitive. (I am java programmer - everything is case sensitive).
LUA:
function onKill(cid, target, lastHit)

local killerLevel = getPlayerLevel(cid)
local victimLevel = getPlayerLevel(target)
local pkCalc = (10 - getPlayerFrags(cid))

if victimLevel < 80 and victimLevel < (0.5 * killerLevel) then
doPlayerAddExperience(cid, -(getPlayerExperience(target)))
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"You have been punished for killing a noob! You lost " .. getPlayerExperience(target) .. " EXP. You have " .. pkCalc .. " kills left till Red Skull.")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"Good kill. You have " .. pkCalc .. " kills left till Red Skull.")
end
return true
end

Not sure if this is a problem. :P Its a wild guess I got when comparing with other creaturescripts.

I have checked 5 - 10 lua creaturescript, and all of them have return true as the 2nd last line.
 
Last edited:
Code:
function onKill(cid, target, lastHit)
	if(getPlayerLevel(target) < 80 or getPlayerLevel(target) < 0.5 * getPlayerLevel(cid)) then
		doPlayerAddExperience(cid, -(getPlayerExperience(target)))
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"You have been punished for killing a noob! \nYou lost " .. getPlayerExperience(target) .. " EXP. \nYou have " .. (10 - getPlayerFrags(cid)) .. " kills left till Red Skull.")
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"Good kill. You have " .. (10 - getPlayerFrags(cid)) .. " kills left till Red Skull.")
	end
	return true
end
 
Code:
function onKill(cid, target, lastHit)
	if(getPlayerLevel(target) < 80 or getPlayerLevel(target) < 0.5 * getPlayerLevel(cid)) then
		doPlayerAddExperience(cid, -(getPlayerExperience(target)))
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"You have been punished for killing a noob! \nYou lost " .. getPlayerExperience(target) .. " EXP. \nYou have " .. (10 - getPlayerFrags(cid)) .. " kills left till Red Skull.")
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"Good kill. You have " .. (10 - getPlayerFrags(cid)) .. " kills left till Red Skull.")
	end
	return true
end

Code:
function onKill(cid, target, lastHit)
	if(getPlayerLevel(target) < 80 and getPlayerLevel(target) < 0.5 * getPlayerLevel(cid)) then
		doPlayerAddExperience(cid, -(getPlayerExperience(target)))
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"You have been punished for killing a noob! \nYou lost " .. getPlayerExperience(target) .. " EXP. \nYou have " .. (10 - getPlayerFrags(cid)) .. " kills left till Red Skull.")
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,"Good kill. You have " .. (10 - getPlayerFrags(cid)) .. " kills left till Red Skull.")
	end
	return true
end

I think he wants it to be and, not or.
 
Back
Top