right, i desided to make a simple AI script to sync AI and so on. the idea is that the target sync cog (i never did find out if i need it or not) and the AI server are in the placed cogs window
then copys of the AI_basic cog (one for eatch type of enermy template can be added to a temple with a ghost parent and no 3do. simple idea really..
but the cog wont work. and i dont know why.
if you are going to fix this cog i woudl prefer it if you just fix the cog as it is without rewriteing it from scratch. but if you cant i wont mind that mutch.
AI basic code
AI server code
AI targeting code
i know JK is ment to be haveing a revial, i hope cog is too.
as you can see i have added decriptions of what everythign dose, and good old parsec says its clean, so i dont really know whats wong
------------------
I am Darth PJB!
well, go on, run away!
i have a plastic lightsaber and a jedi cape.. am i a nerd?
If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
then copys of the AI_basic cog (one for eatch type of enermy template can be added to a temple with a ghost parent and no 3do. simple idea really..
but the cog wont work. and i dont know why.
if you are going to fix this cog i woudl prefer it if you just fix the cog as it is without rewriteing it from scratch. but if you cant i wont mind that mutch.
AI basic code
Code:
# JK cogscript # # PJ_AI_base.cog # # tell the AI server we have another AI # note you need a new copy of this for every different template # IE. the TPL assignment for the AI and the team int is the AI's # team, it will not attack a AI with the same team int, but can # attack any AI without it. works on the players team too, # set it to -1 if you want it to allways attack anyone, finaly # the int, dist is the maximum distance a target is away from the # AI before it wont attack it, distance in JKU. # cog only runs on the server's computer, so we know that its the # right AI being synced # # 13/jan/2004 # [PJB] symbols message trigger message user0 message user1 message created message pulse message timer thing pos local # template servertpl=serv local flex killsleep=0 local cog AI_server local int i=0 local thing AI local # the items below here (team maximum distance and template must be set int dist=5 local int team=-1 local template tpl=stormtroop2 local end # ======================================================================================== code trigger: // check if its the right trigger if(getsourceref()!=135)return; AI_server=getparam(0); return; created: if(IsServer()==0) return; // find the (after) killsleep, then remove the timer so we can create // the thing later, without it being destroyed by the thinglife (timer) pos=getsenderref(); killsleep=getlifeleft(pos); SetLifeLeft(pos, 0); // now we have all we need lets send a nice user0 to the Ai server // and watch the mayhem start, dammit i own SendMessageEx(AI_server, user0, tpl, pos, killsleep, team); settimer(1.5); Return; user0: if(IsServer()==0) return; // this will send all the AI information to the AI_server when the AI // needs to respawn. back and fourth we go SendMessageEx(AI_server, user2, tpl, pos, killsleep, team); return; user1: if(IsServer()==0) return; // this part of the cog will sync the AI and its target // (target via second server trigger?) AI=getparam(0); setpulse(0.1); return; timer: if(IsServer()==0) return; // this timer is to send a message to the main cog in order // to store this cog in a heap. SendMessage(AI_server, user1); return; pulse: if(IsServer()==0) return; // sync pos (why did LEC not do this in the engine *yawn* syncthingpos(AI); // sync target (this will target the first actor/player the // ai can see, check if its on teh same team, if not attack // unfortunatly this means that the AI will allways attack // the thing with the lowest thing number and the correct // peramiters, but i cant think how to check everything. for(i=0; i <= getthingcount(); i=i+1) { if(hasLOS(AI,i)) { if(GetThingType(i)==2 || GetThingType(i)==10) { if(getthingtype(i)==2) if(GetThingUserData(i)==team) { if(getthingtype(i)==10) if(GetPlayerTeam(i)==team) { if(VectorDist(getthingpos(i), getthingpos(AI))<=dist) { if(team != -1) { if(getthinguserdata(i) != team) { // the actors target is avalible, so we can set it as the // target and send the message (team mode) SendTrigger(-1, 145, AI, i, 0, 0); return; } } else if(team == -1) { // the actors target is avalible, so we can set it as the // target and send the message (no team mode) SendTrigger(-1, 145, AI, i, 0, 0); return; } } } } } } } // if you get to here with not target, theres nothing for the AI to attack // so turn its AI off. AISetMode(AI, 0x2000); return; end
AI server code
Code:
# JK cogscript # # PJ_AI_server.cog # # this is the big stuff, the main AI controle cog, # as you can see eatch of the decore AI ghost templates cogs # send the infromation to this cog, by adding userdata to the # things we can find them easaly, i may also try other ways. # again runs only on the server. # # 13/jan/2004 # [PJB] symbols message user0 message user1 message user2 message startup message killed message timer thing AI local thing AIT local int ainum=0 local int totnum=0 local cog AI_cog local int i=0 local int inplay=0 local cog me local end code startup: me=GetSelfCog(); sendtrigger(-1,135,me,0,0,0); if(IsServer()==0) return; // set the timer for the heap. as all the AI // must be registerd first. (ainum) settimer(1); // also find the number of things before the // AI are created. totnum=getthingcount(); return; user0: if(IsServer()==0) return; // very basic, get the paramiters to make the thing. ainum=ainum+1; AI=FireProjectile(getparam(0),getparam(1), -1, -1, '0 0 0', '0 0 0', 0, 0, 0, 0); setthinguserdata(AI,getparam(3)); capturething(AI); // send a user1 back to the cog to sync the thing and its target sendmessageex(getsenderref(),user1,AI,0,0,0); return; user1: if(IsServer()==0) return; // this is where we add the information we need to the // heap, in this case we are going to add the cog's of the // correct things. then when we are ready we can ask the cog // to send the information we need, so we dont get to complex // neat system eh? heapset(getparam(0), getsenderref()); return; user2: if(IsServer()==0) return; for(i=0; i<=inplay; i=i+1) { if(hasLOS(GetPlayerThing(i),getparam(0))) { sleep(getparam(2)); SendMessage(getsenderref(), user0); return; } } AI=FireProjectile(getparam(0),getparam(1), -1, -1, '0 0 0', '0 0 0', 0, 0, 0, 0); capturething(AI); return; killed: if(IsServer()==0) return; // the AI was killed, so respawn it at the orginal location // (may add LOS later) AIT=getthingparent(getsenderref()); AI_cog=heapget(AIT); SendMessage(AI_cog, user0); // this fun bit of code finds the number of players in the game for(i=0;i <= 32; i=i+1) { if(GetPlayerThing(i)==-1) { inplay=i-1; return; } Else if(i==32) inplay=32; } return; timer: if(IsServer()==0) return; // change this to timer EX for the killsleep HeapNew(totnum+1, (ainum*3)+totnum); return; end
AI targeting code
Code:
# JK cogscript # # PJ_AI_target.cog # # this cog will change the target of the AI so its synced # # 13/jan/2004 # [PJB] flags=0x140 # local cog (i hope) symbols message trigger thing AI local thing target local end # ======================================================================================== code trigger: // check if its the right trigger if(getsourceref()!=145)return; // get AI and target AI=getparam(0); target=getparam(1); // clear disabled mode if AI is disabled if(AIGetMode(AI)==0x2000) AIClearMode(AI, 0x2000); // attack! AISetFireTarget(AI, target); return; end
i know JK is ment to be haveing a revial, i hope cog is too.
as you can see i have added decriptions of what everythign dose, and good old parsec says its clean, so i dont really know whats wong
------------------
I am Darth PJB!
well, go on, run away!
i have a plastic lightsaber and a jedi cape.. am i a nerd?
If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
I am Darth PJB!
well, go on, run away!
i have a plastic lightsaber and a jedi cape.. am i a nerd?
If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
well, go on, run away!
i have a plastic lightsaber and a jedi cape.. am i a nerd?
If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?