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

After looking in lua tutorials I made a script.

Mithaz

Nightimp Mapper/Scripter
Joined
Nov 7, 2007
Messages
120
Reaction score
1
Location
Sweden
Hello.
I have read some tutorials after some tips and hints when i made a script.
Now i made a new intressting script and think i done it right :D

Can some one check it fast and tell me if i made it right this time? :D
Lua:
-- Script made by Mithaz
-- Date : 2011 - 01/13
-- Vocation Teleport Tile

local config = {

	action = 10007,
	newPos = { x = 1176, y =199 , z =7 },
	playerPos = getCreaturePosition(cid),
	voc = 4

}

function onStepIn(cid, item, frompos, itemEx, topos)
		if item.actionid == config.action and getPlayerVocation(cid) == config.voc then
			DoTeleportThing(cid, config.newPos, false)
		else 
			config.playerPos.x - 1
			DoTeleportThing(cid, config.playerPos, false)
			DoPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have to be a warrior to get teleported to the warriors armory.")
		end

end

Thanks for all help and tips!
 
Code:
-- Script made by Mithaz
-- Date : 2011 - 01/13
-- Vocation Teleport Tile
 
local config = {
 
[B][COLOR=blue]    action = 10007,[/COLOR][/B]
    newPos = { x = 1176, y =199 , z =7 },
    playerPos = [COLOR=red][B]getCreaturePosition(cid),[/B][/COLOR]
    voc = 4
 
}
 
function onStepIn(cid, item, frompos, itemEx, topos)
        if [B][COLOR=blue]item.actionid == config.action[/COLOR][/B] and getPlayerVocation(cid) == config.voc then
            [B][COLOR=red]DoTeleportThing[/COLOR][/B](cid, config.newPos, [COLOR=blue][B]false[/B][/COLOR])
        else 
            config.playerPos.x - 1
            [B][COLOR=red]DoTeleportThing[/COLOR][/B](cid, config.playerPos, [COLOR=blue][B]false[/B][/COLOR])
            [COLOR=red][B]DoPlayerSendTextMessage[/B][/COLOR](cid, MESSAGE_INFO_DESCR, "You have to be a warrior to get teleported to the warriors armory.")
        end
 
end
not necessary
will give error


suggested:
Lua:
-- Script made by Mithaz
-- Date : 2011 - 01/13
-- Vocation Teleport Tile
 
local config = { 
    newPos = {x=1176, y=199, z=7},
}
 
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if not isKnight(cid) then    
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have to be a warrior in order to get teleported to the warriors armory.')
        doTeleportThing(cid, fromPosition, true)
        return true
    end
    
    doTeleportThing(cid, config.newPos)
    return true
end
 
cid is declared only inside a function onStepIn(acroding to ur script). You cannot make a variable related local variable cid without calling another function within this param.

Suggested: ^^
Lua:
local newPos = {x=1176, y=199, z=7},
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
	return isKnight(cid) and doTeleportThing(cid, newPos) or doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You have to be a warrior in order to get teleported to the warriors armory.') and doTeleportThing(cid, fromPosition);
end
 
@up, yep, i know. i wanted to show him how many things are still to learn, i hope i made him more motivated.

@Mithaz. Your script is mainly good [remember that most of function starts with smalll letter], only major bug came with trying to get local variable outside a function. :)

Keep Doing, There's still much left to learn;)
 
cyko style(everything in return) is "a bit" not practical
good for showoff but can be really annoying

@topic: stay with readable codes, its good even if you dont release cause after few weeks when you need to edit it it gonna be easier
 

Similar threads

Back
Top