Home   Help Search Login Register  

Author Topic: spawn 1 ai thats joins...  (Read 3122 times)

0 Members and 1 Guest are viewing this topic.

sinchi runa

  • Guest
spawn 1 ai thats joins...
« on: 07 Oct 2007, 23:59:58 »
greetings,

in MP i understand how to create respawn points for the players and vehicles... however..

1. how does a player have 1 ai spawn ( i.e. sabatouer2) and join the player that just respawned? and if your other ai is where you died.. a way to dismiss him.


2. i know i seen it in the hundred+ hours looking through the posts here... how do units keep their names after respawn?

so it can continue to call upon a script that needs a named unit.


 :)



« Last Edit: 08 Oct 2007, 01:04:22 by sinchi runa »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: spawn 1 ai thats joins...
« Reply #1 on: 08 Oct 2007, 12:32:01 »
1) Erm, why dismiss one ai and replace him? Why not just setPos the original AI to the position of the player if that is the effect you require?
Otherwise:
Code: [Select]
// Dismiss the old unit by creating a new group for it to join.
_group = createGroup (side _oldUnit);
_oldUnit join _group;

// Create a new unit directly into the player's group.
_newUnit = "Sabateur2" createUnit [getPos player, group player];

2) You'd have to define a specific identity in the description.ext file and use setIdentity on the original and newly spawned versions to make them consistent.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

sinchi runa

  • Guest
Re: spawn 1 ai thats joins...
« Reply #2 on: 08 Oct 2007, 19:06:39 »
first i want to say thank you for you reply.. though i don't understand how or why it works...

as per Q1: do you mean that when a player dies and respawns at "respawn_west" and the ai is on the other side of the map where the player was killed, there is a way to move the ai to the player after their respawn?

so i would need some kind of check to see if and when the ai dies, and then added to the code you have given should create something like a full time guardian angel.??


as per Q2: could you show me an example of how to do "define a specific identity in the description.ext file and use setIdentity on the original and newly spawned versions to make them consistent."

* i did look at the example in the COMREF... if i have 4 player spots named p1,p2,p3,p4 and they are all sabatouer2.. how do i mark the same unit types with different names?


i bet you guys get tired of noob questions... lol

thanks again.
« Last Edit: 08 Oct 2007, 19:13:27 by sinchi runa »

Offline Ranger

  • Members
  • *
  • Hoo-ah!
Re: spawn 1 ai thats joins...
« Reply #3 on: 08 Oct 2007, 22:30:16 »
as per Q1: do you mean that when a player dies and respawns at "respawn_west" and the ai is on the other side of the map where the player was killed, there is a way to move the ai to the player after their respawn?

You can move any unit via the setPos command.

http://community.bistudio.com/wiki/setPos

In your case, let's say the player who died is named p1, and the AI unit you want to move is named ai1.  You can use code similar to the following:

Code: [Select]
ai1 setPos (getPos p1);
That will move ai1 to p1's position.

so i would need some kind of check to see if and when the ai dies, and then added to the code you have given should create something like a full time guardian angel.??

Don't you want to check when the player unit dies, not the AI unit?  You want the AI unit to move to the respawned player, right?  If so, then you want to check when the player dies.  To do that, you can use an event handler.  See addEventHandler:

http://community.bistudio.com/wiki/addEventHandler

Specifically, you want the Killed event handler, which you will add to the player unit.

http://community.bistudio.com/wiki/Armed_Assault:_EventHandlers_List#Killed

* i did look at the example in the COMREF... if i have 4 player spots named p1,p2,p3,p4 and they are all sabatouer2.. how do i mark the same unit types with different names?

I'm not sure if you are mixing up your terminology.  My definition of a unit's name is the value in the Name field in the Insert Unit window.  See the following picture for an example:

http://community.bistudio.com/wiki/Image:ArmA_editor_unit.jpg

If that's what you mean, then the p1, p2, p3, and p4 names that you mentioned above are already giving different names to multiple units of the same type.

Are you instead asking about the description of each unit?  If so, simply enter a value in the Description field of the unit when looking at the Insert Unit window.
Ranger

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: spawn 1 ai thats joins...
« Reply #4 on: 09 Oct 2007, 11:11:23 »
@Sinchi Runa:
Ah, Ranger read your post properly, even if I didn't! I thought by name you meant name like "Fred Bloggs" not p1, so you can totally ignore what I said about setIdentity. Sorry!. If you set the name of a unit in the editor as Ranger explains, then that name will be kept for the player as long as he is alive, then for the player's corpse, but it will not be updated when the player respawns.

As far as the AI partners go, it really depends how you want them to behave. You could have the AI partner (or partners) that always teleport to the player on player respawn using a "KILLED" event handler on the player, as Ranger explained above, though "KILLED" is handled at the moment of death rather than at the moment of respawn, so it is slightly more complex than it appears:
Code: (init.sqf) [Select]
// Code has been tested for syntax errors, but no MP testing.
// This killed handler moves any surviving AI to the player's location on respawn, as well as reassociating the name of the player with the respawned player:
_killedHandler =
{
    // Player has died at this point, so we must spawn a new process so that we can wait for respawn.
    _this spawn
    {
         _deadPlayer = _this select 0;

         // Wait until the player respawns (player name will point at the corpse until respawn).
         waitUntil { (player != _deadPlayer) and (not (isNull player)) };

         // Reassign the player name to the respawned player object and make sure all machines are aware of this change.
         _playerNameStr = vehicleVarName _deadPlayer; // Find out the name of the player.
         call compile format ["%1 = player", _playerName]; // Reassign the name to the respawned player.
         publicVariable _playerNameStr; // Broadcast the name to all machines in MP.
         _deadPlayer setVehicleVarName ""; // The corpse doesn't have a name any more.

         // Move the AI(s) in the player leader's group, if still alive, to the player's current (respawn) position.
         {
             if ((alive _x) and (not (isPlayer _x)) and ((leader _x) == player)) then
             {
                  _x setPos (getPos player);
             };
         } forEach (units (group player));

         // Any other things you want to happen to newly respawned players could be placed here.
    };
};

// If a dedicated client, wait until synchronised.
if (not isServer) then
{
    waitUntil { not (isNull player) };
};

// Unless we're on the dedicated server, add a local handler for when the player dies.
if (not (isNull player)) then
{
    player addEventHandler ["KILLED", _killedHandler];
};

This code assumes that the players are in seperate groups, each having one or more AI soldiers under their command. If there were more than one player in the group, which isn't something you seemed to want, then the AI would teleport back only when the group leader respawned. Also note that if the AI is already dead by the time the player respawns, then they won't be moved or recreated at the player's respawn location, though this could easily be added to the script.

One thing you might consider is whether the scripts you are using, that require player names to operate, might not use "player" instead, to avoid the whole mess of updating the name! I don't know what scripts you are using, so I can't make a more informed comment than that.

** Edit **
Made some naive mistakes in my comments and the example code, which I have now corrected.
« Last Edit: 09 Oct 2007, 14:28:58 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

sinchi runa

  • Guest
Re: spawn 1 ai thats joins...
« Reply #5 on: 10 Oct 2007, 01:25:01 »
thank you both for the reply,

the int.sqf script works great.  :clap:

* i do see a error to do with 'scalar |#| bool array string.... something...' after i die and the ai comes to my respawn point.. however it does what it is supposed to do.

also here is a MP map with what i am trying to do.. please take a look and help me to understand how to:

when the ai (sabateur2) that is attached to whichever player is killed and has respawned.. make it move it to the players location.. like a teleport?

when the player dies....keep the blu_1 or blu_2 name when i respawn so i can keep calling the helotaxi?

almost got it 100%... this will make a nice template for MP mission options.

 :)

*** the map is for example only.. not submission ***
« Last Edit: 10 Oct 2007, 19:54:57 by sinchi runa »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: spawn 1 ai thats joins...
« Reply #6 on: 10 Oct 2007, 12:20:29 »
Moving my respawn script into "spawn/init.sqf" makes sense, though as is, it won't be run from in there. Just put:
Code: [Select]
[] execVM  "spawn/init.sqf";
in the main "init.sqf", rather than all the code, to call that.

In a single-player mission, you start as the soldier marked as "player" and can teamswitch to any soldier marked as "playable". In MP, you can start as any "player" or "playable" soldier. Thus, for an MP mission, it is fine to have a defined "player", since they will just act the same as "playable" in MP and it makes it easier to test in SP (since you don't have to keep marking someone as "player" when testing in SP and mark them back as "playable" in MP). Er, I hope that makes some sense!

In one of the player groups, the saboteur is the leader...I thought the saboteurs were supposed to be the AI lackeys?

Rather than making empty helocopters and moving in a complete crew of individual soldiers, why not just create Blufor helocopters which are already crewed?

The mission uses the default respawn mode (which is "bird"/seagull) so the version you uploaded wasn't the one that you tested and got an error in. No point me testing a mission that is different than the one that is broken, is there? Also, the "scalar bool array..." error means that a variable has been used although it is nil (undefined). Without knowing in what file and at what line the error occurred (or, if you are really keen, a screenshot of the entire error message) just knowing it is a "scalar bool array..." error doesn't give enough information to find the bug. I'd rather not run a complete test on a dedicated server just to discover the error message if you could just tell me what it is.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

sinchi runa

  • Guest
Re: spawn 1 ai thats joins...
« Reply #7 on: 10 Oct 2007, 19:35:05 »
@spooner.

once again your time is continuing to increase my understanding of basics...  :)

i am not sure why the map wasn't correct.. all maps are done in MP editing only.. (does that matter?)

as per the last mission... i put a copy of the init.sqf in the spawn folder just to know where it is.. it is actually in the main folder being initiated as the game starts.. not sure why i like to make copies of things.. maybe its because i'm always in them changing things i shouldn't.. hahaha...



this is the map that i have been working on.. it has been tested in MP for a couple of weeks now by several different friends.. no problems.. other than:

1. how do i get the ai (lackey) once killed and respawned.. to teleport to the (human) players location.. no matter where it is?

2. how do i keep the blu_1, blu_2.. names for the (human) players after resawning so they can continue to use the helo taxi's?

if you do try.. please do it in MP.

*** map is not for submission***


also.. none of these scripts are mine..... i'm just a noob putting together a frankenstien MP mission.

i hope you can excuse my persistent questioning... i have an insatiable appetite for knowledge.   :yes:
« Last Edit: 17 Jan 2011, 00:19:30 by savedbygrace »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: spawn 1 ai thats joins...
« Reply #8 on: 10 Oct 2007, 20:40:46 »
The map wasn't a problem as such, I was just trying to explain that setting a character as "player" is fine in MP as well as SP.

1) That is a lot more messy, since it is impossible to know who an AI is after they respawn. It might be easier to allow the AI to be respawned via script, rather than having the AI as unplayed players. I'm not sure if you want the mission playable with 4 players as well as with 2 players, each with lackeys. It is a lot more straightforward if each player has a normal AI lackey, rather than there being 2 groups of 2 players, one of which could be an AI or a player. So, what do you want?

2) Ah, I immediately see where the error comes from when I saw the full message! I made a typo in writing out my script earlier, which should have been this (I wrote _playerName instead of _playerNameStr originally, so it defaulted to nil, giving that error):
Code: [Select]
         call compile format ["%1 = player", _playerNameStr]; // Reassign the name to the respawned player.

The point of this code was to preserve the name of the player, so hopefully, you should have some joy now. Also should move the AI to the player when the player dies.

<EDIT>
Erm Blu_1 and blu_2 are names of the player groups, not of the players. Groups aren't changed when you respawn (While dead, your group changes, but you will come back in the same group when you respawn), so we may be wasting a lot of time trying to keep player names over respawn! Sure you mean blu_1 and blu_2 (group names) and not p1, p2, etc. (player names).
« Last Edit: 10 Oct 2007, 20:46:21 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

sinchi runa

  • Guest
Re: spawn 1 ai thats joins...
« Reply #9 on: 10 Oct 2007, 21:43:38 »
script has no errors now.. :good:

i understand now what you mean about the setting a player on the map.. thanks. never used the regular editor.

however.. respawn doesn't work in SP?

** i was totally using wrong terms in my first posts... such a noob :-[ ***

1. i agree a script for the player creation and ai lackey would be better..
    say 4 players for the sake of conversation... each with  1 ai lackey.
    the ai (lackey) once killed and respawned.. teleports to the (human) players location.. no matter where the player position is?
    4 two man teams 1 human/1 ai per team? AND the player leaders have to be grouped as blu_1, blu_2, blu_3,blu_4.. every spawn...otherwise the helotaxi script dies...

    the reason i did it with the ai's as playable is i couldn't get the ai to respawn after killed... let alone rejoin their 'master'  :whistle: .. still doesn't.

all i know is with the helo pickup script.. the option for airlift is not there (the mouse wheel action menu) after i die and respawn. why does the option disappear?
    and when any human player gets killed the helo script stops for all...?

i understand this is only 1 of the 10 or so scripts that make it work.. i put this here to show spooner what i mean about blu_1 and such.

TJ_INIT.SQS
Code: [Select]
;INIT


;Minumum distance from Airbase for Transport service
TrnsTrsh = 200


;all players who call Airlift must be leader and listed in the array below to get the Action command
Playerlist = [leader Blu_1, leader Blu_2, leader Blu_3, leader Blu_4]


_i = 0
_countplayers = count Playerlist
#Start

_player = Playerlist select _i
Action1 = _player addaction ["call for Airlift", "TJ72_CPUp\SET_AR_VAR.sqs"]
? _i >= _countplayers - 1: goto "End"
_i = _i + 1
goto "Start"
#END


;Arrays for using on the transports

; 0     1      2    3
;Name,Status,Type,Base
;Status types: (0)Ready,(1)Unavailable
;Transport types: (0)AIR.(1)LAND (not used yet)
etar01 = [1,0,0,1]
etar02 = [2,0,0,1]
etar03 = [3,0,0,1]
etar04 = [4,0,0,1]
etar05 = [5,0,0,1]
etar06 = [6,0,0,1]

LZ_Names =[0,"LZ_1","LZ_2","LZ_3","LZ_4","LZ_5","LZ_6"]
VECT1_Names =[0,"VC_1","VC_2","VC_3","VC_4","VC_5","VC_6"]
VECT2_Names =[0,"VC2_1","VC2_2","VC2_3","VC2_4","VC2_5","VC2_6"]
LZ2_Names= [0,"LZ2_1","LZ2_2","LZ2_3","LZ2_4","LZ2_5","LZ2_6"]




Baselist = [0,ebas01]
;List of those transport arrays
e_alltrnsp = [0,etar01,etar02,etar03,etar04,etar05,etar06]
;List of internal transport names
e_alltrnsp2 = [0,etrnspt01,etrnspt02,etrnspt03,etrnspt04,etrnspt05,etrnspt06]
;List of transport group names
e_trnsgrp = [0,etg01,etg02,etg03,etg04,etg05,etg06]

e_allbas= [0,ebas01]
exit



why is it hard to have a helo taxi system for MP? callable by any human player? using player mapclicks as to set the position to come and go? different helos for each player... that will respawn when killed?

... other than the obvious... :dunno:
   
« Last Edit: 10 Oct 2007, 23:15:30 by sinchi runa »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: spawn 1 ai thats joins...
« Reply #10 on: 11 Oct 2007, 00:47:45 »
Respawn doesn't work in SP, but it can be useful to quickly test, even an MP-only mission, in SP mode (all MP missions work in SP, or at least they should do, but anything but a very simple SP-only mission  is unlikely to work in MP).

Well, a lot of your problems are in fact limitations with the helo scripts you are using, rather than things you should be expecting to just fix up yourself. Get onto the people that wrote them and ask them to make them respawn-compatible! Something else that you might not have noticed, although it isn't a massive problem, is that if you stand near one of the other group leaders, then you will actually have two "helo pickup" actions available. Sadly, you can't assume that scripts you download are perfect and you must check all documentation for known bugs and accepted limitations. Most of the time, however, you will be able to live with the small imperfections of a script, especially if you couldn't write it yourself.

To ensure that the AI respawn, it would be better if they weren't players and you manually re-spawned them. If they could be players, then someone will end up playing as them and mess everything up! Before we start discussing how this might be scripted, you should also consider whether you want the AI lackeys to just respawn next to the player. What if the player is in a fire-fight and the AI just keeps respawning in the line of fire and keeps dying? Anyway, something to think about.

The reason that the "helo pickup" actions disappear is that all actions are placed on an object, such as the player object or a Humvee. When you die, the action stays on your corpse and you don't automatically get the action put on your re-spawned self. This effect has nothing at all to do with player names or group names being "forgotten", but is just an effect of this script you are using not having been made respawn-compatible. If the script was not actually intended to be respawn-compatible, then that is fine, of course.

As to your last comment about MP scripting, the essential problem is that in MP games you have to manage the actions of and synchronise the data on 10 (or whatever) computers all at the same time, whereas in SP, you only ever have one machine to deal with. Although it is possible to make simple MP missions without dealing with a lot of these issues, once an MP mission is non-trivial, it is very easy to get things very wrong (I know, I've messed up countless times already in MP scripting!). For example, in the helo script you are using, the helocopters are managed by the dedicated server, but each player's soldier is managed by their local machine, so, before you can get anywhere, you need to get the computers to start talking to each other...
« Last Edit: 11 Oct 2007, 00:51:33 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

sinchi runa

  • Guest
Re: spawn 1 ai thats joins...
« Reply #11 on: 11 Oct 2007, 03:47:14 »
understood about testing in the SP editor.. it is much faster.. also that some scripts aren't perfect..

hence why i am here trying to pick the brains of those who seem to have been at it for a while.

i have contacted the author of the helo script as suggested.. don't know why that never occurred to me..

too much this :cool2::blink:

i hope to hear from him soon and will post any updates about the MP part of the script.

about the ai lackey..  especially when i'm in a firefight..lol

even if there is a 2 - ?? sec delay on the respawning ai.

there doesn't seem to be much in the way of MP scripting.. is it because ArmA is new? or not too many know about it? or.. just curious.

 because it kind of zaps the fun out of making really in depth maps when they can't be played with friends.

it sucks getting downed 30 miles from the base and having no weapons... and no one to call for a ride.


about the MP scripting.. guess what your saying, is that i jumped into the deep end of the pool first.. ha!
« Last Edit: 11 Oct 2007, 04:15:50 by sinchi runa »

sinchi runa

  • Guest
Re: spawn 1 ai thats joins...
« Reply #12 on: 11 Oct 2007, 20:46:53 »
 :clap: :good: :clap:

SOLVED the issue with the airlift option in the mouse wheel menu not showing up after respawn.

created a trigger

put 'alive player' in the condition box

set it to repeatedly

In the activation of the trigger, have it run the script to populate the actions.

i.e. this exec "TJ72_CPUp\TJ_INIT.sqs" for the airlift script.


/// added ///

i found a walk around for the ai lackey in MP.

i created a marker 20x20 rectangle...
called it HireCenter.
put a trigger down over the marker and the same size...
put the trigger for blufor present, repeatedly...
and [this] exec "hire.sqs" in the Act box.

HIRE.sqs
Code: [Select]
"SoldierWSaboteurPipe2" createUnit [getMarkerPos "hirecenter", group player]
and an object.. (gravestone) for visual reference for the player.

works nice.. it only spawns a lackey for the player in the circle in MP mode.

not exactly what i was looking for.. but does the job ok in MP.

*** added updated map for example of all the scripts together *** not for submission ***

and thanks to Spooner for keeping on the right track, even when i didn't use the right terms. :)
« Last Edit: 11 Oct 2007, 21:56:34 by sinchi runa »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: spawn 1 ai thats joins...
« Reply #13 on: 13 Oct 2007, 13:45:24 »
The alive player trigger will work, but the point of using the KILLED event handler was to avoid the cost of continually running a trigger. You could put the action-creation command in the event handler code I gave earlier in the "Any other things you want to happen to newly respawned players could be placed here" section.

Yes, a more manual way to re-hire a lackey is a good idea. Unfortunately, there are a number of issues with the trigger that you are using:
- If the player moves in and out of the zone, he can get a whole squad, since there is no check to see if he already has a lackey!
- If another player is standing in the zone, then when you enter you will not get a lackey, even if the other player leaves (you would need to exit and reenter the zone when it was empty)
- If another player moves into the zone, then all players will get a new lackey!

The solution is either:

a) Change the trigger condition:
Code: (Trigger condition) [Select]
(player in thisList) and ((count (units (group player))) == 1)

b) Use an action placed on the gravestone (I'd prefer this version, since it doesn't require the trigger continually checking the condition):
Code: (Gravestone init) [Select]
this addAction ["Recruit Soldier", "HIRE.sqs"];

And change the script to:
Code: (hire.sqs) [Select]
? (count (units (group player))) != 1 : exit

"SoldierWSaboteurPipe2" createUnit [getPos player, group player]

Incidentally, there is no reason to use this in the activation box, since the value will be undefined when the trigger is activated and you don't use the passed parameters in the script anyway. Just use:
Code: (Trigger activation) [Select]
[] exec "hire.sqs"
« Last Edit: 13 Oct 2007, 13:49:54 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

sinchi runa

  • Guest
Re: spawn 1 ai thats joins...
« Reply #14 on: 16 Oct 2007, 21:17:41 »
spooner.. tried it over the weekend. it works great in MP. thanks for the time. :)

its nice to have some backup (ai) now and then.