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

My First Script Dont Work :-(

MagicHereos

Magic.org.pl
Joined
Nov 6, 2008
Messages
60
Reaction score
0
Hello !
I wrote my first script and it... dont work :(
movements - hp.lua :
Code:
function onStepIn(cid, item, pos)
local hp = getPlayerHealth(uid)
if(pos.x == 814) and (pos.y == 1112) and (pos.z == 7)
then
doPlayerSendTextMessage(cid, 19, "Czujesz ukojenie") and doPlayerAddHealth(uid,hp)
doSendAnimatedText(x=814 y=1112 z=7,Przekraczajac bramy rookguardu, czujesz ukojenie...,8)
end
retun 1
end
And movements :
Code:
<movevent event="StepIn" uniqueid="9213" script="hp.lua" />
And I have this error :

[01/01/2004 20:48:41] data/movements/scripts/hp.lua:2: attempt to call global 'getPlayerHealth' (a nil value)
[01/01/2004 20:48:41] stack traceback:
[01/01/2004 20:48:41] data/movements/scripts/hp.lua:2: in function <data/movements/scripts/hp.lua:1>
[/code]
:blink::blink:
What I should to give to place of getPlayerHealth?( : Or meaby I have any mistake (error) in it?
Sorry for my English, but i learn it now :p
Thanks,
Magic
 
And you wrote "retun 1" :p, why getCreatureHealth(uid)? It should be cid! I see meaning of this script, it should set full hp right? But it simply adds ammount of hp that player has. Ex. player have 100hp, max hp is 500. After script is launched, he receives 100hp+, so he will have 200 out of 500. I made that he is fully healed.

Player is healed without limit, so he can "go through rook gate" million times >.>" so I will add storage value, that he is healed only once.

Then I have added some magic effects which will make script nicier :D

Code:
function onStepIn(cid, item, pos)
local hp = getCreatureHealth(cid)
local max = getCreatureMaxHealth(cid)
local add = max - hp
local storage = 34652

if(pos.x == 814) and (pos.y == 1112) and (pos.z == 7) and (getPlayerStorageValue(cid, storage) == -1) then
doPlayerSendTextMessage(cid, 19, "Przekraczajac bramy rookgaardu czujesz ukojenie...") and doPlayerAddHealth(uid, add)
setPlayerStorageValue(cid, storage, 1)
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
else
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
end
return 1
end

Also fixed literal errors.
 
Last edited:
And now I make better (If monster = Ded)
And this now dont work too :| :
Code:
function onStepIn(cid, item, pos)
local hp = getCreatureHealth(cid)
if isPlayer(uid) ~= TRUE
and
(pos.x == 814) and (pos.y == 1112) and (pos.z == 7)
then
doPlayerSendTextMessage(cid, 19, "Czujesz ukojenie")
doCreatureAddHealth(cid,hp)
doSendAnimatedText({x=814, y=1112, z=7}, "Hail Gelio",8)
end
else
doCreatureAddHealth(uid,-300)
doSendAnimatedText({x=814, y=1112, z=7}, "Gin !!!",9)
return 1
end
What I should to do?:(
Ohh and Error in console :
Code:
[02/01/2004  11:23:30] Warning: [Event::loadScript] Can not load script. data/movements/scripts/hp.lua
[02/01/2004  11:23:30] data/movements/scripts/hp.lua:11: 'end' expected (to close 'function' at line 1) near 'else'
Help, please
PS. How to give rep+ to anybody?: )
 
Code:
function onStepIn(cid, item, pos)
local hp = getCreatureHealth(cid)
local max = getCreatureMaxHealth(cid)
local add = max - hp

  if isPlayer(cid) ~= TRUE and (pos.x == 814) and (pos.y == 1112) and (pos.z == 7) then
    doPlayerSendTextMessage(cid, 19, "Czujesz ukojenie")
    doCreatureAddHealth(cid, add)
    doSendAnimatedText(playerPos, "Hail Gelio",8)
  else
    doPlayerSendTextMessage(cid, 19, "Niestety nie jest to mozliwe.")
  end
  return 1
end
 
check this

Code:
function onStepIn(cid, item, pos)
local hp = getCreatureHealth(cid)
local max = getCreatureMaxHealth(cid)
local ahp = local add = max - hp
local storage = 34652
local poss = getCreaturePosition(cid)

if isPlayer(cid) ==TRUE and {poss.x == 814, poss.y == 1112, poss.z == 7} and (getPlayerStorageValue(cid, storage) == -1) then
doPlayerSendTextMessage(cid, 19, "Przekraczajac bramy rookgaardu czujesz ukojenie...")
doPlayerAddHealth(cid, ahp)
setPlayerStorageValue(cid, storage, 1)
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
else
doPlayerAddHealth(cid,-(getCreatureMaxHealth))
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
end
return 1
end
 
Last edited:
PHP:
function onStepIn(cid, item, pos)
    local playerPos = getCreaturePosition(cid)
    
    if playerPos.x == pos.x and playerPos.y == pos.y and playerPos.z = pos.z then
        if isPlayer(cid) == TRUE then
            doPlayerSendTextMessage(cid, 24, "Your health was restored to its maximum value.")
            doCreatureAddHealth(cid, (getCreatureMaxHealth(cid) - getCreatureHealth(cid)))
        else
            doCreatureAddHealth(cid, -(getCreatureMaxHealth(cid)))
        end
    end
    
    return TRUE
end
 
PHP:
-- By Magic
-- Help by Gelio (EDITED ERROR)
-- Help by Macroman (HELP)
function onStepIn (cid, item, pos)
	local ppos = getCreaturePosition(cid)
	if ppos.x == pos.x and ppos.y == pos.y and ppos.z == pos.z then
		if isPlayer(cid) == TRUE then
			doCreatureAddHealth(cid,(getCreatureMaxHealth(cid) - getCreatureHealth(cid)))
			doCreatureSendTextMessage(cid,24,"Your health are new...")
		else
			doCreatureAddHealth(cid,-(getCreatureMaxHealth(cid)))
		end
	end
			return TRUE
end
@UP
Thanks, I look you post, read it, and rewrite my script !
Rep+
 
I wrote new script - wall deleted. Code :
PHP:
function onUse (cid, item, frompos, item2, topos)
local sciana = {x=621, y=1177, z=7}
local mwall = getThingFromPos(sciana)
if isPlayer(cid) == 1 then
if item.actionid(cid) == 2345 and item.itemid == 1945 and mwall.itemid == 1945 then
doRemoveItem(mwall.uid,1)
end
else
if item.uid == 2345 and item.id == 1946 then
doCreateItem(1026,1,sciana)
else
doPlayerSendTextMessage(cid,22,"Sorry, not possible.")
end
return 1
end
end
In anctions.xml
PHP:
	<action itemid="2345" script="wall.lua" />
	<action itemid="2346" script="wall.lua" />
Help me !
(Script should delete wall, and next create it (when you use switch))
Thanks,
Magic
 
Use an uniqueid/actionid on the lever, any of your choice.
PHP:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local stonePos = { x = 621, y = 1177 , z = 7, stackpos = 1 }
    
    if item.itemid == 1945 then
        doRemoveItem(getThingfromPos(stonePos).uid, 1)
    elseif item.itemid == 1946 then
        doCreateItem(1026, 1, stonePos)
    end
    return TRUE
end

EDIT: I removed the "is-it-a-player" check as theres no need. Players are the only ones who may pull a lever, lmao.
 
Are you using 0.2? If so, change this line.
PHP:
function onUse(cid, item, fromPosition, itemEx, toPosition)
to:
PHP:
function onUse(cid, item, frompos, item2, topos)
 
This should work, also put 5000 on the tile(uid)

PHP:
function onStepIn(cid, item, pos, fromPosition)

local hp = getCreatureHealth(cid)
if item.uid == 5000 then

doPlayerSendTextMessage(cid, 19, "Czujesz ukojenie") and doCreatureAddHealth(cid, hp)
doSendAnimatedText(getPlayerPosition(cid), Przekraczajac bramy rookguardu, czujesz ukojenie...,8)
end
retun TRUE
end

This dont delete wall it is the first script you requested ;)
 
My old script to POI :D, unoptimized a bit so it will take some time to configure it ;P but it's working for me.

Code:
function onUse(cid, item, frompos, item2, topos)
-- position of wall
wallpos = {x=915, y=1273, z=10, stackpos=1}
getwall = getThingfromPos(wallpos)
-- change item.uid to unique id of lever, and getwall.itemid to id of wall
if item.uid == 10256 and item.itemid == 1945 and getwall.itemid == 1304 then
doRemoveItem(getwall.uid,1)
doTransformItem(item.uid,item.itemid+1)
-- change item.uid to unique id of lever
elseif item.uid == 10256 and item.itemid == 1946 and getwall.itemid == 0 then
-- change 1304 to id of wall
doCreateItem(1304,1,wallpos)
doTransformItem(item.uid,item.itemid-1)
else
doPlayerSendCancel(cid,"Sorry not possible.")
end
return 1
end
 
@UP
Thanks, I read you post, and rewrite my script, this :
PHP:
-- Script by Magic
-- Thanks for help, Hermes of OTLand,
-- This script is for MagicOTS
function onUse(cid, item, frompos, item2, topos) 
local wallpos = {x = 612, y = 1177, z = 7, stackpos=1}
local wall = getThingformPos(wallpos)
if item.uid == 2345 and item.itemid == 1945 and wall.itemid == 1026 then
doRemoveItem(wall.uid)
doTransformerItem(item.id, item.itemid+1)
elseif item.uid == 2345 and item.itemid == 1946 and wall.itemid == 0 then
doCreateItem(1026,1,wallpos)
doTransformerItem(item.id, item.itemid-1)
else
doPlayerSendMessage(cid,22,"Sorry, not posible")
end
return 1
end
And in actions.xml :
PHP:
	<action itemid="2345" script="wall.lua" />
And script dont work :(
Code:
14:46 You see a switch.
ItemID: [1945].
ActionID: [2345].
Position: [X: 610] [Y: 1178] [Z: 7].

Code:
14:46 You see a brick wall.
ItemID: [1026].
Position: [X: 612] [Y: 1177] [Z: 7].
 
Last edited:
Back
Top