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

LightX's Scripting Thread

Alyhide

Banned User
Joined
Aug 21, 2010
Messages
1,945
Reaction score
54
Location
Switzerland
Hello, I am here to see if I have increased my scripting abilities at all.. Here are some simple scripts I made..



11/26/2010 || 1:30 AM

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
		if getPlayerLevel(cid) >= 100 then
				doPlayerSendTextMessage(cid,21,"Congratulations!")
				doPlayerAddMana(cid,500)
				doPlayerAddHealth(cid,500)
		else
				doPlayerSendCancel(cid,"Sorry, Try Gaining Some Levels!"
				doPlayerPopupFYI(cid, "Gain Levels By Hunting or Exploring New Islands!")
		end
		return TRUE
end

11/26/2010 || 1:41 AM

Lua:
function onStepIn(cid, item, frompos, itemEx, topos)
					doPlayerSendTextMessage(cid,21,"Welcome To Avian!"
end
 
Last edited:
Why would you make a script that onUse gives a useless message? XD

What a useless item. :p
 
This is how I tab:

Lua:
Function (no tab)
	if something then--(IF-statements, 1 tab)
		doSomething--(ee.. commands that start with "do" i use 2 tabs)
	elseif --(IF-statement again, so I use 1 tab.)
		doSomething--( 2 tabs)
	else --(1 tab)
                doSomethingElse(2 tabs)
	end--(my first end always has the same tab as the line above started with)
end --(my end below always goes 1 tab in, and it continues that way depending on how many tabs I use)
 
This is how I tab:

Lua:
Function (no tab)
	if something then--(IF-statements, 1 tab)
		doSomething--(ee.. commands that start with "do" i use 2 tabs)
	elseif --(IF-statement again, so I use 1 tab.)
		doSomething--( 2 tabs)
	else --(1 tab)
                doSomethingElse(2 tabs)
	end--(my first end always has the same tab as the line above started with)
end --(my end below always goes 1 tab in, and it continues that way depending on how many tabs I use)


okay neat that helped me a lot :)
 
wrong tab

Lua:
function onStepIn(cid, item, frompos, itemEx, topos)
					doPlayerSendTextMessage(cid,21,"Welcome To Avian!"
end

good tabbing
Lua:
function onStepIn(cid, item, frompos, itemEx, topos)
	doPlayerSendTextMessage(cid,21,"Welcome To Avian!") -- you forgot ')'
end

This is how I tab.

Lua:
local item = 2149 -- same line as function/if statement. Numbers/strings that don't change during the script, ABOVE the function statement.
function learnTab(script) -- function has no tab.
local lastTab = 0 -- local on the same line as function/if statement. this function changes during the script and needs to be 0 again on read, so put it somewhere UNDER function statement.
	if doUnderstand() then -- every if statement has 1 tab from the last if statement.
	local lastTab = 1 -- same line as if statement now, as it changes during script.
		if reallyUnderstands() then -- basically you need to tab lastTab+1 time. so if lastTab = 1 and you make a new if statement tab 1 more time.
		local lastTab = 2 -- tabbed 2x so it's 2 now.
			doPlayerGiveItem(item) -- lastTab+1 = 3 so 3x tab needed. also gives the itemid of the number that doesn't change during script.
		end -- end under last if statement so it closes
	end -- end under last if statement again so it closes
	return true -- under the last end of an if statement.
end -- 0 tabs as this closes the function.

If you need more help, you can PM me.
 
^last is kinda wrong:
Code:
local item = 2149 -- same line as function/if statement. Numbers/strings that don't change during the script, ABOVE the function statement.
function learnTab(script) -- function has no tab.
    local lastTab = 0 -- local on the same line as function/if statement. this function changes during the script and needs to be 0 again on read, so put it somewhere UNDER function statement.
    if doUnderstand() then -- every if statement has 1 tab from the last if statement.
        local lastTab = 1 -- same line as if statement now, as it changes during script.
        if reallyUnderstands() then -- basically you need to tab lastTab+1 time. so if lastTab = 1 and you make a new if statement tab 1 more time.
            local lastTab = 2 -- tabbed 2x so it's 2 now.
            doPlayerGiveItem(item) -- lastTab+1 = 3 so 3x tab needed. also gives the itemid of the number that doesn't change during script.
        end -- end under last if statement so it closes
    end -- end under last if statement again so it closes
    return true -- under the last end of an if statement.
end -- 0 tabs as this closes the function.

Why true with caps?
it does not matter at all :p
Lua:
TRUE = true
FALSE = false
LUA_ERROR = false
LUA_NO_ERROR = true
LUA_NULL = nil
 
Stop correcting the original poster in his thread. If you want to help, PM him and help...don't make him look stupid.

Where is the respect now days? :(
 
Well, you're not helping at all..
 
Congratulations, for helping, we are also helping, we are not making him look stupit we are correcting him how he should do it so he gets better, and might help other people.

@CyberM why is it wrong? lol.
 
@CyberM why is it wrong? lol.
well, i'm used to see any content inside a function tabbed
Code:
local item = 2149 -- same line as function/if statement. Numbers/strings that don't change during the script, ABOVE the function statement.
function learnTab(script) -- function has no tab.
[COLOR=red]local lastTab = 0 -- local on the same line as function/if statement. this function changes during the script and needs to be 0 again on read, so put it somewhere [/COLOR]UNDER function statement.
    if doUnderstand() then -- every if statement has 1 tab from the last if statement.
    local lastTab = 1 -- same line as if statement now, as it changes during script.
        if reallyUnderstands() then -- basically you need to tab lastTab+1 time. so if lastTab = 1 and you make a new if statement tab 1 more time.
        local lastTab = 2 -- tabbed 2x so it's 2 now.
            doPlayerGiveItem(item) -- lastTab+1 = 3 so 3x tab needed. also gives the itemid of the number that doesn't change during script.
        end -- end under last if statement so it closes
    end -- end under last if statement again so it closes
    return true -- under the last end of an if statement.
end -- 0 tabs as this closes the function.
 
Well as I said, thats how I tab.
I just find this more organized than creating an extra tab for just a local, but you can't really say it's wrong, lol.
 
Example on the first script, you should use player storage too since a player can go to 100, die, go to 100 and die = lots of hp :d
 
Back
Top