Forum

> > CS2D > Scripts > how to use ai_build
Forums overviewCS2D overview Scripts overviewLog in to reply

English how to use ai_build

25 replies
Page
To the start Previous 1 2 Next To the start

old how to use ai_build

DragonAwper
User Off Offline

Quote
i've tryed it:

addhook("second","trybuild")
function trybuild(id,building,x,y)
if id=="Bot" then
building = 7
x=5
y=5
end
end
============================================

Other:

============================================
addhook("startround","trybuild")
function trybuild(id,building,x,y)
if id=="Bot" then
building = 7
x=5
y=5
end
end

but it's don't work
help

old Re: how to use ai_build

palomino
User Off Offline

Quote
Evan more, correct me if I am wrong, but you've set x=5 and y=5. It means that the building will only be possible on those coordinates.

old Re: how to use ai_build

DC
Admin Off Offline

Quote
sorry but nothing of this makes much sense. it looks to me like you didn't understand the fundamental principles behind cs2d Lua scripts. you should read a Lua tutorial first and take a look at the samples.

problems I see:

× second or startround hooks for building stuff? doesn't make too much sense

× neither second nor startround have the parameters (id,building,x,y) - it doesn't work and doesn't make sense

× you check if id is "Bot" this is never true. player ids are numbers. you would have to use if (player(id,"bot")) instead

× you are changing the values of your local variables but for what reason? that doesn't change anyhting

× you are not even calling the ai_build function so it's no wonder that nothing happens
edited 1×, last 04.03.11 10:08:32 am

old Re: how to use ai_build

EngiN33R
Moderator Off Offline

Quote
@Sunny Autumn
It's not even a script, it's like Lua gibberish.

@topic
What are you trying to do exactly? Explain what do you want and then we may be able to help you.

old Re: how to use ai_build

DC
Admin Off Offline

Quote
you call this function like any function. there is no difference. but you don't call it in your posted code at all. instead you are just changing local variables - which has no effect.

(oh and maybe it is not working, I probably didn't test it after implementing it)

old Re: how to use ai_build

DragonAwper
User Off Offline

Quote
>is it more correct?

addhook("second","trybuild")
function trybuild(id,building,x,y)
if player(id,"bot") then
ai_build(7,5,5)
end
end

or this

addhook("ai_build","trybuild")
function trybuild(id,building,x,y)
if player(id,"bot") then
ai_build(7,5,5)
end
end

addhook("second","callfunc")
function callfunc()
trybuild()
end

i got this error
LUA ERROR: sys/lua/Duvido.lua:13: bad argument #1 to 'player' (number expected, got nil)

My question is Where i have to use ai_build
it's more easy if anyone post a example

old Re: how to use ai_build

J4x
User Off Offline

Quote
That's probably because the second hook didn't have the id parameter. try with this
1
2
3
4
5
6
addhook("build","trybuild")
function trybuild(id,type,x,y,mode,objectid)
if player(id,"bot") then
ai_build(id,7,5,5)
end
end

old Re: how to use ai_build

Banaan
User Off Offline

Quote
Yeah great, but ehm... a bot would need to build for that, so this wouldn't initiate (and if it would, it'd become a chain reaction).

1
2
3
4
5
6
addhook("second","trybuild")
function trybuild()
	for _,id in pairs(player(0,"tableliving")) do
		if(player(id,"bot")) then ai_build(id, 7, 5, 5) end
	end
end

I wonder how wise it is to use this on a second hook though...

old Re: how to use ai_build

J4x
User Off Offline

Quote
But the second hook will not make that bots build every second?

I think this should work too.
1
2
3
4
5
6
7
8
addhook("minute","trybuild")
function trybuild()
for i=1,32 do
if (player(id,"bot")) then
ai_build(id,7,5,5)
end
end
end
edited 2×, last 05.03.11 04:22:08 pm

old Re: how to use ai_build

DannyDeth
User Off Offline

Quote
I suggest you stop Lua scripting, Linkin. That is completely incorrect. The 'minute' hook DOES NOT contain any parametres (especially id)!

old Re: how to use ai_build

EngiN33R
Moderator Off Offline

Quote
God... That ^

You could also modify Banaan's script with a variable "did the bot build a building" and only if it's false let the bot build a building (so he wouldn't start looping)

old Re: how to use ai_build

DragonAwper
User Off Offline

Quote
i've tested all of these but nothing happened
i'm testing in con_sandbox and the tiles 5/5 are disponible

so. all of theses don't work

>Can anyone help me?

old Re: how to use ai_build

TimeQuesT
User Off Offline

Quote
At first the bot have to move to a tile near "5x 5y" for example: 4x 5y
then you must say your bot that he have to build a building there.
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
--hooks
addhook("minute","trybuild")

--functions
function trybuild()
for id=1,32 do
if (player(id,"exists") and player(id,"bot") and player(id,"health")>0 then
timer(1,"moveto",id,-1)
break;
end
end
end

function moveto(id)
p = tonumber(id)
if (player(p,"health")>0) then

if (ai_goto(p,4,5)~=1) then
--nothing
else
ai_build(p,hereyourbuilding,5,5) 
freetimer("moveto",id);
--change "hereyourbuilding" to the building id of your wanted building
end
else
freetimer("moveto",id);
end
end

this should work(i didn't test it of bugs)

old Re: how to use ai_build

J4x
User Off Offline

Quote
@Danny, I really take that as a offence, I write those parameters, because first I used the building hook, and I forgot to erase the F*cking parameters.

Sorry for that error, here the correct one:
1
2
3
4
5
6
7
8
addhook("minute","trybuild")
function trybuild()
for i=1,32 do
if (player(i,"bot")) then
ai_build(i,7,5,5)
end
end
end

old Re: how to use ai_build

DragonAwper
User Off Offline

Quote
×Sorry guys but it's don't work.
>I discovered i'm not the only that don't know how to use ai_build

√But the topic is here, and i need a solution
∗so, i'm waiting for new replies.
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview