• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Setting Mutiple Storage Id's

  • Thread starter Thread starter Xikini
  • Start date Start date
X

Xikini

Guest
0.3.6 TFS
To start I am trying to learn to scripting but I seem to be taking mouthfuls instead if sips.

What I'm trying to do is when a player walks on a tile in-game they get a storage value ranging from 20001-30000
Ideally I would not have to touch the movements afterwords.
I would be able to set the ActionID on the map editor with any tile. (example: map editor has ActionID 26470 on a grass tile in front of a cave - it would give the player the storage of 26470

What I'm trying to do is make it so that in movements I have this
XML:
<movevent type="StepIn" actionid="20001-23000" event="script" value="checkpoint.lua"/>

Instead of this
XML:
<movevent type="StepIn" actionid="20001" event="script" value="checkpoint20001.lua"/>
<movevent type="StepIn" actionid="20002" event="script" value="checkpoint20002.lua"/>
<movevent type="StepIn" actionid="20003" event="script" value="checkpoint20003.lua"/>
<movevent type="StepIn" actionid="20004" event="script" value="checkpoint20004.lua"/>
<movevent type="StepIn" actionid="20005" event="script" value="checkpoint20005.lua"/>

This is my current set player storage on step in. (not tested)
I believe I have it is set so that it will only set the storage value once and give the player a message.
LUA:
function onStepIn(cid, item, position, position)
	   if getPlayerStorageValue(cid, 20001) ~= -1 then
		setPlayerStorageValue(cid, 20001, 1)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Checkpoint Found!")
		end
	return TRUE
end
Do I need an else do nothing?
I don't really understand if I need the 'return true', but copy paste is a wonderful thing.

Would something like this work?
LUA:
function onStepIn(cid, item, position, position)
	if(actionid > 20001 and actionid < 30000) then
		if getPlayerStorageValue(cid, actionid) ~= -1 then
		setPlayerStorageValue(cid, actionid, 1)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Checkpoint Found!")
		end
	end
	return TRUE
end

But I'm not sure how to do it exactly :P

Any pointers or solutions off the top of your heads?

Rep++ of course for any help :P
 
First of all your script explained:
(gz, for using lua code instead of normal code ;))
LUA:
function onStepIn(cid, item, position, fromposition)
	   if getPlayerStorageValue(cid, 20001) == -1 then -- Checks, if Player Storage Value is equal to -1 (unused) [~= mean unequal; == means equal; < smaller than; > bigger than; <= smaller or equal; >= bigger or equal]
		setPlayerStorageValue(cid, 20001, 1) -- sets the storageValue to 1
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Checkpoint Found!")
		end
	return TRUE -- says that script ends here. You can use multiple "return TRUE"s in one script, if you wanna cancel the script, if something is not right
end

For your question about all actionids in one script:
LUA:
local storages =
{
	[1] = 20001,
	[2] = 20002,
	[3] = 20003,
	[4] = 15551,
	[5] = 12392
} -- you create a table here, where you say which number means which storage

function onStepIn(cid, item, position, fromposition)
	   if getPlayerStorageValue(cid, storages[item.actionid - 20000]) ~= -1 then
		setPlayerStorageValue(cid, storages[item.actionid - 20000], 1)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Checkpoint Found!")
		end
	return TRUE
end

If the storage value is always equal to the actionid, then just
LUA:
--remove
storages[item.actionid - 20000]
--with this
item.actionid
And remove the table as well.

Hope you understand it. If there are more questions, just ask ;)
 
First of all your script explained:
(gz, for using lua code instead of normal code ;))
LUA:
function onStepIn(cid, item, position, fromposition)
	   if getPlayerStorageValue(cid, 20001) == -1 then -- Checks, if Player Storage Value is equal to -1 (unused) [~= mean unequal; == means equal; < smaller than; > bigger than; <= smaller or equal; >= bigger or equal]
		setPlayerStorageValue(cid, 20001, 1) -- sets the storageValue to 1
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Checkpoint Found!")
		end
	return TRUE -- says that script ends here. You can use multiple "return TRUE"s in one script, if you wanna cancel the script, if something is not right
end

For your question about all actionids in one script:
LUA:
local storages =
{
	[1] = 20001,
	[2] = 20002,
	[3] = 20003,
	[4] = 15551,
	[5] = 12392
} -- you create a table here, where you say which number means which storage

function onStepIn(cid, item, position, fromposition)
	   if getPlayerStorageValue(cid, storages[item.actionid - 20000]) ~= -1 then
		setPlayerStorageValue(cid, storages[item.actionid - 20000], 1)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Checkpoint Found!")
		end
	return TRUE
end

If the storage value is always equal to the actionid, then just
LUA:
remove
storages[item.actionid - 20000]
with this
item.actionid
Hope you understand it. If there are more questions, just ask ;)

Would my movements.xml work with..

XML:
<movevent type="StepIn" actionid="20001-23000" event="script" value="checkpoint.lua"/>
LUA:
local storages =
{
	[1] = 20001,
	[2] = 20002,
	[3] = 20003, -- using this I would have to write in every single number from 20001-30000...
	[4] = 15551, -- I was kind of hoping not to have to write 10,000 numbers :/
	[5] = 12392
} -- you create a table here, where you say which number means which storage

function onStepIn(cid, item, position, fromposition)
	   if getPlayerStorageValue(cid, item.actionid) ~= -1 then
		setPlayerStorageValue(cid, item.actionid, 1)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Checkpoint Found!")
		end
	return TRUE
end

edit
LUA:
function onStepIn(cid, item, position, fromposition)
	   if getPlayerStorageValue(cid, item.actionid) ~= -1 then
		setPlayerStorageValue(cid, item.actionid, 1)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Checkpoint Found!")
		end
	return TRUE 
end
^ above would work without having to write the table everytime. haha :P
- I think - :S

Edit a second time

LUA:
item.actionid -- find's the action id of the tile that the player is standing on?
 
I am not quite sure if
XML:
<movevent actionid="20001-23000"/>
will work, cause I'm using 0.2.14, and there you need to write
XML:
<movevent fromaid="20001" toaid="23000"/>
But you can try it :)
 
alright so when I tried using from and toaction it errored and wouldn't let the server start-up. so it's currently like this..
LUA:
<movevent type="StepIn" actionid="20001-25000" event="script" value="CheckPoints/checkpoint.lua"/>
LUA:
function onStepIn(cid, item, position, fromposition)
	   if getPlayerStorageValue(cid, item.actionid) ~= -1 then
		setPlayerStorageValue(cid, item.actionid, 1)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Checkpoint Found!")
		end
	return TRUE 
end
There are no error's in console when starting up and when I walk over tile it does not give me the message, and there are no error's in console.
Also to be sure I looked at the tile, and it shows this..
Code:
12:39 You see sandstone floor.
ItemID: [777], ActionID: [20001].
Position: [X: 1505] [Y: 2674] [Z: 7].
So currently I'm confused. :P
No error's at all, it's like it doesn't even know what to do.

nevermind I tried using your things with copy paste..
I was putting fromactionid
instead of fromaid
:P

But still the same result o;
 
Back
Top