Jump to content
Sign in to follow this  
AdirB

AI spawns twice

Recommended Posts

For a quick way use this

 

trigger repeating

 

cond round (time %1) ==1

on act copytoclipboard str getpos player;hint str getpos player

 

Now when you move around your position is displayed and is also copied to the clipboard so you can paste it into your code

when you find a good location.

 

In Eden the position of objects is shown in one of the menus but Eden isn't working in DEV branch today so I can't say exactly where it is.

Share this post


Link to post
Share on other sites

For a quick way use this

 

trigger repeating

 

cond round (time %1) ==1

on act copytoclipboard str getpos player;hint str getpos player

 

Now when you move around your position is displayed and is also copied to the clipboard so you can paste it into your code

when you find a good location.

WOW that's very nice, thank you! :)

 

hm I think the last thing is the if (isserver)

Is it required? I'm using it here:

if (isServer) then {
    [] execVM "base_ai_guards\hireguards.sqf";
};

In the "hireguards.sqf" there's lines that spawns a unit (GuardBoss), it checks if it's a server because when it's not it spawns the unit per machine connected. (https://forums.bistudio.com/topic/187557-ai-spawns-twice/#entry2970256)

 

That's the reason I'm asking, I don't want the AI to spawn twice, one per machine connected.

Share this post


Link to post
Share on other sites

For a quick way use this

 

trigger repeating

 

cond round (time %1) ==1

on act copytoclipboard str getpos player;hint str getpos player

 

Now when you move around your position is displayed and is also copied to the clipboard so you can paste it into your code

when you find a good location.

 

In Eden the position of objects is shown in one of the menus but Eden isn't working in DEV branch today so I can't say exactly where it is.

I think I got it.

The bohemia wiki says:

 

 

Description: Returns true if the machine (executing the command) is the server in a multiplayer game or is running single player.

Please correct me if I'm wrong.

 

"if (isServer)" checks if it's a server that runs the script and only if it's a server it will execute.

addAction can't be used by a server so it's finds out that it's not a server and not executing it.

Am I right?

Share this post


Link to post
Share on other sites

Ok, I think I understand. As you are suspecting you should not use "if (isServer)..." to execute the script that hires the guards. If you do that the script will not be executed on a client machine (but on a hosted server since it's both a server and a client). But you need to use the isServer condition on the script that creates the guardboss, so it is not created twice. It's ok if the server creates the boss and a player's machine creates the hired guards (even if I think it is a better practice to always have the server create new units). When the addAction script is fired it is only executed on the client machine, and not on server or another client machine, and therefore the units will not spawn twice.

 

Remember this:

Single player: Very simple - all scripts are executed on the players machine, since it is a hosted server (a server and a client/player at the same time).

Multiplayer: More to keep in mind. There is always exactly one server, and the rest of the connected machines are clients. Scripts execute on all machines independent of the others. Scripter will need to control on which machine(s) scripts are executed.

Multiplayer on hosted server: One of the clients/players is also the server. The connected machines are just clients. The condition "if (isServer)..." will be true on the server. However, the condition "if (!isServer)..." will be true on the clients, but *not on the client that is also the server*.

Multiplayer on dedicated server: A little easier to imagine. A server is never a client/player. So the condition "if (!isServer)..." is now false on the server, but true for all other machines (the clients/players). You can use condition "if (isDedicated)..." to execute something only if it is a dedicated server, or maybe the more useful "if (!isDedicated)..." to execute something for all clients/players (but not on a dedicated server).

 

Did you see my suggestion to get the position? You can put a marker in the editor, and then read the marker's position with the command "getMarkerPos". That way you can move the markers around without having to change the script.

_pos = getMarkerPos "MyMarker";

What I cannot explain is why your position's z value is as high as 16732. That is 17 km up in the air, and makes me think that the x and y values may be way off too... z should be 0. Your position [14737.639,17.91,16731.543] seem to be somewhere on the right side of a large map (so it cannot be Stratis) and only 17.9 meters from the lower edge of the map (if you're on Stratis or Altis that is in the water) and then some km up in the air as mentioned earlier.

Share this post


Link to post
Share on other sites

Ok, I think I understand. As you are suspecting you should not use "if (isServer)..." to execute the script that hires the guards. If you do that the script will not be executed on a client machine (but on a hosted server since it's both a server and a client). But you need to use the isServer condition on the script that creates the guardboss, so it is not created twice. It's ok if the server creates the boss and a player's machine creates the hired guards (even if I think it is a better practice to always have the server create new units). When the addAction script is fired it is only executed on the client machine, and not on server or another client machine, and therefore the units will not spawn twice.

 

Remember this:

Single player: Very simple - all scripts are executed on the players machine, since it is a hosted server (a server and a client/player at the same time).

Multiplayer: More to keep in mind. There is always exactly one server, and the rest of the connected machines are clients. Scripts execute on all machines independent of the others. Scripter will need to control on which machine(s) scripts are executed.

Multiplayer on hosted server: One of the clients/players is also the server. The connected machines are just clients. The condition "if (isServer)..." will be true on the server. However, the condition "if (!isServer)..." will be true on the clients, but *not on the client that is also the server*.

Multiplayer on dedicated server: A little easier to imagine. A server is never a client/player. So the condition "if (!isServer)..." is now false on the server, but true for all other machines (the clients/players). You can use condition "if (isDedicated)..." to execute something only if it is a dedicated server, or maybe the more useful "if (!isDedicated)..." to execute something for all clients/players (but not on a dedicated server).

 

Did you see my suggestion to get the position? You can put a marker in the editor, and then read the marker's position with the command "getMarkerPos". That way you can move the markers around without having to change the script.

_pos = getMarkerPos "MyMarker";

What I cannot explain is why your position's z value is as high as 16732. That is 17 km up in the air, and makes me think that the x and y values may be way off too... z should be 0.

 

THANK YOU! :)

I understand the client, server, dedicated now, I'll keep it in mind.

 

I did see your suggestion about getting a position with a marker.

I used it in other mission that I've created, it's extremely useful, thanks.

 

The reason I won't use the marker getPos is that I'm gonna position the AI's on the players base location which is variabled somehow in the Exile mod.

 

Thing I'm gonna do is check if the player has a base and if he is the server will check its location, then spawn the AI in there.

The AI will be friendly to the base own player and his base partners.

 

Then the AI will start patrolling in a radius which is variabled too somehow in the Exile mod.

 

Thank you again :)

Share this post


Link to post
Share on other sites

Glad to help! Good luck!

Thanks :)

Share this post


Link to post
Share on other sites

I never do MP stuff so server stuff is beyond me.

When you do have trouble with a script not seeming to run just place something simple in the script that you know works.

 

Hint "check1";

 

if that line isn't seen when you run the preview you know something is wrong, then you can add more throughout the script to see what is working or what is failing.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×