• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

CreatureEvent PVP-E Area!

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Reaction score
53
Location
Włocławek
Hello, I made the code for a normal pvp server, that people acquire the experience for killing other players when you kill someone on the designated area, something like arena pvp-enforced.

into creaturescritps.xml
PHP:
<event type="preparedeath" name="pvpArena" event="script" value="pvparena.lua"/>

into creaturescripts/scripts/pvparena.lua
PHP:
config = {
	pvpParcent = 2, -- how many exp(player killed exp parcent) killers gain for kill.
	-- arena must be square!!
	arenaFrom = {200, 200, 7}, -- pvp arena from x,y,z position
	arenaTo = {400, 400, 7}, -- pvp arena to x,y,z position 

}


function gainExperience(cid,lastHitKiller, mostDamageKiller)
	if (isPlayer(lastHitKiller) and isPlayer(mostDamageKiller)) and (lastHitKiller ~= mostDamageKiller) then
		doPlayerAddExp(lastHitKiller, (getPlayerExperience(cid)/200)*config.pvpParcent)
		doSendAnimatedText(getPlayerPosition(lastHitKiller), (getPlayerExperience(cid)/200)*config.pvpParcent, TEXTCOLOR_WHITE)
		doPlayerAddExp(mostDamageKiller, (getPlayerExperience(cid)/200)*config.pvpParcent)
		doSendAnimatedText(getPlayerPosition(mostDamageKiller), (getPlayerExperience(cid)/200)*config.pvpParcent, TEXTCOLOR_WHITE)
	elseif (isPlayer(lastHitKiller) and not(isPlayer(mostDamageKiller))) then
		doPlayerAddExp(lastHitKiller, (getPlayerExperience(cid)/100)*config.pvpParcent)
		doSendAnimatedText(getPlayerPosition(lastHitKiller), (getPlayerExperience(cid)/100)*config.pvpParcent, TEXTCOLOR_WHITE)
	elseif (not(isPlayer(lastHitKiller)) and isPlayer(mostDamageKiller)) then	
		doPlayerAddExp(mostDamageKiller, (getPlayerExperience(cid)/100)*config.pvpParcent)
		doSendAnimatedText(getPlayerPosition(mostDamageKiller), (getPlayerExperience(cid)/100)*config.pvpParcent, TEXTCOLOR_WHITE)
	end
end

function onPrepareDeath(cid, lastHitKiller, mostDamageKiller)

	local playerPos = getPlayerPosition(cid)
	local killerPos = getPlayerPosition(lastHitKiller)
	if isPlayer(cid) then
		if (playerPos.x >= config.arenaFrom[1] and playerPos.x <= config.arenaTo[1]) and (playerPos.y >= config.arenaFrom[2] and playerPos.y <= config.arenaTo[2]) and (playerPos.z >= config.arenaFrom[3] and playerPos.z <= config.arenaTo[3]) then
			if (killerPos.x >= config.arenaFrom[1] and killerPos.x <= config.arenaTo[1]) and (killerPos.y >= config.arenaFrom[2] and killerPos.y <= config.arenaTo[2]) and (killerPos.z >= config.arenaFrom[3] and killerPos.z <= config.arenaTo[3]) then
				gainExperience(cid,lastHitKiller, mostDamageKiller)
			end
		end
	end
        return TRUE
end

and into creaturescripts/scripts/login.lua before:
PHP:
return TRUE

add:
PHP:
registerCreatureEvent(cid, "pvpArena")

Regards,
Azi.
 
Last edited:
i tested this. but i got some bugs that it goes to 0 hp then you just stand ther :S
 
you added it here ?
config = {
pvpParcent = 2, -- how many exp(player killed exp parcent) killers gain for kill.
-- arena must be square!!
arenaFrom = {200, 200, 7}, -- pvp arena from x,y,z position
arenaTo = {400, 400, 7}, -- pvp arena to x,y,z position

}


function gainExperience(cid,lastHitKiller, mostDamageKiller)
if (isPlayer(lastHitKiller) and isPlayer(mostDamageKiller)) and (lastHitKiller ~= mostDamageKiller) then
doPlayerAddExp(lastHitKiller, (getPlayerExperience(cid)/200)*config.pvpParcent)
doSendAnimatedText(getPlayerPosition(lastHitKiller), (getPlayerExperience(cid)/200)*config.pvpParcent, TEXTCOLOR_WHITE)
doPlayerAddExp(mostDamageKiller, (getPlayerExperience(cid)/200)*config.pvpParcent)
doSendAnimatedText(getPlayerPosition(mostDamageKiller), (getPlayerExperience(cid)/200)*config.pvpParcent, TEXTCOLOR_WHITE)
elseif (isPlayer(lastHitKiller) and not(isPlayer(mostDamageKiller))) then
doPlayerAddExp(lastHitKiller, (getPlayerExperience(cid)/100)*config.pvpParcent)
doSendAnimatedText(getPlayerPosition(lastHitKiller), (getPlayerExperience(cid)/100)*config.pvpParcent, TEXTCOLOR_WHITE)
elseif (not(isPlayer(lastHitKiller)) and isPlayer(mostDamageKiller)) then
doPlayerAddExp(mostDamageKiller, (getPlayerExperience(cid)/100)*config.pvpParcent)
doSendAnimatedText(getPlayerPosition(mostDamageKiller), (getPlayerExperience(cid)/100)*config.pvpParcent, TEXTCOLOR_WHITE)
end
end

function onPrepareDeath(cid, lastHitKiller, mostDamageKiller)

local playerPos = getPlayerPosition(cid)
local killerPos = getPlayerPosition(lastHitKiller)
if isPlayer(cid) then
if (playerPos.x >= config.arenaFrom[1] and playerPos.x <= config.arenaTo[1]) and (playerPos.y >= config.arenaFrom[2] and playerPos.y <= config.arenaTo[2]) and (playerPos.z >= config.arenaFrom[3] and playerPos.z <= config.arenaTo[3]) then
if (killerPos.x >= config.arenaFrom[1] and killerPos.x <= config.arenaTo[1]) and (killerPos.y >= config.arenaFrom[2] and killerPos.y <= config.arenaTo[2]) and (killerPos.z >= config.arenaFrom[3] and killerPos.z <= config.arenaTo[3]) then
gainExperience(cid,lastHitKiller, mostDamageKiller)
end
end
end
return TRUE
end
 
It could be better with the formula of tibia cip.

Lua:
(1 - (getPlayerLevel(lastHitKiller) * 0.9) / getPlayerLevel(cid)) * 0.05 * getPlayerExperience(cid)

f4cbfed9a98f8b52a43e9ee7d32f51.png

  • a = killer's level * 0.9 <- rounded down
  • b = victim's level
  • c = victim's experience

http://tibia.wikia.com/wiki/Formula#Exp_from_Killing_other_Players_on_PvP-Enforced_World
 
When i used the script i got this error and i didnt die i just had 0 hp and 0 mana

PHP:
[01/04/2010 14:10:35] Lua Script Error: [CreatureScript Interface] 
[01/04/2010 14:10:35] data/creaturescripts/scripts/pvparena.lua:onPrepareDeath

[01/04/2010 14:10:35] luaGetCreaturePosition(). Creature not found

[01/04/2010 14:10:35] Lua Script Error: [CreatureScript Interface] 
[01/04/2010 14:10:35] data/creaturescripts/scripts/pvparena.lua:onPrepareDeath

[01/04/2010 14:10:35] data/creaturescripts/scripts/pvparena.lua:30: attempt to index field 'arenaFrom' (a nil value)
[01/04/2010 14:10:35] stack traceback:
[01/04/2010 14:10:35] 	data/creaturescripts/scripts/pvparena.lua:30: in function <data/creaturescripts/scripts/pvparena.lua:25>
 
I tested this on 0.3.6, but it never worked, but i got was you get to dead and stand there.

would be great if it worked, i think its the best idea ever
 
I get this error
and the player just stands there after dead

[27/05/2010 02:16:08] [Error - CreatureScript Interface]
[27/05/2010 02:16:08] data/creaturescripts/scripts/pvparena.lua:eek:nPrepareDeath
[27/05/2010 02:16:08] Description:
[27/05/2010 02:16:08] data/creaturescripts/scripts/pvparena.lua:30: attempt to index field 'arenaFrom' (a nil value)
[27/05/2010 02:16:08] stack traceback:
[27/05/2010 02:16:08] data/creaturescripts/scripts/pvparena.lua:30: in function <data/creaturescripts/scripts/pvparena.lua:25>

[27/05/2010 02:16:09] [Error - CreatureScript Interface]
[27/05/2010 02:16:09] data/creaturescripts/scripts/pvparena.lua:eek:nPrepareDeath
[27/05/2010 02:16:09] Description:
[27/05/2010 02:16:09] (luaGetThingPosition) Thing not found


And it keeps rolling lol, anyway, hope it helps u get your script fixed,

(0.3.6)
 
Your work really doesn't get the appreciation it deserves dude, great work ;).

Might use this on my custom map, rep++.
 
Back
Top