• 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!

Lua function onStatsChange(cid, attacker, type, combat, value)

Potar

SocialWorld
Senator
Joined
Mar 1, 2009
Messages
1,661
Reaction score
125
Location
Warsaw, Poland
Hello, iam tired of make this script to work, it should be work but it doesn't and i can't do anythnig.

I want to make a simple script, when monster attack me (POFF) ill be moved to Temple, i tested with onAttack / onCombat / onPrepareDeath and i cant do this script, it doesn't work, please help me, its from Zombie Event.

LUA:
local config = {
    playerCount = 2001, -- Global storage for counting the players left/entered in the event
    moneyReward = {2160, 10, 1},
 
    -- Should be same as in the globalevent!
    -- The zombies will spawn randomly inside this area
    fromPosition = {x = 341, y = 465, z = 7}, -- top left cornor of the playground
    toPosition = {x = 424, y = 520, z = 7}, -- bottom right cornor of the playground
    }
 
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(cid) and isMonster(attacker) then
        if isInArea(getPlayerPosition(cid), config.fromPosition, config.toPosition) then
            if getGlobalStorageValue(config.playerCount) >= 2 then
                doBroadcastMessage(getPlayerName(cid) .. " have been kicked by Spider!", MESSAGE_STATUS_CONSOLE_RED)
                doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), false)
                doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
                setGlobalStorageValue(config.playerCount, getGlobalStorageValue(config.playerCount)-1)
            elseif getGlobalStorageValue(config.playerCount) == 1 then
                if isInArea(getPlayerPosition(cid), config.fromPosition, config.toPosition) then
                    doBroadcastMessage(getPlayerName(cid) .. " won the Survival event! Congratulations!", MESSAGE_STATUS_WARNING)
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                    doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), false)
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
                    if config.moneyReward[3] == 1 then
                        doPlayerAddItem(cid, config.moneyReward[1], config.moneyReward[2])
                    end
                end
 
                for x = config.fromPosition.x, config.toPosition.x do
                    for y = config.fromPosition.y, config.toPosition.y do
                        for z = config.fromPosition.z, config.toPosition.z do
                            areapos = {x = x, y = y, z = z, stackpos = 253}
                            getMonsters = getThingfromPos(areapos)
                            if isMonster(getMonsters.uid) then
                                doRemoveCreature(getMonsters.uid)
                            end
                        end
                    end
                end
            end
            return false
        end
    end
return true
end

REP for help guys.
 
try change

Code:
if isPlayer(cid) and isMonster(attacker) then

to

Code:
if isMonster(attacker) and type == STATSCHANGE_HEALTHLOSS then
 
LUA:
local config = {
    playerCount = 2001, -- Global storage for counting the players left/entered in the event
    reward = {true,2160,10},
    pos = {{x = 341, y = 465, z = 7},{x = 424, y = 520, z = 7}}
    }
function removeM()
                         for x = config.pos[1].x, config.pos[2].x do
                         for y = config.pos[1].y, config.pos[2].y do
                          local pos = {x=x, y=y, z=config.pos[1].z}
                           local m = getTopCreature(pos).uid
                            if m ~= 0 and isMonster(m) then 
				doRemoveCreature(m) 
					end
                            end
       end
end
function onStatsChange(cid, attacker, type, combat, value)
		if isMonster(attacker) and isPlayer(cid) and isInArea(getPlayerPosition(cid), config.pos[1], config.pos[2]) then
		if getGlobalStorageValue(config.playerCount) == 1 and config.reward[1] == true then 
			doPlayerAddItem(cid, config.reward[2], config.reward[3]) 
				removeM()
		end
		doBroadcastMessage(getPlayerName(cid) .. " "..(getGlobalStorageValue(config.playerCount)  == 1 and "won the Survival event! Congratulations" or "have been kicked by Spider").."!")
		setGlobalStorageValue(config.playerCount, getGlobalStorageValue(config.playerCount)-1)
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                    doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), false)
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
		end
return true
end

register in login.lua too
 
LUA:
local config = {
    playerCount = 2001, -- Global storage for counting the players left/entered in the event
    reward = {true,2160,10},
    pos = {{x = 341, y = 465, z = 7},{x = 424, y = 520, z = 7}}
    }
function removeM()
                         for x = config.pos[1].x, config.pos[2].x do
                         for y = config.pos[1].y, config.pos[2].y do
                          local pos = {x=x, y=y, z=config.pos[1].z}
                           local m = getTopCreature(pos).uid
                            if m ~= 0 and isMonster(m) then 
				doRemoveCreature(m) 
					end
                            end
       end
end
function onStatsChange(cid, attacker, type, combat, value)
		if isMonster(attacker) and isPlayer(cid) and isInArea(getPlayerPosition(cid), config.pos[1], config.pos[2]) then
		if getGlobalStorageValue(config.playerCount) == 1 and config.reward[1] == true then 
			doPlayerAddItem(cid, config.reward[2], config.reward[3]) 
				removeM()
		end
		doBroadcastMessage(getPlayerName(cid) .. " "..(getGlobalStorageValue(config.playerCount) == 1 and "won the Survival event! Congratulations" or "have been kicked by Spider").."!")
		setGlobalStorageValue(config.playerCount, getGlobalStorageValue(config.playerCount)-1)
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                    doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), false)
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
		end
return true
end


Crash:
Segmentation fault
 
LUA:
local config = {
    playerCount = 2001, -- Global storage for counting the players left/entered in the event
    reward = {true,2160,10},
    pos = {{x = 341, y = 465, z = 7},{x = 424, y = 520, z = 7}}
    }
function removeM()
                         for x = config.pos[1].x, config.pos[2].x do
                         for y = config.pos[1].y, config.pos[2].y do
                          local pos = {x=x, y=y, z=config.pos[1].z}
                           local m = getTopCreature(pos).uid
                            if m ~= 0 and isMonster(m) then 
				doRemoveCreature(m) 
					end
                            end
       end
end
function onStatsChange(cid, attacker, type, combat, value)
		if isCreature(attacker) and isMonster(attacker) and isInArea(getCreaturePosition(cid), config.pos[1], config.pos[2]) then
		if getGlobalStorageValue(config.playerCount) == 1 and config.reward[1] == true then 
			doPlayerAddItem(cid, config.reward[2], config.reward[3]) 
				removeM()
		end
		                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
                    doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), false)
                    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
		doBroadcastMessage(getPlayerName(cid) .. " "..(getGlobalStorageValue(config.playerCount) == 1 and "won the Survival event! Congratulations" or "have been kicked by Spider").."!")
		setGlobalStorageValue(config.playerCount, getGlobalStorageValue(config.playerCount)-1)
		return false
		end
return true
end
 
Back
Top