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

Need help with a simple lua script

SE000

New Member
Joined
Nov 19, 2010
Messages
43
Reaction score
1
Code:
function onUse(cid, item, frompos, item2, topos)
 
if item.uid == 3004 then
if getPlayerStorageValue(cid,3004) == -1 then
	doPlayerSendTextMessage(cid,25,"You have found some useful weapons.")
	doPlayerAddItem(cid,2476,1)
	if getPlayerVocation == 1 and getPlayerVocation == 2 and getPlayerVocation == 5 and getPlayerVocation 6 then
	doPlayerSendTextMessage(cid,20,"You are not the right vocation.")
	
		setPlayerStorageValue(cid,3004,1)
	doPlayerSendMagicEffect(cid,1)
else
	doplayerSendMagicEffect(cid,2)
	doPlayerSendTextMessage(cid,25,"EMPTY")
end
 
end
return TRUE
end
end

What exactly is wrong? Can you improve this script? Im currently trying to learn LUA.
 
Try:

Lua:
function onUse(cid, item, frompos, item2, topos)
ppos = getPlayerPosition(cid)

if getPlayerStorageValue(cid,3004) == -1 then
   setPlayerStorageValue(cid,3004,1)
                  doPlayerSendTextMessage(cid,25,"You have found some useful weapons.")
                  doPlayerAddItem(cid,2476,1)
	              doSendMagicEffect(ppos,1)
elseif getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 5 or getPlayerVocation(cid) == 6 then
	doPlayerSendTextMessage(cid,20,"You are not the right vocation.")
elseif getPlayerStorageValue(cid,3004) == 1 then
	doSendMagicEffect(ppos,2)
	doPlayerSendTextMessage(cid,25,"EMPTY")
end
return true
end

Set the uniqueID at actions.xml
 

Dude, really need help with this again:

first quest:

Code:
function onUse(cid, item, frompos, item2, topos)
ppos = getPlayerPosition(cid)
 
if getPlayerStorageValue(cid,3004) == -1 then
   setPlayerStorageValue(cid,3004,1)
                getPlayerVocation(cid) = 1 or getPlayerVocation(cid) = 2 or getPlayerVocation(cid) = 5 or getPlayerVocation(cid) = 6 then
				doPlayerSendTextMessage(cid,20,"You are not the right vocation, but since im a nice lever, I give you the items anyway. Lucky, huh?")
				  doPlayerSendTextMessage(cid,25,"You have found some items")
                  	doPlayerAddItem(cid,2476,1)
					doPlayerAddItem(cid,2477,1)
	              doSendMagicEffect(ppos,1)
elseif getPlayerStorageValue(cid,3004) == 1 then
	doSendMagicEffect(ppos,2)
	doPlayerSendTextMessage(cid,25,"The lever isnt working anymore.")
end
return true
end

this is the console error message:

Code:
[25/11/2010 21:19:14] [Error - LuaScriptInterface::loadFile] data/actions/scripts/hemgjordaquests/knightset.lua:6: unexpected symbol near '='
[25/11/2010 21:19:14] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/hemgjordaquests/knightset.lua)
[25/11/2010 21:19:14] data/actions/scripts/hemgjordaquests/knightset.lua:6: unexpected symbol near '='

And this is the other script (another quest)

Code:
function onUse(cid, item, frompos, item2, topos)
 
 
if item.uid == 3004 then
if getPlayerStorageValue(cid,3005) == -1 then
	doPlayerSendTextMessage(cid,25,"You have found a good crossbow.")
	doPlayerAddItem(cid,2498,1)
	
	if getPlayerVocation == 1 and getPlayerVocation == 2 and getPlayerVocation == 5 and getPlayerVocation 6 then
	doPlayerSendTextMessage(cid,23,"You dont have the right vocation, but since im a nice gingerman, you get the items anyway.")
		setPlayerStorageValue(cid,3005,1)
	doPlayerSendMagicEffect(cid,1)
else
	doplayerSendMagicEffect(cid,2)
	doPlayerSendTextMessage(cid,25,"Unfortunaly the cake dont want you to eat anymore. Come back in around 2 weeks.")
end
 
end
return TRUE
end
end

This is the error message:

Code:
[25/11/2010 21:19:14] [Error - LuaScriptInterface::loadFile] data/actions/scripts/hemgjordaquests/pallyset.lua:13: 'then' expected near '6'
[25/11/2010 21:19:14] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/hemgjordaquests/pallyset.lua)
[25/11/2010 21:19:14] data/actions/scripts/hemgjordaquests/pallyset.lua:13: 'then' expected near '6'
 
First:
Lua:
function onUse(cid, item, frompos, item2, topos)
ppos = getPlayerPosition(cid)
v = getPlayerVocation(cid)
if getPlayerStorageValue(cid,3004) == -1 and v == 1 or v == 2 or v == 5 or v == 6 then
   setPlayerStorageValue(cid,3004,1)
				doPlayerSendTextMessage(cid,20,"You are not the right vocation, but since im a nice lever, I give you the items anyway. Lucky, huh?")
				  doPlayerSendTextMessage(cid,25,"You have found some items")
                  	doPlayerAddItem(cid,2476,1)
					doPlayerAddItem(cid,2477,1)
	              doSendMagicEffect(ppos,1)
elseif getPlayerStorageValue(cid,3004) == 1 then
	doSendMagicEffect(ppos,2)
	doPlayerSendTextMessage(cid,25,"The lever isnt working anymore.")
end
return true
end

Second:
Lua:
function onUse(cid, item, frompos, item2, topos)
v = getPlayerVocation(cid)
ppos = getPlayerPosition(cid)


if getPlayerStorageValue(cid,3005) == -1 and v == 1 or v == 2 or v == 5 or v == 6 then
   	setPlayerStorageValue(cid,3005,1)
		doPlayerSendTextMessage(cid,23,"You dont have the right vocation, but since im a nice gingerman, you get the crossbow anyway.")
	    doSendMagicEffect(ppos,1)
	    doPlayerAddItem(cid,2498,1)
else
	doSendMagicEffect(ppos, 2)
	doPlayerSendTextMessage(cid,25,"Unfortunaly the cake dont want you to eat anymore. Come back in around 2 weeks.")
end
return true
end

Set uids in action.xml
Please note that if you are paladin or knight, you won't be able to get the items.
If you want knights and pally to get items normal, and druid and sorc, to get items but that it says "you dont have right voc but i give u items anyway" then tell me please so i do it
 
Yes. thats how i want it.

Everyone gotta get the items, but sorc and druid (including promotion) will get that "you dont have right voc" message.

Thank you, "rep+" as they say.
 
First:
Lua:
function onUse(cid, item, frompos, item2, topos)
ppos = getPlayerPosition(cid)
v = getPlayerVocation(cid)
if getPlayerStorageValue(cid,3004) == -1 and v == 1 or v == 2 or v == 5 or v == 6 then
   setPlayerStorageValue(cid,3004,1)
				doPlayerSendTextMessage(cid,20,"You are not the right vocation, but since im a nice lever, I give you the items anyway. Lucky, huh?")
				  doPlayerSendTextMessage(cid,25,"You have found some items")
                  	doPlayerAddItem(cid,2476,1)
					doPlayerAddItem(cid,2477,1)
	              doSendMagicEffect(ppos,1)
elseif getPlayerStorageValue(cid,3004) == 1 then
	doSendMagicEffect(ppos,2)
	doPlayerSendTextMessage(cid,25,"The lever isnt working anymore.")
elseif v == 3 or v == 4 or v == 7 or v == 8 then
    doPlayerSendTextMessage(cid,25,"You have found some items")
end
return true
end

Second:
Lua:
function onUse(cid, item, frompos, item2, topos)
v = getPlayerVocation(cid)
ppos = getPlayerPosition(cid)
 
 if getPlayerStorageValue(cid,3005) == -1 and v == 1 or v == 2 or v == 5 or v == 6 then
   	setPlayerStorageValue(cid,3005,1)
		doPlayerSendTextMessage(cid,23,"You dont have the right vocation, but since im a nice gingerman, you get the crossbow anyway.")
	    doSendMagicEffect(ppos,1)
	    doPlayerAddItem(cid,2498,1)
elseif getPlayerStorageValue(cid,3005) == 1 then
	doSendMagicEffect(ppos, 2)
	doPlayerSendTextMessage(cid,25,"Unfortunaly the cake dont want you to eat anymore. Come back in around 2 weeks.")
elseif v == 3 or v == 4 or v == 7 or v == 8 then
    doPlayerSendTextMessage(cid,25,doPlayerSendTextMessage(cid,25,"You have found a good crossbow.")
	doPlayerAddItem(cid,2498,1)
end
return true
end
 
Yes. thats how i want it.

Everyone gotta get the items, but sorc and druid (including promotion) will get that "you dont have right voc" message.

Thank you, "rep+" as they say.
When they say Rep+, it means they click a feature under the post of someone (Bottom left) to add 'Reputation'
repfi.png
 
Code:
[26/11/2010 00:46:05] [Error - LuaScriptInterface::loadFile] data/actions/scripts/hemgjordaquests/pallyset.lua:19: ')' expected (to close '(' at line 18) near 'end'
[26/11/2010 00:46:05] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/hemgjordaquests/pallyset.lua)
[26/11/2010 00:46:05] data/actions/scripts/hemgjordaquests/pallyset.lua:19: ')' expected (to close '(' at line 18) near 'end'

Thats the second script of yours.
 
Add sorry man, pasted 2 functions and forgot to remove 1 and it got mixed xD
Lua:
function onUse(cid, item, frompos, item2, topos)
v = getPlayerVocation(cid)
ppos = getPlayerPosition(cid)
 
 if getPlayerStorageValue(cid,3005) == -1 and v == 1 or v == 2 or v == 5 or v == 6 then
   	setPlayerStorageValue(cid,3005,1)
		doPlayerSendTextMessage(cid,23,"You dont have the right vocation, but since im a nice gingerman, you get the crossbow anyway.")
	    doSendMagicEffect(ppos,1)
	    doPlayerAddItem(cid,2498,1)
elseif getPlayerStorageValue(cid,3005) == 1 then
	doSendMagicEffect(ppos, 2)
	doPlayerSendTextMessage(cid,25,"Unfortunaly the cake dont want you to eat anymore. Come back in around 2 weeks.")
elseif v == 3 or v == 4 or v == 7 or v == 8 then
    doPlayerSendTextMessage(cid,25,"You have found a good crossbow.")
	doPlayerAddItem(cid,2498,1)
end
return true
end
 
Really annoying, what error is this?

Code:
[26/11/2010 13:58:36] [Error - LuaScriptInterface::loadFile] data/actions/scripts/hemgjordaquests/pallyset.lua:18: 'end' expected (to close 'if' at line 6) near 'elseif'
[26/11/2010 13:58:36] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/hemgjordaquests/pallyset.lua)
[26/11/2010 13:58:36] data/actions/scripts/hemgjordaquests/pallyset.lua:18: 'end' expected (to close 'if' at line 6) near 'elseif'

This is the script:

Code:
function onUse(cid, item, frompos, item2, topos)
 
pvoc = getPlayerVocation(cid)
 
if item.uid == 3005 then
		if getPlayerStorageValue(cid,3005) == -1 and pvoc == 3 and pvoc == 4 and pvoc == 7 and pvoc == 8 then
	doPlayerSendTextMessage(cid,25,"You have found a pally set with a great crossbow.")
	doPlayerAddItem(cid,2498,1)
	doPlayerAddItem(cid,8849,1)
	doPlayerAddItem(cid,8891,1)
	doPlayerAddItem(cid,7730,1)
	doPlayerAddItem(cid,2195,1)
		setPlayerStorageValue(cid,3005,1)
	doPlayerSendMagicEffect(cid,1)
else
	doplayerSendMagicEffect(cid,2)
	doPlayerSendTextMessage(cid,25,"Unfortunaly the cake didnt like how you ate him, you cannot get any more items.")
			elseif getPlayerStorageValue(cid,3005 == -1 and pvoc == 1 and pvoc == 2 and pvoc == 5 and pvoc == 6 then
		doPlayerSendTextMessage(cid,"You dont have the right vocation, but since im a very nice gingerman, you get the items.")
	doPlayerAddItem(cid,2498,1)
	doPlayerAddItem(cid,8849,1)
	doPlayerAddItem(cid,8891,1)
	doPlayerAddItem(cid,7730,1)
	doPlayerAddItem(cid,2195,1)
	setPlayerStorageValue(cid,3005,1)
	oPlayerSendTextMessage(cid,25,"Unfortunaly the cake didnt like how you ate him, you cannot get any more items.")
			end
		end
		return TRUE
end
return TRUE

Knights and pally's (including promotions) should get the items.
Sorcs and druids including promotions should get the items with the "youre not the right voc" message.
 
what a horrible script you made :s.

Lua:
local ij,s = {2498,8849,8891,7730,2195),3005
function onUse(cid,item,fromPos,itemEx,toPos)
local j,v = getPlayerVocation(cid),getThingPos(cid)
	if getPlayerStorageValue(cid,s) < 1 then
		if isInArray({3,4,7,8},j) then
			for _,items in ipairs(ij) do
				doPlayerGiveItem(cid,items,1)
			end
			doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,'You\'ve found a paladin set and a great crossbow!')
			doSendMagicEffect(v,CONST_ME_MAGIC_GREEN)
			setPlayerStorageValue(cid,s,1)
		else
			doPlayerSendTextMessage(cid,MESSAGE_FIRST,'You\'re not the right vocation.')
			doSendMagicEffect(v,CONST_ME_POFF)
		end
	else
		doPlayerSendTextMessage(cid,MESSAGE_FIRST,'You can\'t use this twice.')
	end
	return true
end
 
@Up: The other vocs should get items too, but with a message "You're not the right vocation, but as im a nice lever etc..
So It would be like this I think
Lua:
local ij,s = {2498,8849,8891,7730,2195},3005
function onUse(cid,item,fromPos,itemEx,toPos)
local j,v = getPlayerVocation(cid),getThingPos(cid)
	if getPlayerStorageValue(cid,s) < 1 then
		if isInArray({3,4,7,8},j) then
			for _,items in ipairs(ij) do
				doPlayerGiveItem(cid,items,1)
			end
			doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,'You\'ve found a paladin set and a great crossbow!')
			doSendMagicEffect(v,CONST_ME_MAGIC_GREEN)
			setPlayerStorageValue(cid,s,1)
		elseif isInArray({1,2,5,6},j) then
            for _,items in ipairs(ij) do
                doPlayerGiveItem(cid,items,1)
			doPlayerSendTextMessage(cid,MESSAGE_FIRST,'You\'re not the right vocation, but since Im a nice gingerman, you get the items!.')
			doSendMagicEffect(v,CONST_ME_MAGIC_GREEN)
			setPlayerStorageValue(cid,s,1)
		end
	else
		doPlayerSendTextMessage(cid,MESSAGE_FIRST,'You can\'t use this twice.')
	end
	return true
end
end
 
Lua:
local ij,s = {2498,8849,8891,7730,2195),3005
function onUse(cid,item,fromPos,itemEx,toPos)
local j,v = getPlayerVocation(cid),getThingPos(cid)
	if getPlayerStorageValue(cid,s) < 1 then
		if isInArray({3,4,7,8},j) then
			for _,items in ipairs(ij) do
				doPlayerGiveItem(cid,items,1)
			end
			doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,'You\'ve found a paladin set and a great crossbow!')
			doSendMagicEffect(v,CONST_ME_MAGIC_GREEN)
			setPlayerStorageValue(cid,s,1)
		else
			for _,items in ipairs(ij) do
				doPlayerGiveItem(cid,items,1)
			end
			doPlayerSendTextMessage(cid,MESSAGE_FIRST,'You\'re not the right vocation, but as I\'m kind you will get the paladin set too.')
			doSendMagicEffect(v,CONST_ME_MAGIC_GREEN)
			setPlayerStorageValue(cid,s,1)
		end
	else
		doPlayerSendTextMessage(cid,MESSAGE_FIRST,'You can\'t use this twice.')
	end
	return true
end
 

Similar threads

Back
Top Bottom