• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action Damons' Scripting Corner :)

Damon

Check my status to contact me :)
Joined
Mar 26, 2011
Messages
6,209
Solutions
1
Reaction score
2,026
Location
Germany
Hello, I just started with lua,and here are my first scripts ,more to come!

First script: Change effect ; 26th January 2013
Tested [not yet]

When u rightclick on crystal coin and get 100platinum coins u also get this text message, which u can change :)
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
       if item.itemid == 2160 then
               doPlayerSendTextMessage(cid,21,"You are rich ! You have transformed 1cc to 100 platinum coins !")
       end 
       return TRUE
end

Second Script: "!buyitem" ; 26th January 2013


Tested [not yet]

Hello, here is my second script, which
Is supposed to let the player buy any item with a command you can specify choose (e.g. !buyitem) .

data/talkactions

Add to talkactions.xml

"!buyitem" is what the player has to say in order to buy the item, you may change it to w.e. U want , e.g. To "!buysword"
Code:
<talkaction words="!buyitem" 
script="buyitem.lua" />

Create a new .lua at data/talkactions/scripts
and name it
buyitem.lua
.
Now paste this in buyitem.lua:
Lua:
function onSay(cid, words, param)
 
	if doPlayerRemoveMoney(cid, 10000) then
		doPlayerAddItem(cid, 2160, 1)
	else 
		doPlayerSendTextMessage(cid, 21, "You are too poor yeye, u mad now?")
	end
	return true
end

How to edit?!
"10000" can be changed to the amount of Gold coins the player has to pay for the item when using the command.
"2160,1" can be changed to whatever u like, just keep in mind it is:
"itemidofitemtheplayerwillrecive,amount"


Third Script:
ChangeSexForMoneyScript ; added 26th January 2013


Tested [not yet]
Hey, here is my next script :)

It is supposed to let players ChangeSex via Command!
e.g. !changesex
To talkactions.xml add:
Code:
<talkaction words="!changesex" 
script="changesex.lua" />

To talkactions/scripts
Add "changesex.lua" :

Lua:
function onSay(cid, words, param) if doPlayerRemoveMoney(cid, 5000) == 1 then	
doPlayerSetSex(cid, newSex)
end
end

The script is easy to configure :)
You can change the price , which is currently set to "5000" gold coins.
Just exchange "5000" with the amount of gp you want it to cost!


Regards,
//Damon
 
Last edited:
Nice bro, keep it up. I need to go back to lua, haven't done any since my last script i released here tbh.. Like what - june? May? Lol

But fair play at trying the steep learning curve :)
 
Second script !buyitem optimized thanks to Limos :D
More scripts to come hell yeah!
 
Goodluck but your first script do not change the money it only checks the item id then it gives a certain message:p

Maybe some usefull things:
- http://otland.net/f16/new-functions-167528/ I use that link to check the functions and such so you can see what things are easy to fix(You can find it in lib files either)
- In my sig There you will learn the basic of spells nice start for you
- Lua Scripting Guide And use this link to learn how to build a script.
- http://otland.net/f481/spells-effects-83514/ magic effects list also usefull..

goodluck
 
@up thanks :)
Anyway I already read evil heros guide :)

Here a simple premiumitem script .
It makes that when u use item XY u get x premium days added :)
Please correct me, cause I think I did the effect part wrong :/

Here I just made a little script for a premium scroll :)

To actions.xml add:
Code:
<action itemid="itemidoftheitemwhichisusedtogetpremmy" event="script" value="premiumitem.lua"/>

Create a new .lua at data/actions/scripts and name it "premiumitem.lua" .
Then paste the following into it!

Lua:
function onUse(cid, item, frompos, item2, topos)
doPlayerAddPremiumDays(cid, 7) --You can change 7 to whatever number of premium days you want to be added 
doPlayerSendTextMessage(cid, 22, "Congratulations! You  just recived 7 days additional premium time!") --you can change the message to whatever you want
doSendMagicEffect(pos, type[, player])
return TRUE
end
 
Lua:
function onSay(cid, words, param) if doPlayerRemoveMoney(cid, 5000) == 1 then	
doPlayerSetSex(cid, newSex)
end
end
You're trying to set a player to newSex, which hasn't even been defined yet.. so it's just going to throw an error, you also don't need == 1 because if it removes the money it will continue, if not it will stop.

Lua:
function onUse(cid, item, frompos, item2, topos)
doPlayerAddPremiumDays(cid, 7) --You can change 7 to whatever number of premium days you want to be added 
doPlayerSendTextMessage(cid, 22, "Congratulations! You  just recived 7 days additional premium time!") --you can change the message to whatever you want
doSendMagicEffect(pos, type[, player])
return TRUE
end
That function onUse is outdated and is missing a lot of params.
doSendMagicEffect is wrong, you're missing a position, a type, and you have the optional thing in that is true / false. The true/false depends on if everyone will see it, or only cid (cid in this case is the person using the item).

Also why would you just not define a variable for the amount of days so you don't even need to change the string? Try something like this;

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local days = 7 -- defining the amount of days
	doPlayerAddPremiumDays(cid, days) -- adding the amount of days already defined
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You've just added ".. days .." premium days to your account! You now have ".. getPlayerPremiumDays(cid) + days .."!") -- adding the amount of days & telling them their new amount
	doSendMagicEffect(getCreaturePosition(cid), CONST_ME_GIFT_WRAPS) -- getCreaturePosition(cid) gets the position of the person using the item, and then a magic effect of your choice
	doRemoveItem(item.uid) -- removes the item that was just used
	return true
end

Also your signature is full of errors :(
 
Yes I am ;)

And well to my old functions :
EvilHero didnt update em :/

And well I am still learning . Thanks for
the correction though :p

Our greatest glory is not in never failing, but in rising up every time we fail.
by Ralph Waldo Emerson
 
Gogo Damon

btw,

Lua:
function onSay(cid, words, param) if doPlayerRemoveMoney(cid, 5000) == 1 then	
doPlayerSetSex(cid, newSex)
end
end

this should be like

Lua:
function onSay(cid, words, param)
if getPlayerSex(cid) == PLAYERSEX_FEMALE and getPlayerMoney(cid) => 5000 then
doPlayerRemoveMoney(cid, 5000)
doPlayerSetSex(cid, 1)
elseif getPlayerSex(cid) == PLAYERSEX_MALE and getPlayerMoney(cid) => 5000 then
doPlayerRemoveMoney(cid, 5000)
doPlayerSetSex(cid, 0)
else
doPlayerSendTextMessage(cid, 21, 'You do not have enough money to change ur sex.')
end
return true
end
 
Last edited:
Back
Top