Forum

> > CS2D > Scripts > Plant at map tiles script?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Plant at map tiles script?

11 replies
To the start Previous 1 Next To the start

old Plant at map tiles script?

Mora
User Off Offline

Quote
Hello us
I wanna ask, how to check in the script tiles where i'm pressed button.
Example table of them?
idk..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
tableplantpossible = { --is {x,y} for one
[1]={x,y},
[2]={x,y},
[3]={x,y}
}

addhook("menu","fcking_menu")
function fcking_menu(id,title,b)
	if title=="Shit Plants Menu" then
		if b==1 then
			if tilex and tiley == tableplantpossible then
				if haveplants[id] >= 1 then
blabalabla
				end
			end
		end
	end
end

And how can i remove self other images without bug like a:
1
2
3
4
5
imagethatspawnedonmap = ("gfx\dffahu"+100500,+100500,on map spawned where do i planted plant)
timer(5000,"ssz")
	function ssz()
freeimage(imagethatspawnedonmap)
	end
but when i spawn 2 + images, some images is not free and/or free at -time when removed old image after new.
If you don't understand i can make video or images

Thank you alot.
edited 1×, last 05.02.15 05:35:28 pm

old Re: Plant at map tiles script?

Rainoth
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
tableplantpossible = { --is {x,y} for one
[1]={x,y},
[2]={x,y},
[2]={x,y}
}

addhook("menu","fcking_menu")
function fcking_menu(id,title,b)
     if title=="Shit Plants Menu" then
          if b==1 then
			for k,v in pairs(tableplantpossible) do
				if player(id,"tilex") == v[1] and player(id,"tiley") == v[2] then
					msg("You're standing on a correct spot for sth or idk..")
                    --[[if haveplants[id] >= 1 then

                    end]]
               end
          end
     end
end

I'd add another option in 3rd index.
1
{x,y,false}
Which would show if there's a plant or not. When planting you check
1
2
3
4
if v[3] == false then
	v[3] = true
	--planting stuff
end

You can't delete those images because you're overwriting the variable with a new image

image = image1 -- we make one image appear
image = image2 -- we make another image appear

image will never contain image1 now because it's lost forever. That's why it's best to assign images in a table. They will all get their own spot and won't be lost.

Good luck!

old Re: Plant at map tiles script?

Joni And Friends
User Off Offline

Quote
You need to make new image variable or make it in table for remove other image
In table >

old Re: Plant at map tiles script?

Mora
User Off Offline

Quote
This everything is hard for me..
But i don't understand one thing-
why cant i add for every new image new function of delete it?
example
standart new image name is "img"
new image is starting add like a player id,
ex "img1" means image name is "img1" and start function of deleting is "imguse" should be "imguse1".
If on the map is image "img" and "img1" and "img2" so, they start functions
"imguse","imguse1","imguse2", so if i'll plant a new plant it's will be "img3" and function "imguse3", after these images will free it can again start add new images with names "img","img1","img2","img3" etc.
/i need understand this all before just copy then paste it.
@user Rainoth: i'm not sure you understand my shitty english right,
it's means
[1]={x,y} where is 1 is "first possible plant planting tile", "x" is tilex on the map for this "1"(first possible plant planting tile), and + "y". Just telling by words:
"[possible plant planting tile N1]={position for N1 tile x 2,position for N1 tile y 5}"

So, it's means if i'm on x2 and y5 on the map i can plant it.
(First means that is just place where i can plant, 2,3 etc is just other planting tiles)
so ex:
1
2
3
4
5
6
tableplantpossible = {
[1]={2,5},
[2]={2,6},
[3]={4,5},
[4]={4,6}
}

old Re: Plant at map tiles script?

Rainoth
Moderator Off Offline

Quote
Ye, I DID understand that. That's obvious at a glance. What I SUGGESTED was that you actually add more things in your tables in your table to be able to check if there's a plant on the spot already.

Also, for the images, it would be dumb to make a new function for each image. I'm not even sure if that's possible.

Your function name would have to be not a string. So
function name
not
function "name"
I don't know much in this but I think that's not possible. However, it IS possible and a lot more convenient to add all images in one table. Convenient removal (or remove everything simply)

old Re: Plant at map tiles script?

VaiN
User Off Offline

Quote
if you want a function for each image, you could create a class for it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function newImage()
	local obj = {}
	obj.id = nil -- not needed, but just for clarity

	obj.create = function(self,strPath,numX,numY,numMode,optNumID)
		if self.id ~= nil then obj.remove(self) end
		self.id = image(strPath,numX,numY,numMode,optNumID)
		return self.id
	end
	obj.remove = function(self)
		if self.id ~= nil then
			freeimage(self.id)
			return true
		end
		return false -- in case you want to validate
	end
	obj.exists = function(self) return (self.id ~= nil) end

	return obj
end

local plant1 = newImage()
-- OR
local plant1 = newImage():create(...)

plant1:create(...)
plant1:remove()

if plant1:exists() then
	-- plant1 already exists
end
untested, but should at least give you an idea of how it works. OOP can really come in handy sometimes.
edited 3×, last 06.02.15 07:57:01 am

old Re: Plant at map tiles script?

Mora
User Off Offline

Quote
Why you always send me code..
They may be not for me, or whatever.. you just waste your freetime.
Here is roleplay script that had it, but i wanna make something other.
@file cs2d RolePlay

/oa: how can i place hud on the map x,y? example
hudtxt (for everyone can see it)
21 (tilex or just x pixels on the map)
22 (tiley or just y pixels on the map)
these numbers (21,22) just as example.
parse("hudtxt 1 "\169255128212Hudexample "..shit[id].."" 21,22")
edited 1×, last 06.02.15 02:03:44 pm

old Re: Plant at map tiles script?

Rainoth
Moderator Off Offline

Quote
You'll have to calculate the objects position relative to your own and then place the hud on your screen accordingly. I'm at school atm so I can't help you now but I think Engin33r made a script like that.

old Re: Plant at map tiles script?

Mora
User Off Offline

Quote
@user Rainoth: Yeah i know his "Survive some days" or something like it.
But his style of making lua is make me confused .-.
Calculate objects? it's can be for example tile on the map? or just entity that cannot be used w/o triggers (dyn_wall for ex).
/P.s-ah Engin33r, yea, i'll ask him .-.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview