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

Solved How can I update player's hp after using setCreatureMaxHealth?

Ramirez

New Member
Joined
Apr 11, 2013
Messages
19
Reaction score
0
Hey

LUA:
setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+100)

Is there a way to update player's health at the same time? I can't see any change before using some spell for example exura.
 
Last edited:
Yeah but it also adds the bonus hp. It's not what I meant. I don't want to heal the player after changing his hp.
 
Last edited:
Just add 1 health and then remove it?
I do not even know what you want to update because max health should work just fine..
 
Yeah can you explain what this function is supposed to do? Are you using it on a player? Or a monster or what?

Ok I will try to explain it more.

I'm using spell "transform". This spell is suppose to change player's vocation, outfit and add bonus hp and mana.

part of this spell is:
LUA:
if (getPlayerVocation(cid) == 1) and (getPlayerLevel(cid) >= 50) then
	doPlayerSetVocation(cid,2)
	doSetCreatureOutfit(cid, {lookType=31}, -1)
	setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+200)
	setCreatureMaxMana(cid, getCreatureMaxMana(cid)+100)
	doSendMagicEffect(getCreaturePosition(cid), 14)
end

When i type "transform" my character is changing from
a21GhF2.png
to
7zvQsZB.png
but the health is staying the same after using the spell
nYgK0dx.png


To update it I have to use spell for example "gran aura" (healing spell).
JlkhmL0.png
When I do that the health is changing.
nSoPXTf.png


I want hp/mana to update immediately after I use "transform".


Just add 1 health and then remove it?
If I add 1 health and then remove it I will get battle condition which I don't want.
 
Last edited:
What if player is already in battle? I don't want to remove it in this case.

and stop doing anime-based otservers, their sprites are flat and terrible
I just do it for fun while trying to learn how to create spells etc :) It's for my personal use.
 
Last edited:
as Defeater said

doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
doCreatureAddMana(cid, getCreatureMaxMana(cid), false)

this will update the hp just like a spell would

but I'm not clear if your screen shots are posted correctly? but basically if you use the spell to transform it transforms and what not but does not give the player the extra hp visably in client?

like it's supposed to turn 1000 into 1200? but it doesn't? unless you use the spell, then when you use the spell it makes your mana 90 lower?

looks like a bug to me...
 
LUA:
local state = getCreatureCondition(cid, CONDITION_INFIGHT)
-- do your transform stuff
-- set max health / mana
-- add 1 health / mana then remove it, if full health / mana remove 1 health / mana then add it
if not state then
    doRemoveCondition(cid, CONDITION_INFIGHT)
end
 
as Defeater said

doCreatureAddHealth(cid, getCreatureMaxHealth(cid), false)
doCreatureAddMana(cid, getCreatureMaxMana(cid), false)

this will update the hp just like a spell would

but I'm not clear if your screen shots are posted correctly? but basically if you use the spell to transform it transforms and what not but does not give the player the extra hp visably in client?

like it's supposed to turn 1000 into 1200? but it doesn't? unless you use the spell, then when you use the spell it makes your mana 90 lower?

looks like a bug to me...

I think you have misunderstood what I meant or maybe I asked a wrong question.

Before transform it should be like this:
1000/1000 hp
1000/1000 mana

After transform it should be like this:
1000/1200 hp
1000/1100 mana

After transform now:
1000/1000 hp
1000/1000 mana
while in database:
1000/1200 hp
1000/1100 mana

The problem is that the client is not displaying correct value of the maxhp/maxmana from database. That's why I had to use spell to update it.

I hope that it's clear now :rolleyes:

btw. Ignore that I had 990 mana and that my hp didn't go up after using "gran aura" (healing spell).
(I used spell "ryuken" (offensive spell - cost 10) instead of "gran aura" but I didn't update the image.)


- - - Updated - - -

LUA:
local state = getCreatureCondition(cid, CONDITION_INFIGHT)
-- do your transform stuff
-- set max health / mana
-- add 1 health / mana then remove it, if full health / mana remove 1 health / mana then add it
if not state then
    doRemoveCondition(cid, CONDITION_INFIGHT)
end

I will check it now.

edit:

LUA:
--Transform
function onCastSpell(cid, var)

if (getPlayerVocation(cid) == 1) and (getPlayerLevel(cid) >= 50) then
local state = getCreatureCondition(cid, CONDITION_INFIGHT)
	doPlayerSetVocation(cid,2)
	doSetCreatureOutfit(cid, {lookType=31}, -1)
	setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+200)
	setCreatureMaxMana(cid, getCreatureMaxMana(cid)+100)
	doCreatureAddHealth(cid, 1)
	doCreatureAddMana(cid, 1)
	doCreatureAddHealth(cid, -1, false)
	doCreatureAddMana(cid, -1, false)
if not state then
    doRemoveCondition(cid, CONDITION_INFIGHT)
end
elseif getPlayerLevel(cid) < 50 then
	doSendMagicEffect(getCreaturePosition(cid), 3)
	doPlayerSendCancel(cid, "You need 50 level to transform!")
elseif getPlayerVocation(cid) == 2 then
	doPlayerSendCancel(cid, "It's your last transform.")
end

return true
end

Works exactly as I wanted :)

The only problem is when i use "transform" I get this meesage: "18:26 You lose 1 hitpoint." Is there a way to hide it?
 
Last edited:
Either by adding a parameter to not display that message to the function or you can try to send a empty cancel or something afterwards.
 
The message doesn't show after
LUA:
doPlayerSendCancel(cid, "")
but it's still in Server Log.


I tried
LUA:
doCreatureAddHealth(cid, -1, false)
but it didn't work.
 
Yeah so I did understand correctly your distro isn't capable of it or you created a bug ... Because my distro it automatically makes hp 1200 to client not just in database without having to Relog character
 
I have no idea. It was just strange. Even if I relog it'd not make a difference. It would be still 1000/1000 instead of 1000/1200.

Anyway, thanks for help guys :)
 
Back
Top