• 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 new scripts randomly crash server

sharinn

Active Member
Joined
Aug 27, 2011
Messages
157
Solutions
8
Reaction score
43
GitHub
ArturKnopik
Twitch
krecikondexin
Hello, at the beginning I want to apologize to you for my English, I helped translator..
I need help to detect problem of random server crash, i adding 2 new spells and one weapon
probably one or all of them is a problem.. all of them use addEvent()
storageReseter.lua - used to reset storage when player die and addevent from other scripts try remove storage from unexisting player
on start i give onLogin function(register on player)
Code:
function onLogin(player)
    player:setStorageValue(1999, -1)
    player:setStorageValue(1991, -1)
return true
end
doubleCast.lua - rune to set storage... all spell check storage and set cooldown based on current storage (1991)
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

combat:setCondition(condition)
local player

local function resetStorage()
	if player:getStorageValue(1999) > -1 then
	   player:setStorageValue(1999, getPlayerStorageValue(player, 1999)-1)
	   end
end


local combat1 = Combat()
combat1:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_NONE)


local exhaustHealGroup = Condition(CONDITION_SPELLGROUPCOOLDOWN)
exhaustHealGroup:setParameter(CONDITION_PARAM_SUBID, 3)

local exhaust = Condition(CONDITION_EXHAUST_HEAL)
combat:setCondition(exhaust)

function onCastSpell(creature, var)

	player = Player(creature)
	
		if creature:getStorageValue(1999) > -1 then
			exhaustHealGroup:setParameter(CONDITION_PARAM_TICKS, 500)
			combat1:setCondition(exhaustHealGroup)
		else
			exhaustHealGroup:setParameter(CONDITION_PARAM_TICKS, 1000)
			combat1:setCondition(exhaustHealGroup)
		end
		player:addCondition(exhaustHealGroup)
	player = Player(creature)
	
	if creature:getStorageValue(1999) > -1 then
		exhaust:setParameter(CONDITION_PARAM_TICKS, 500)
	else
		exhaust:setParameter(CONDITION_PARAM_TICKS, 1000)
	end
	player:addCondition(exhaust)
	creature:say("Double Cast Speed!", TALKTYPE_MONSTER_SAY)

	setPlayerStorageValue(creature, 1999, getPlayerStorageValue(player, 1999)+1)

	addEvent(resetStorage, 20000)
	return combat:execute(creature, var)
end

utanaAni.lua - spell incresing atack speed if storage 1999 >-1

Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local condition = Condition(CONDITION_HASTE)
condition:setParameter(CONDITION_PARAM_TICKS, 100)
condition:setFormula(0, 0, 0, 0)
combat:setCondition(condition)

local player

local  function resetStorage()
	if player:getStorageValue(1991) > -1 then
		player:setStorageValue(1991, getPlayerStorageValue(player, 1991)-1)
		if player:getStorageValue(1991) == -1	then
			player:setAttackSpeed(player:getAttackSpeed()*2)
		end
	end
end

local exhaust = Condition(CONDITION_SPELLCOOLDOWN)
local combat1 = Combat()
combat1:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_NONE)


local exhaustHealGroup = Condition(CONDITION_SPELLGROUPCOOLDOWN)
exhaustHealGroup:setParameter(CONDITION_PARAM_SUBID, 1)

local exhaust = Condition(CONDITION_EXHAUST_COMBAT)
combat:setCondition(exhaust)


function onCastSpell(creature, var)
	
	player = Player(creature)
	
		if creature:getStorageValue(1991) > -1 then
			exhaustHealGroup:setParameter(CONDITION_PARAM_TICKS, 1000)
			combat1:setCondition(exhaustHealGroup)
		else
			exhaustHealGroup:setParameter(CONDITION_PARAM_TICKS, 2000)
			combat1:setCondition(exhaustHealGroup)
		end
		player:addCondition(exhaustHealGroup)
	creature:say("Speed!", TALKTYPE_MONSTER_SAY)
	if getPlayerStorageValue(player, 1991) == -1	then
		player:setAttackSpeed(player:getAttackSpeed()/2)
	end
	setPlayerStorageValue(creature, 1991, getPlayerStorageValue(player, 1991)+1)
	addEvent(resetStorage, 20000, var)
	combat:execute(creature, var)
	return true
end

TwinAxe.lua - custom weapon script
Code:
local combat1 = createCombatObject()
setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)



function onGetFormulaValues(player, skill, attack, factor)
	local skillTotal = (skill*4) * (attack/2)
	local levelTotal = player:getLevel() 
	return -(((skillTotal * 0.04) + 7) + (levelTotal/5)), -(((skillTotal * 0.07) + 11) + (levelTotal/5))
end

combat1:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
local player

local function resetStorage(var)
	if player then
	   doCombat(player, combat1, var)
	 end
end

function onUseWeapon(cid, var)
player = Player(cid)
	addEvent(resetStorage, player:getAttackSpeed()/2, var)
	return doCombat(player, combat1, var)
end
 
Solution
You should not store player object outside the function and try to execute it as a addEvent. Since then it become a dangling pointer.

E.g

Code:
local function printName(cid)
    local creature = Creature(cid)
    if creature then
        print(creature:getName())
    end
end

addEvent(printName, 5 * 1000, creature.uid)
you don't have to set storage = -1 because any storage in the server is -1 .. make it 0 .. i don't have time to read all this scripts
:(
 
Code:
local function resetStorage()
    if player:getStorageValue(1999) > -1 then
       player:setStorageValue(1999, getPlayerStorageValue(player, 1999)-1)
       end
end
this does make any sense :|
Code:
local function resetStorage()
    if player:getStorageValue(1999) > -1 then
       player:setStorageValue(1999, 1)
       end
 
in the database, the value of storage -1 is removed, other values are saved, and I followed these values in the database

Code:
local function resetStorage()
    if player:getStorageValue(1999) > -1 then
       player:setStorageValue(1999, getPlayerStorageValue(player, 1999)-1)
       end

I use this form so that when the spell / run effect is extended, the effect does not disappear after finishing the first one.
For example: I use double rune, after 10 seconds I extend its effect and I want it to end after 20 seconds and not after the first one.
Earlier, I removed this effect in the following way:
Code:
local function resetStorage()
       player:setStorageValue(1999, -1)
end


the script above unfortunately ended the effect after the first one ended, the next effect did not increase the effect time
 
You should not store player object outside the function and try to execute it as a addEvent. Since then it become a dangling pointer.

E.g

Code:
local function printName(cid)
    local creature = Creature(cid)
    if creature then
        print(creature:getName())
    end
end

addEvent(printName, 5 * 1000, creature.uid)
 
Solution
All my scripts should look like this one?
Code:
local combat1 = createCombatObject()
setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(player, skill, attack, factor)
    local skillTotal = (skill*4) * (attack/2)
    local levelTotal = player:getLevel()
    return -(((skillTotal * 0.04) + 7) + (levelTotal/5)), -(((skillTotal * 0.07) + 11) + (levelTotal/5))
end

combat1:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local function secondDamage(cid, var)
    local creature = Creature(cid)
    if creature then
        doCombat(creature, combat1, var)
    end
end




function onUseWeapon(cid, var)
local player = Player(cid)
    addEvent(secondDamage,  player:getAttackSpeed()/2, cid.uid, var)
    return doCombat(player, combat1, var)
end
 
Yes, but if you already sending cid through the onUseweapon you do not need to write cid.uid enough with cid.

Here is a more clean version:
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(player, skill, attack, factor)
    local skillTotal = (skill*4) * (attack/2)
    local levelTotal = player:getLevel()
    return -(((skillTotal * 0.04) + 7) + (levelTotal/5)), -(((skillTotal * 0.07) + 11) + (levelTotal/5))
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local function secondDamage(id, variant)
    local player = Player(id)
    if player then
        combat:execute(player, variant)
    end
end

function onUseWeapon(player, variant)
    addEvent(secondDamage, player:getAttackSpeed() / 2, player.uid, variant)
    return combat:execute(player, variant)
end
 
Last edited:
Back
Top