• 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 change this script

sallem

Member
Joined
Nov 18, 2024
Messages
20
Reaction score
14
It would be possible to configure it to steal life and mana instead of critical?



creaturescripts.xml


<!-- CRITICAL SYSTEM -->
<event type="statschange" name="critical" event="script" value="critical.lua"/>
creaturescripts\scripts\login.lua
--- CRITICAL SYSTEM ----
registerCreatureEvent(cid, "critical")
if getPlayerStorageValue(cid, 48903) == -1 then
setPlayerStorageValue(cid, 48903, 0)
end






creaturescripts\scripts\critical.lua:


-----[[Critical System
by Night Wolf]]


local lvlcrit = 48903
local multiplier = 1.5






function onStatsChange(cid, attacker, type, combat, value)
if (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) and isPlayer(attacker) and isCreature(cid) then
if (getPlayerStorageValue(attacker, lvlcrit)*3) >= math.random (0,1000) then
value = math.ceil(value*(multiplier))
doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
doSendAnimatedText(getCreaturePos(attacker), "CRITICAL!!", 144)
return false
end
end
return true
end



actions.xml:
<action itemid="1294" script="criticalrock.lua"/>


actions\scripts\criticalrock.lua:
--- CRITICAL System by Night Wolf



local config = {
effectonuse = 14, --
levelscrit = 100, ---
storagecrit = 48903 -- storage
}

function onUse(cid, item, frompos, item2, topos)
if getPlayerStorageValue(cid, config.storagecrit) < config.levelscrit then
doRemoveItem(item.uid, 1)
doSendMagicEffect(topos,config.effectonuse)
doPlayerSendTextMessage(cid,22,"You've Leveled your Critical Skill to ["..(getPlayerStorageValue(cid, config.storagecrit)+1).."/100].")
setPlayerStorageValue(cid, config.storagecrit, getPlayerStorageValue(cid, config.storagecrit)+1)
elseif getPlayerStorageValue(cid, config.storagecrit) >= config.levelscrit then
doPlayerSendTextMessage(cid,22,"You've already reached the MAX level of Critical Skill.\nCongratulations!!!!")
return 0
end
return 1
end
 
Last edited:
Please use the code button to add code to your posts, it makes it very difficult for us to read the code and be helpful to you when it looks this messy, do the extra step so that we don't have to if you're requesting help please.
 
didn't work here.
What didn't work? Show your code that you attempted so that we can guide you... If you're not looking to learn and you're just looking to have people create code for you, put it in the requests section and offer to pay people. Someone will gladly do it for money.
 
--[[Critical System By Night Wolf]]

local lvlcrit = 48913
local multiplier = 1.5
local efect = 26 ---

function onStatsChange(cid, attacker, type, combat, value)
if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS and isCreature(attacker) then
if (getPlayerStorageValue(attacker, lvlcrit)*3) >= math.random (0,1000) then
dano = math.ceil(value*(multiplier))
doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
doCreatureAddHealth(attacker, -value)
doSendMagicEffect(getCreaturePos(cid), efect)
return false
end
end
return true
end
error in function "onStatsChange"
 
Can you copy the error? What server and version of the server are you using? Does this work without doCreatureAddHealth function?

Also, this was an example of what to use, the way that you calculate your values should be based on how much health you want the player to gain when leaching life.
 
Can you copy the error? What server and version of the server are you using? Does this work without doCreatureAddHealth function?

Also, this was an example of what to use, the way that you calculate your values should be based on how much health you want the player to gain when leaching life.
error when player critically hits target :

[26/11/2024 15:32:52] [Error - CreatureScript Interface]
[26/11/2024 15:32:52] data/creaturescripts/scripts/critical.lua:onStatsChange
[26/11/2024 15:32:52] Description:
[26/11/2024 15:32:52] data/creaturescripts/scripts/critical.lua:9: attempt to perform arithmetic on a boolean value
[26/11/2024 15:32:52] stack traceback:
[26/11/2024 15:32:52] data/creaturescripts/scripts/critical.lua:9: in function <data/creaturescripts/scripts/critical.lua:7>
[26/11/2024 15:32:52] [C]: in function 'doCreatureAddHealth'
[26/11/2024 15:32:52] data/creaturescripts/scripts/critical.lua:12: in function <data/creaturescripts/scripts/critical.lua:7>

tfs 0.3.6 8.6

I would like it to steal 15% of life from the damage caused.
 
In the error critical:9 means line 9, this appears to be getPlayerStorageValue(attacker, lvlcrit)
This implies that the player using this does not have a storage value for storage key 48913, you should add a check before this. But for now we can try the following

LUA:
//change
getPlayerStorageValue(attacker, lvlcrit)
//to
math.max(0, getPlayerStorageValue(attacker, lvlcrit))

with this, there will be a 0 percent chance for critical but it should stop error, then you need to give the player storage for that key.
 
In the error critical:9 means line 9, this appears to be getPlayerStorageValue(attacker, lvlcrit)
This implies that the player using this does not have a storage value for storage key 48913, you should add a check before this. But for now we can try the following

LUA:
//change
getPlayerStorageValue(attacker, lvlcrit)
//to
math.max(0, getPlayerStorageValue(attacker, lvlcrit))

with this, there will be a 0 percent chance for critical but it should stop error, then you need to give the player storage for that key.

erro:

[26/11/2024 21:36:54] [Error - CreatureScript Interface]
[26/11/2024 21:36:54] data/creaturescripts/scripts/critical.lua:onStatsChange
[26/11/2024 21:36:54] Description:
[26/11/2024 21:36:54] data/creaturescripts/scripts/critical.lua:9: bad argument #2 to 'max' (number expected, got boolean)
[26/11/2024 21:36:54] stack traceback:
[26/11/2024 21:36:54] [C]: in function 'max'
[26/11/2024 21:36:54] data/creaturescripts/scripts/critical.lua:9: in function <data/creaturescripts/scripts/critical.lua:7>
[26/11/2024 21:36:54] [C]: in function 'doCreatureAddHealth'
[26/11/2024 21:36:54] data/creaturescripts/scripts/critical.lua:12: in function <data/creaturescripts/scripts/critical.lua:7>
 
try to switch getPlayerStorageValue with getCreatureStorage, for some reason it's returning false instead of -1, we may need to modify your lib.
 
try to switch getPlayerStorageValue with getCreatureStorage, for some reason it's returning false instead of -1, we may need to modify your lib.
I did as you said and got this error


[26/11/2024 22:49:36] [Error - CreatureScript Interface]
[26/11/2024 22:49:36] data/creaturescripts/scripts/critical.lua:onStatsChange
[26/11/2024 22:49:36] Description:
[26/11/2024 22:49:36] data/creaturescripts/scripts/critical.lua:9: bad argument #2 to 'max' (number expected, got boolean)
[26/11/2024 22:49:36] stack traceback:
[26/11/2024 22:49:36] [C]: in function 'max'
[26/11/2024 22:49:36] data/creaturescripts/scripts/critical.lua:9: in function <data/creaturescripts/scripts/critical.lua:7>
[26/11/2024 22:49:36] [C]: in function 'doCreatureAddHealth'
[26/11/2024 22:49:36] data/creaturescripts/scripts/critical.lua:12: in function <data/creaturescripts/scripts/critical.lua:7>
 
Wrap it in if statement

If(getCreatureStorage(attacker, lvlcrit)) then
Now he critically attacked and went to the temple, it worked but killed the player.
and it only works on creatures with the event tag, it doesn't work on creatures without the tag.

error that occurs when you hit the critical : [Error - CreatureEvent::executeStatsChange] Call stack overflow.

script:
local lvlcrit = 48903
local multiplier = 1.5






function onStatsChange(cid, attacker, type, combat, value)
if (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) and isPlayer(attacker) and isCreature(cid) then
if(getCreatureStorage(attacker, lvlcrit)) then
value = math.ceil(value*(multiplier))
doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
doCreatureAddHealth(attacker, -value)
doSendAnimatedText(getCreaturePos(attacker), "CRITICAL!!", 144)
return false
end
end
return true
end
 
Remove the - in front of value. Are you trying at all to attempt these repairs yourself? That’s simple math, - means subtract. My mistake for leaving it there when I sent it but that’s a really simple one. Please at least make attempts or I’ll just stop helping.
 
give up the previous script
is it possible to change this to tfs 0.3.6 ?


weapon :

function onTargetCreature(creature, target)
return target:registerEvent("lifesteal")
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, 1)
combat:setParameter(COMB, COMBAT_PHYSICALDAMAGE)
combat:setFormula(COMBAT_FORMULA_SKILL, 0, 0, 1.0, 0)
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onUseWeapon(player, variant)
return combat:execute(player, variant)
end

creaturescripts/creaturescripts.xml

<event type="healthchange" name="lifesteal" script="lifesteal.lua"/>

creaturescripts/scripts/lifesteal.lua


local cfg = {
weaponId = 16162,
chance = 10,
percent = 10
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
local damage = primaryDamage + secondaryDamage
if attacker:isPlayer() then
if math.random(100) <= cfg.chance then
local weapon = attacker:getSlotItem(CONST_SLOT_LEFT)
if weapon and weapon:getId() == cfg.weaponId then
attacker:addHealth(damage * (cfg.percent/100))
end
end
end
creature:unregisterEvent("lifesteal")
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
@sallem @samuel157
You never learn, do you? It’s just a simple script! If you have some free time, take it to study and learn how to do what you want. Seriously, you’ve made over a million requests with different accounts and got banned several times. Have some shame and study Lua!

If you're using TFS 1.x, I’ll help, but if it’s TFS 0.3.6, I won’t—no one will, honestly. It’s too outdated, and getting help for it is nearly impossible.
 
Back
Top