Forum

> > CS2D > Scripts > [Math]Combination of words
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch [Math]Combination of words

26 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

alt Re: [Math]Combination of words

Flacko
User Off Offline

Zitieren
You should call generate_instance only once (when the player buys the item), then, just pass the table around.

For your second question, just change prefix_num here to whatever value you want
1
for i=1, math.random(0,prefix_num) do

If tibia stores the player's inventory using item ids then you will have to hack it a little so it uses tables storing the item data directly instead.

alt Re: [Math]Combination of words

KenVo
User Off Offline

Zitieren
Hmm, It would take awhile to work on that...But I think I should try it.

@user Flacko: So if I store items table in player's inventory, it's gonna be something like this?

inventory={[1]={id=300,magic = 5},[2]={id=300,atk = 1},[3]={id=300,spd=2}}

note that the element in the keys are only bonuses
4× editiert, zuletzt 28.02.12 07:21:37

alt Re: [Math]Combination of words

Flacko
User Off Offline

Zitieren
It should be possible to do it like that.
But I think it's better to store the whole data returned by the generate_instance function.
1
2
3
4
5
6
7
8
9
10
inventory = {
	[1] = {
		name = "hard shiny leather helmet",
		desc = "Protect yourself from headshots! +5% armor Has a nice white color"
		r = 255,
		g = 255,
		b = 255,
		--and so on
	}
}
(Note that special attributes, name changes and descriptions are already calculated beforehand and stored like that)
Although this way requires more memory, it could still be faster and more comfortable to work with.
For example, when the player just bought the weapon and you want to put it into it's inventory, the code could look like this:
1
table.insert(inventory[id], generate_item(boughtItemId))

alt Re: [Math]Combination of words

KenVo
User Off Offline

Zitieren
The problem of that is when I save then start the server again, the item's function changes from this:

1
food = function() return math.random(10,20) end,

to this:
1
food=function: 02CE0B98,

And I think that happens because of the save function of tibia, I honestly don't wanna mess with it

Also, how do you make the table key like this when you add an item to the inventory of the player?
1
Inventory={[1] = {blablabla},[2] = {blablabla}}

instead of
1
Inventory={{blablabla},{blablabla}}

Wait! I think that's the same thing ! lol nvm

So yeah, I like my own way better although it's not comfortable to work with in the beginning but once I set all the things that I need up, I should be fine. It's also better in the long run too imo because every player's save would be really long if I store tables in their saves.

alt Re: [Math]Combination of words

EngiN33R
Moderator Off Offline

Zitieren
user KenVo hat geschrieben
1
food = function() return math.random(10,20) end,


This doesn't work because you set that variable (food) to be the function and don't execute it.

1
2
local function r() return math.random(10,20) end
food = r()

user KenVo hat geschrieben
Also, how do you make the table key like this when you add an item to the inventory of the player?


To insert a value in a specific table position (for example's sake let it be 2), you can either use

1
table[2] = value

or

1
table.insert(table,2,value)

alt Re: [Math]Combination of words

KenVo
User Off Offline

Zitieren
No, you didn't understand me correctly. What I meant to say is that I wanted it to be like this:

Inventory={[1] = {blablabla},[2] = {blablabla}}

instead of:

Inventory={{blablabla},{blablabla}}

But then realize that it's kinda like the same thing
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht