Forum

> > CS2D > Scripts > Tables and random spawns ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Tables and random spawns ?

18 replies
To the start Previous 1 Next To the start

old Tables and random spawns ?

Kirito2K
User Off Offline

Quote
Hey us !
Today i need some help ..

What i need is so simple , it's 2 requests but easy to be made !

First quest : I need a script for a happytown , when a mod spawns he spawns in a random house of "mod" houses which in the map!
Which means i need 2 tables for this script , i think ..

Second quest : I need a script allows only mods to get in a special and other players just can't in!

old Re: Tables and random spawns ?

G3tWr3ck3d
User Off Offline

Quote
Create your tables and use the spawn hook.

admin = {x,y}
mod = {x,y}

function spawn(id)
if level[id] == admin then
parse("setpos '..id..' '..admin[1]..' '..admin[2]")
end
end

old Re: Tables and random spawns ?

Mora
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
mods = {114940}

addhook("spawn","_sp")
function _sp(id,tilex,tiley)
	for _,modsusgn in ipairs(mods) do
		if player(id,"usgn")==modsusgn then
rand_sp={"100 100","500 500","240 130"}
parse("setpos "..id.." "..rand_sp[math.random(1,#rand_sp)])
		end
	end
end

you have to add more pos to the table "rand_sp". Good luck.

old Re: Tables and random spawns ?

Kirito2K
User Off Offline

Quote
user Mora's one is good , i used it !

Anyway ! , now i need another script for the houses!

It prevent the normal players from getting into a area can be modified by some entity in the editor !
edited 1×, last 13.09.15 04:57:33 pm

old Re: Tables and random spawns ?

Rainoth
Moderator Off Offline

Quote
Please mind that I haven't used lua for quite a while so there might be problems.
Here's the code: >

It should do what you're asking for. If you want to include more possible houses to spawn in, write them. It will spawn the person in a random house. Coordinates are in tiles not pixels. If you want to make an impassable area, make any entity and name it either 'No' or 'Impassable' or 'NoEntry'
Say if there's anything wrong and I'll see if I can fix that.
edited 1×, last 13.09.15 07:39:20 pm

old Re: Tables and random spawns ?

Kirito2K
User Off Offline

Quote
@user Rainoth: Wait , i already said that i want user Mora's script , but also i need the second script of that house u made , i can't understand about it a bit, it will be better if you mix with this script below with your house script!
Script >

old Re: Tables and random spawns ?

Rainoth
Moderator Off Offline

Quote
What's not to understand there?
• Change numbers to fit tile coordinates that you need
• Create an entity where people cant go and name it 'Impassable'
• Try running the script

You don't have to understand anything. Also, you didn't say that we were supposed to mix user Mora' script (which btw requires you to calculate coordinates in pixels by yourself). All you have to do is change the numbers to fit your map. Please tell me you've got enough brain to edit a few numbers .-.

old Re: Tables and random spawns ?

Kirito2K
User Off Offline

Quote
@user Rainoth: The spawning stuff is working well but the house thingy gives a error when the server starts !
Errors >

old Re: Tables and random spawns ?

Rainoth
Moderator Off Offline

Quote
Wut. House thingy IS the spawning stuff.
But I can see the error. I was copy pasting and so there's two 'x' instead of 'x' and 'y'. Let me correct the code and then you copy it from the post where I put it

old Re: Tables and random spawns ?

Rainoth
Moderator Off Offline

Quote
Ah that. No problem. Give me some time (a day at most).

// Oke, here's the code
Click me! >

All you have to do is change pk.Type (line 5) into the number of which entity it has to be. I don't know the type IDs and cs2d.com doesn't provide them so you'll have to print out the type ID by yourself (that much I'm sure you can do) OR wait for someone else to write them
edited 1×, last 14.09.15 03:02:00 pm

old Re: Tables and random spawns ?

Kirito2K
User Off Offline

Quote
@user Rainoth: Not working , got another bug , u didn't get it so too btw !
I need the entity to be modified by name AND type , not one of them!

here's the bug below ..
1
2
3
4
[15:09:05] LUA ERROR: sys/lua/HT2.lua:23: bad argument #3 to 'inentityzone' (number expected, got nil)
[15:09:05]  -> [C]: in function 'inentityzone'
[15:09:05]  -> sys/lua/HT2.lua:23: in function <sys/lua/HT2.lua:22>
[15:09:05]  -> in Lua hook 'movetile', params: 1, 6, 1

old Re: Tables and random spawns ?

Rainoth
Moderator Off Offline

Quote
That's not possible. At least I don't know how I'd do it. inentityzone has only 3 arguments (x to be checked, y to be checked, entity type). It's the only way to check if you're in the zone. If you want it by name, you use one entity for one tile. If you want one entity for an area of tiles, you'll have to use my method. It's just how CS2D works.

In the future I'd advise to write what you want properly. You didn't say that you wanted it both by name and inentityzone so how was I supposed to 'get you'???

TL;DR choose one method.

old Re: Tables and random spawns ?

Kirito2K
User Off Offline

Quote
Can't we just add
1
if entity(x,y,"name") == "NoEntry" or entity(x,y,"name") == "Impassable" or entity(x,y,"name") == "No" then
Before
1
if inentityzone(x,y,pk.Type) then

or simply modifying the zone using env_hurt with 0 valve ??

old Re: Tables and random spawns ?

Rainoth
Moderator Off Offline

Quote
@Option 1: No you can't because it's looking for ENTITY at X|Y
So lets say you've got a 5 tile wide gap which you want to close
If you want your method to work you'd have to do:
X - entity, O - space covered by entity
1
X X X X X
Then it would work but then why would you need inentityzone?
Cause when you've got
1
X O O O O
(with inentityzone) and say you're here
1
X O P O O
then you're looking for entity but it's not there (only a zone covered by entity in another tile)
@Option 2: Ye, it could work with any kind of entity that covers area. env_hurt would be no exception however it would work on ALL env_hurt entities. I'd rather suggest using _NoBuildings.

TL;DR choose one method.

old Re: Tables and random spawns ?

Kirito2K
User Off Offline

Quote
Then i would like to use the x|y x|y thingy , but i need a example for it so i can understand , btw ur X and O things didn't get them at all ..

old Re: Tables and random spawns ?

Rainoth
Moderator Off Offline

Quote
Quote
Then i would like to use the x|y x|y thingy

Wat. There's no x|y thingy in my script when talking about disallowing entry on a tile.

I'll just assume that you want to use the "entity with name "NoEntry"" method and place an entity everywhere that's supposed to be impassable

Replace
1
if inentityzone(x,y,pk.Type) then
with
1
if entity(x,y,"name") == "NoEntry" or entity(x,y,"name") == "Impassable" or entity(x,y,"name") == "No" then
in my code. I'm sure you can do that much.

old Re: Tables and random spawns ?

Kirito2K
User Off Offline

Quote
@user Rainoth: About the X|Y i meant i write X to X , Y to Y , but i got idea that it using env_room , i don't use that entity at any place , so it will be a good idea for mod houses only!

I think that i have to use this
code, right ? >


but i got a error last time i used it here it is below
Pirates killer has written
1
2
3
4
[15:09:05] LUA ERROR: sys/lua/HT2.lua:23: bad argument #3 to 'inentityzone' (number expected, got nil)
[15:09:05]  -> [C]: in function 'inentityzone'
[15:09:05]  -> sys/lua/HT2.lua:23: in function <sys/lua/HT2.lua:22>
[15:09:05]  -> in Lua hook 'movetile', params: 1, 6, 1


EDIT : Any help ?? none answered me ?
edited 1×, last 16.09.15 04:07:22 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview