Forum

> > CS2D > Scripts > how to use ai_build
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch how to use ai_build

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

alt how to use ai_build

DragonAwper
User Off Offline

Zitieren
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

alt Re: how to use ai_build

palomino
User Off Offline

Zitieren
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.

alt Re: how to use ai_build

DC
Admin Off Offline

Zitieren
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
1× editiert, zuletzt 04.03.11 10:08:32

alt Re: how to use ai_build

EngiN33R
Moderator Off Offline

Zitieren
@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.

alt Re: how to use ai_build

DC
Admin Off Offline

Zitieren
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)

alt Re: how to use ai_build

DragonAwper
User Off Offline

Zitieren
>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

alt Re: how to use ai_build

J4x
User Off Offline

Zitieren
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

alt Re: how to use ai_build

Banaan
User Off Offline

Zitieren
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...

alt Re: how to use ai_build

J4x
User Off Offline

Zitieren
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
2× editiert, zuletzt 05.03.11 16:22:08

alt Re: how to use ai_build

DannyDeth
User Off Offline

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

alt Re: how to use ai_build

EngiN33R
Moderator Off Offline

Zitieren
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)

alt Re: how to use ai_build

DragonAwper
User Off Offline

Zitieren
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?

alt Re: how to use ai_build

TimeQuesT
User Off Offline

Zitieren
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)

alt Re: how to use ai_build

J4x
User Off Offline

Zitieren
@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

alt Re: how to use ai_build

DragonAwper
User Off Offline

Zitieren
×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.
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht