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

just starting scripting

tnecniiv

scripter to be
Joined
Jan 6, 2012
Messages
294
Solutions
3
Reaction score
23
hey so i am just diving into the scripting world.
but how do i add scripts to my server i have this lever command that i found on otland buuuuuuut they dont explain how to add it in the game could i get some info please and thank you

the point on this command is to remove a wall (i preferred a certain rock) but i have no idea how to add it into my game. please send help thanks a plenty.

function onUse(cid, item, frompos, item2, topos)

local wallpos1 = {x=599, y=619, z=8, stackpos=1} ---
local wall1 = getThingfromPos(wallpos1)
local wallID = 1028 --- item id of the wall to be removed ---


if item.itemid == 1945 then

doRemoveItem(wall1.uid, 1)
doTransformItem(item.uid, 1946)

elseif item.itemid == 1946 then

doCreateItem(wallID, 1, wallpos1)
doTransformItem(item.uid, 1945)

end

return TRUE
end
 
use code tags please
actions.xml to activate scripts

Code:
-- Takes x, y, z as required arguments and stackpos as an optional argument, and returns a position table {x, y, z[, stackpos]}
local function Position(x, y, z, stackpos)
    return {x = x, y = y, z = z, stackpos = stackpos or 0}
end

local wallPosition = Position(599, 619, 8, 1)
local wall = getThingfromPos(wallpos1)

function onUse(cid, item, fromPosition, itemEx, toPosition) 
    if item.itemid == 1945 then 
        doRemoveItem(wall.uid, 1) 
    elseif item.itemid == 1946 then 
        doCreateItem(1028, 1,  wallPosition) 
    end 
    -- Fancy way of saying if item.itemid == 1945 then 1946 else 1945 (or is 'else', and is 'then')
    doTransformItem(item.uid, (item.itemid == 1945) and 1946 or 1945)
    return true
end
 
i apologize you have to realize i am really new to all this. this is just a code i found on google and was hoping to get insight on how to add it in game. i can do spells but actions in games im still learning.
 
i apologize you have to realize i am really new to all this. this is just a code i found on google and was hoping to get insight on how to add it in game. i can do spells but actions in games im still learning.
The code you posted goes into your actions/scripts folder. Save it as a .lua file.

Open actions.xml in your actions/ folder. In this file you will actually call the .lua script and coordinate it with an "action ID" or "unique ID". For example:
Code:
<action uniqueid="2906" script="anni2lever.lua" />

As you can see in this example I used a unique ID. These are better suited for things like levers or an action that will only apply to one thing. Action ID is better for things you will use multiple times, in different areas.
Now you need to go into your RME map editor and place the lever wherever you want it on the map. Now right click it, assign it the same uniqueID that is in actions.xml (2906).

Should work if your script is good :)
 
thank you so much
this helps a lot could you also make it possble that a countdown happen and it resets the wall back to normal?
im sorry to burden but it all helps
 
To make it a little bit easier, let's talk noob. :p

To put stuff into "code tags" do this. (without dots)
[.code] words here [./code]
Code:
words here

To install your code, first you need to know what folder it goes into.
To figure that out is usually easy.
Just check what type of function it is.
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
When you see an onUse function, it is an action script.
An action script is an object/item that you use, and then it does something.
Action scripts go into data/actions/scripts

When you are saving scripts for your server, make sure you save them as a LUA document.

Unfortunately the script you found is a little buggy, so I'll quickly fix it up, and add the additional count-down that you wanted.

data/actions/scripts/remove_wall_plus_timer.lua
Code:
local config = {
    wall_id = 1111
    wall_position = {x = 1000, y = 1000, z = 7}
    wall_timer = 15 -- counts in seconds
}

local function reset(pos)
    doTransformItem(getTileItemById(pos, 1946).uid, 1945)
    doCreateItem(wall_id, 1, wall_position)
end

local function countdown(cid, pos, n)
    n = n - 1
    doCreatureSay(cid, n, TALKTYPE_ORANGE_1, nil, nil, toPosition)
    if n > 0 then
        addEvent(countdown, 1000, cid, pos, n)
    end
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

    -- check if lever is currently used
    if item.itemid == 1946 then
        doSendMagicEffect(toPosition, CONST_ME_POFF)
        return doPlayerSendTextMessage(cid, 22, "Wait for switch to reset.")
    end

    -- remove wall
    doTransformItem(getTileItemById(config.wall_position, config.wall_id).uid, 0)

    -- countdown timer
    addEvent(countdown, 0, cid, toPosition, config.wall_timer)

     
    -- transform lever, and add reset for wall+lever
    doTransformItem(item.uid, item.itemid + 1)
    addEvent(reset, config.wall_timer * 1000, toPosition)

    return true
end

Now that you have your script, you'll want to install it into actions.xml
Actions.xml is how you register the script, so the server can load it.

As stated above, UniqueID (uid) is used when the script will only be used in 1 spot on the server, whereas ActionID (aid) is when it will be used in multiple spots.

so put this line into actions.xml

data/actions/actions.xml (45001 can be changed to ANY open value, not currently being used in the server.)
Code:
<action uniqueid="45001" event="script" value="remove_wall_plus_timer.lua"/>

Now the script is registered in the server.

Last step is configuring the script and the map to work together.

Open your map, place down a lever (item_id = 1945), and open it's properties to give it a UniqueID (uid) the same as in your actions.xml.
Make sure the wall_id & wall_pos are correct in the script..
Then save the map, reload server and Test your new script.

:)
 
there are 3 ways you can register a script in actions
Code:
<action itemid="1111" script="x.lua"/>
<action actionid="1111" script="x.lua"/>
<action uniqueid="1111" script="x.lua"/>
itemid registers the corresponding script to the item itself
action and uniqueid registers it to certain clickable things that have the actionid/uniqueid defined

yes, you are able to use a countdown with the addEvent() function
addEvent takes 2 mandatory arguments (function callback and millisecond delay)
the rest are arguments to your function callback
example of an addEvent:
i made a cool picture for you my friend
Y61aDq6.png
 
Back
Top