You must be logged in to post messages.
Please login or register

AI and RM Scripting
Moderated by Crazed Ewok, Gen_Rhys_Dallows

Hop to:    
Welcome! You are not logged in. Please Login or Register.3 replies
SWGB Heaven » Forums » AI and RM Scripting » First attempt at scripting AI for SWGB:CC (also using expanding fronts)
Bottom
Topic Subject:First attempt at scripting AI for SWGB:CC (also using expanding fronts)
IceLizard
Clone Trooper
posted 01-24-19 02:31 PM EDT (US)         
Heya,

I'd like to open this thread for the opportunity at asking a few questions (I might have more later on) about AI.

Until recently, I had not played SWGB for several years, though after grabbing SWGB Saga from Steam (as I cannot seem to find the disks) I have since started again. When the MSN game zone was still alive, I used to play (and love) alot of 'Senate' scenarios. I also used to make a few senate maps, in fact using the scenario editor helped spark my interest in level design back then.

I'm interested in attempting to make a Senate map with an AI controlled senate, I've been following Wok's AI scripting tutorials, but I don't see the potential for an AI player to detect chat strings (unless it goes under another command). Is there any way I could get this AI to detect certain chat messages as a fact which follows through with an 'action' or even several 'actions'? I'd like the Senate to be able to react/respond to certain things which players say in the game chat (hopefully once i do that and learn a few more things, I can have the Senate player take some things into consideration that are said in senate meetings, we'll see).

I'm also having some issues with getting the AI senate to send messages to all of his allies, I have made the following defrule for testing purposes.


(defrule
(food-amount > 51)
=>
(chat-to-allies "Attention all governers")
(chat-to-allies "the senate is currently experiencing a severe famine")
(chat-to-allies "the capital urgently requires food supplies")
(chat-to-allies "to preserve inhabitant life.")
(chat-to-allies "Please send all auxiliary food you can spare")
(chat-to-allies "to the senate immediately.")
)

So basically, what I'm trying to define is that when the Senate has over 51 units of food, he would follow through with a sequence of messages to his allies.

However, after launching the game the Senate player sends no messages, even though his food is well above 51 units of food. I assume I'm doing something wrong but I'm not sure what. After I know how to get it to work I will change the operator to be 'below 51 units of food' <

I don't have alot of scripting knowledge, though I'm interested in learning as I think it's a part which I find interesting.

Are there any more expansive tutorials which would be relevant to this?

Thanks for the help in advance.

[This message has been edited by IceLizard (edited 01-24-2019 @ 02:33 PM).]

AuthorReplies:
rva2895
Clone Trooper
posted 01-27-19 06:44 AM EDT (US)     1 / 3       
taunt-detected is what you should use. Keep in mind you can use any, even nonexistent "taunt" number to control your AI.
If you plan to use your AI in a specific scenario only, consider looking into AI signal - AI trigger mechanics which allows scenario and AI to interact.
IceLizard
Clone Trooper
posted 01-27-19 09:41 AM EDT (US)     2 / 3       
Thanks, though aside from taunt-detected I guess there's no way for the AI to read predefined player chat messages?
pharmer
Clone Trooper
posted 01-28-19 07:13 PM EDT (US)     3 / 3       
I have been testing this code, which requests tribute

(defrule
(current-age equal tech-level-2)
(enable-timer 1 60);set food tribute timer for 60 second
;(enable-timer 2 90);set nova tribute timer for 90 second
(disable-self); set this action once
)

(defrule
(cc-players-building-type-count my-player-number 84 greater-than 0 )
(cc-players-building-type-count any-ally 84 greater-or-equal 1);need spaceport to tribute
(food-amount > 51); detect food as greater than 51
(timer-triggered 1);detects timer running
=>
(disable-timer 1);turns off timer
(chat-to-player any-ally "Attention all governors");alternate coding syntax
;(chat-to-allies "Attention all governers")
(chat-to-allies "the senate is currently experiencing a severe famine")
(chat-to-allies "the capital urgently requires food supplies")
(chat-to-allies "to preserve inhabitant life.")
(chat-to-allies "Please send all auxiliary food you can spare")
(chat-to-allies "to the senate immediately.")
(chat-to-allies-using-id 22122); this the request taunt !!
;(chat-to-allies "FOOD-PLEASE")
(enable-timer 1 180);resets timer for 180 seconds
)

;this code works (chat command)
(defrule
(metal-amount < 100)
=>
(chat-to-allies "6 I need stone, gimme stone!!")
(disable-self)
)
(defrule
;(random-number == 1)
(timer-triggered 2)
(nova-amount < 200)
=>
(disable-timer 2)
(chat-to-allies-using-id 22124)
(enable-timer 2 250)
)

The request is very wordy; the line which gets the job done is "(chat-to-allies-using-id 22122)." The reason for the timer is so the AI periodically makes the request. Otherwise, it would spam the request for as long as the facts are true (there are a lot of numbers greater than 51). Taunts are delivered thru chatting, but are detected as taunt-detected fact.

In order for the other AI's in the game to respond, the following code needs to to in that ai script.

(defrule
(current-age < tech-level-2)
(food-amount < 50)
(taunt-detected any-ally 3)
=>
(disable-timer 1)
(chat-to-player any-ally "Sorry, building economy. No spaceport")
)

(defrule
(current-age >= tech-level-2)
(food-amount < 50)
(taunt-detected any-ally 3)
(taunt-detected any-ally 5)
=>
(chat-to-player this-any-ally 2)
(chat-to-player any-ally "Sorry, building economy. Don't have enough")
)

(defrule
(taunt-detected any-ally 3);food request
(food-amount > 100)
=>
(acknowledge-taunt this-any-ally 3)
(chat-to-player this-any-ally "ok")
(tribute-to-player this-any-ally food 50 )
(chat-to-player this-any-ally "Here is 50 food")
(chat-to-player my-player-number "I sent them 50 food")
(chat-to-player-using-id this-any-ally 22120)
)


(defrule
(taunt-detected any-ally 5)
(nova-amount > 400)
=>
(acknowledge-taunt any-ally 5)
(tribute-to-player this-any-ally gold 150)
(chat-to-player this-any-ally "Here's some nova")
(chat-to-player my-player-number "Sent Nova")
)

(defrule
(taunt-detected any-ally 6)
=>
(acknowledge-taunt any-ally 6)
(tribute-to-player this-any-ally ore 50)
(chat-to-player this-any-ally "Here's some ore")
(chat-to-player my-player-number "Sent ore")
)

(defrule
(taunt-detected any-ally 1)
=>
(acknowledge-taunt this-any-ally 1)
(chat-to-player this-any-ally "You're welcome")

)

;doesn't work
(defrule
(metal-amount < 100)
=>
(taunt 6)
(disable-self)
)

;this code works (chat command)
(defrule
(metal-amount < 100)
=>
(chat-to-allies "6 I need stone, gimme stone!!")
(disable-self)
)

;and finally this code works
(defrule
(or
(or
(taunt-detected any-ally 3)
(taunt-detected any-ally 4)
)
(or
(taunt-detected any-ally 5)
(taunt-detected any-ally 6)
)
)
=>
(chat-to-allies "I am not a bank")
;(chat-to-allies ".")
(acknowledge-taunt this-any-ally 3)
(acknowledge-taunt this-any-ally 4)
(acknowledge-taunt this-any-ally 5)
(acknowledge-taunt this-any-ally 6)
)
I haven't got the thank-you part to work yet. The last part "I am not a bank" works great.
I have been having problem with my scripts because they code d for the "original eight," and do not work if civ-selected is Geonosian or Zann. The scripts are also coded for max of 250 population.

If anything is "wrong" in a script, it won't run

I hope this helps.

[This message has been edited by pharmer (edited 01-28-2019 @ 07:32 PM).]

You must be logged in to post messages.
Please login or register

Hop to:    

SWGB Heaven | HeavenGames