PDA

View Full Version : [SCRIPT] Perfect Host Detection Script



chrisk123999
April 24th, 2011, 07:50 PM
1. Place a vehicle (warthog works best) in Sapien in a in-accessible location (preferably a "sync" room). Name it "host_hog". Make sure the vehicle is set NOT to spawn automatically on any gametypes.
2. Make a trigger volume that just barley fits around the vehicle. Name it "host_vol".
3. Make a cutscene camera flag in the room. Name it "host_cam".
4. Use this script:

(global boolean is_host false)
(global boolean is_dedicated false)
(script startup host_detection
(sleep 5)
(if (= (list_count (players) ) 0)
(set is_dedicatedtrue)
)
(object_pvs_set_camera host_cam)
(object_create_anew host_hog)
(sleep 30)
(if (= (volume_test_object host_vol host_hog) 1)
(set is_host true)
)
)
5. ???
6. Profit!

Explanation: This script works because the host spawns a warthog and it sits there. When a client joins they create another warthog that bounces off the server's warthog and falls outside the trigger volume. The PVS camera point is there so the game doesn't optimize the physics out and stop it from working when there are no players near it. This script even works on the race gametype! (Unlike most other host detection scripts.) The dedicated server detection is simply counting the number of players on the map during the first tick of the game, if there are none it means it's a dedicated server.

I had this script sitting around for awhile and though maybe other people could use it for their maps. This is a simplified version of the script used on Yoyorast Island V2.

Kornman00
April 24th, 2011, 09:31 PM
Simple and effective. Good stuff chrisk. Will probably add some similar script functions for use in OpenSauce (eg, "(machine_is_host)").