• 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 :o

dabaflow

New Member
Joined
May 22, 2008
Messages
277
Reaction score
1
Ok, i read Lua beginner tutorial by Evil Hero and I wanted to see if i could make a simple random script. And i got this one together and i want you to comment and tell me if its useable xD ?




Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
           if item.itemid == 1000 then
                    doPlayerAddExp(cid, 5000000)
            else
                    doPlayerSendCancel(cid,"You can not use this item.") 
            end
 
You simply write [code ] [/code] wrapped around your code to use the code tag, but I personally prefer the [php ] [/php] tag for scripts as it gets highlighted.

Anywho, it sure is nice to see that more people cares to learn LUA. Your script is pretty basic indeed, and everytime someone would use it they would recieve additional 5 million experience points. I'd recommend you to study the art of storages (getPlayerStorageValue(cid, id) and setPlayerStorageValue(cid, id, value)). Other then that, that check is kind of unnecessary as the item/unique/action id should be defined in your actions.xml file.

But yeah, keep on trying and good luck! Don't hestitate to ask for help if you encounter any issue or just feel like having some assistance!
 
Aight, thanks :) do you know any tuts for "getPlayerStorageValue(cid, id" ?
Don't tell me to search cuz i never find what i want by searching :p. And yea all those scripts.. can you/anyone else tell me how to add them to the server? is it just the "actions.xml" and put the scripts in actions>scripts ?
 
Yes it is just to add them into the actions.xml and actions script folder indeed, then just either restart your server or reload the actions (/reload actions).

I'm not really sure if there's any tutorial on storages, but you should try looking at your other scripts (those which you recieved while downloading the server) and try your way up to the top. It's pretty much basic English, really.

if getPlayerStorageValue(cid, 1000) == 1 then
-- something happens because the player has storage 1000 with value of 1.
else
-- send an error message because the player does not have storage 1000 with value of 1.
end
 
Well i dont know

thsi should work... also you dont need if item.itemid...

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local msg = " " ..getPlayerName(cid).. "You gained 500.000 experience." -- The message
local storage = 1000 -- Here the ID/Number of the Storage.

if getPlayerStorageValue(cid, storage) == TRUE then
     doPlayerAddExp(cid, 500000)
else
     doPlayerSendCancel(cid,"You can not use this item.")
     end
	 return TRUE
end

Storage goes like that i think ;)
 
Yes it is just to add them into the actions.xml and actions script folder indeed, then just either restart your server or reload the actions (/reload actions).

I'm not really sure if there's any tutorial on storages, but you should try looking at your other scripts (those which you recieved while downloading the server) and try your way up to the top. It's pretty much basic English, really.

if getPlayerStorageValue(cid, 1000) == 1 then
-- something happens because the player has storage 1000 with value of 1.
else
-- send an error message because the player does not have storage 1000 with value of 1.
end



Your aac roxs.
 
A storage is where you keep stuff. You save your documents on your computer which makes your computer store the documents, thereby storage. Although in OTServers storages are abit different as they can only hold integers (numerics).

So basically you could tell the server that this user has already made this quest by adding storages. Let's say you add storage id 12345 for a quest (doesn't really matter as long as it's below 65.000 or something), you could then do a check to see if this quest has been done already or not.

PHP:
if getPlayerStorageValue(cid, 12345) == -1 then -- Checks if the player has no value registered to this storage id.
    doPlayerAddItem(cid, 2400, 1) -- If he doesn't, give him a sword of valor.
    setPlayerStorageValue(cid, 12345, 1) -- Register the storage for him to prevent him to use the quest more than once.
    doPlayerSendTextMessage(cid, 24, "You recieved a sword of valor!") -- Send him a message concering the reward.
else
    doPlayerSendCancel(cid, "The chest is empty.")
end


Your aac roxs.
Thank you, sir! : )
 
A storage is where you keep stuff. You save your documents on your computer which makes your computer store the documents, thereby storage. Although in OTServers storages are abit different as they can only hold integers (numerics).

So basically you could tell the server that this user has already made this quest by adding storages. Let's say you add storage id 12345 for a quest (doesn't really matter as long as it's below 65.000 or something), you could then do a check to see if this quest has been done already or not.

PHP:
if getPlayerStorageValue(cid, 12345) == -1 then -- Checks if the player has no value registered to this storage id.
    doPlayerAddItem(cid, 2400, 1) -- If he doesn't, give him a sword of valor.
    setPlayerStorageValue(cid, 12345, 1) -- Register the storage for him to prevent him to use the quest more than once.
    doPlayerSendTextMessage(cid, 24, "You recieved a sword of valor!") -- Send him a message concering the reward.
else
    doPlayerSendCancel(cid, "The chest is empty.")
end


Thank you, sir! : )


k im a beginner, too.

So if youve given an unique ID to the chest
is it enough to just set it in the actions.xml or do I have to write

if item.uid == 5000 then

?!

If I can leave it our id just to write getPlayerStorageValue(cid, 29999) == -1 then
doTeleportThing(cid, newpos)
end
return 1
end
 
But ates, in your script you never wrote the ID of the item.. How do the "server" know what item to have that script on ? xD dont u have to write "if item.item == "" "
 
k im a beginner, too.

So if youve given an unique ID to the chest
is it enough to just set it in the actions.xml or do I have to write

if item.uid == 5000 then

?!

If I can leave it our id just to write getPlayerStorageValue(cid, 29999) == -1 then
doTeleportThing(cid, newpos)
end
return 1
end
It is not necessary as in your actions.xml file you do add such a line which already defines it.

Examples:
<action itemid="1000" script="myScript.lua" />
<action actionid="1001" script="myScript.lua" />
<action uniqueid="1002" script="myScript.lua" />

Although, in some cases it may be necessary to do a check, like if you're using a lever script.
PHP:
if item.itemid == 1945 then
    doTransformItem(item.uid, 1946)
elseif item.itemid == 1946 then
    doTransformItem(item.uid, 1945)
end
Which would actually change the lever when you pull/use it.

But ates, in your script you never wrote the ID of the item.. How do the "server" know what item to have that script on ? xD dont u have to write "if item.item == "" "
Read what I wrote above.
 
k im a beginner, too.

So if youve given an unique ID to the chest
is it enough to just set it in the actions.xml or do I have to write

if item.uid == 5000 then

?!

If I can leave it our id just to write getPlayerStorageValue(cid, 29999) == -1 then
doTeleportThing(cid, newpos)
end
return 1
end

Its enough to declare itemid/actionid/uniqueid in actions.xml

But ates, in your script you never wrote the ID of the item.. How do the "server" know what item to have that script on ? xD dont u have to write "if item.item == "" "

You dont have to add if you are using the script just for one item, then you register *this* itemid at actions.xml.
 
Ok, so if i combinate what you guys learned me here. This one should be correct ? :]


Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
           if getPlayerStorageValue(cid, 12345) == -1 then
           doPlayerAddExp(cid, 500000)
           setPlayerStorageValue(cid, 12345, 1)
           local msg " " ..getPlayerName(cid).. "You gained 5 million experience points."
      else
           doPlayerSendCancel(cid,"You can only use this item 1 time.")
end



i also wanna know how to know where to put the "ends" and also what "return TRUE/1" is for. :)
 
It is fairly correct yes, except the local msg line as you do not output that somewhere. An end is to close a function (if, function, for loop etc). So let's say you use two if statements in your code, you would have to end them both by adding two ends where you wish to end them.

PHP:
if i want to do something == true then
   do what i want to do
now end it
Although if you are using elseif's you should only end it once as elseif's are only sub statements to the if statement.
 
Thanks alot, i'll keep looking for tutorials and looking in the action scripts for more knowledge. One last thing, i still dont know what return is for xD
 
Code:
local config = {
	storage = 12345,
	experience = 50000,
	message = "You have gained 500000 experience points.",
	effect = CONST_ME_MAGIC_GREEN
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, config.storage) == - 1 then
		doPlayerAddExp(cid, config.experience)
		setPlayerStorageValue(cid, config.storage, 1)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, config.message)
		doSendMagicEffect(getPlayerPosition(cid), config.effect)
	else
		doPlayerSendCancel(cid, "You can only use this item 1 time.")
	end
end
 
K thx

Now, hows it possible to do a script like you have to put items on something before you can do anything

Thats what I want to know
 
PHP:
local pos = { x = 100, y = 100, z = 7, stackpos = 1}
local itemPos = getThingfromPos(pos).uid
if itemPos.itemid == 2400 then
    # do something
end
 
Back
Top