PDA

View Full Version : How stable is this script?



Inferno
January 28th, 2009, 08:09 PM
I'm trying to write a is_server check script that will work on race. I can't use the normal server check because the check warthog does not spawn on race which screws up the script.

My script basically checks to see if there is anyone in the game. If there is no one in the game its a dedicated server and the dedicated server becomes is_server true. If there is someone in the game your script attempts to kill you. If the script kills you that means you are host and makes you is_server true. If it does not kill you that means you are a client and you have no control over the server and you are set to is_server false.

I've tested this by creating a local server and by creating a dedicated server and joining it from the same computer. Both of those tests worked. I haven't tested joining a local hosted game and I haven't tried having more than 2 players in a server.


(script startup "is_server check"
(sleep 5)
(if ( = (unit_get_health (unit (list_get (players) 0 ) ) ) 1 )
(begin
(unit_kill (unit (list_get (players) 0 ) ) ) (sleep 5)
(if (and ( = (unit_get_health (unit (list_get (players) 1 ) ) ) -1 ) ( = (unit_get_health (unit (list_get (players) 0 ) ) ) -1 ))

(begin (set is_server true) )
(set is_server false)
)
)
(begin
(begin (set is_server false) )
(begin (set is_server true) (object_create is_dedicated) )
)
)
)

(script continuous "test"
(if (= is_server true)
(sv_say "I am the server")
(sleep 10)
)
(if (= is_race true)
(sv_say "Gametype is Race")
(sleep 10)
)
)It seems to work but I'm not sure if it will work properly all the time. I'm wondering if there is something that can break this script that I should know about.

sdavis117
January 28th, 2009, 08:14 PM
Me and my limited scripting skills see nothing wrong.

But just incase (and for the lulz):



(script startup "is_server check"
(sleep 5)
(if ( = (unit_get_health (unit (list_get (players) 0 ) ) ) 1 )
(begin
(unit_kill (unit (list_get (players) 0 ) ) ) (sleep 5)
(if (and ( = (unit_get_health (unit (list_get (players) 1 ) ) ) -1 ) ( = (unit_get_health (unit (list_get (players) 0 ) ) ) -1 ))

(begin (set is_server true) )
(set is_server false)
)
)
(begin
(begin (set is_server false) )
(begin (set is_server true) (object_create is_dedicated) )
)
)
)

(script continuous "test"
(if (= is_server true)
(sv_say "I am the server")
(sleep 10)
)
(if (= is_race true)
(sv_say "Gametype is Race")
(sleep 10)
)
(if (= script broken)
(detonate nuke)
)
)

Inferno
January 28th, 2009, 08:33 PM
I made some changes to the script. I also fixed the race check for dedicated servers.

Here is the entire script for the vehicle spawning. The purpose of this entire thing is to have properly spawning vehicles on race. Me an yoyorast want race to be a fun and balanced game type on v2. V1 race had a lot of broken stuff and I'm trying to fix this with script spawned vehicles.


(script startup "is_race check"
(object_create is_race_check)
(sleep_until ( = (unit_get_health (unit (list_get (players) 0 ) ) ) 1 ) )
(sleep 50)
(if ( = (unit_get_health is_race_check) 0 )
(begin (set is_race true) )
(begin (set is_race false) )
)
)


(script startup "is_server check"
(sleep 5)
(if ( = (unit_get_health (unit (list_get (players) 0 ) ) ) 1 )
(begin
(unit_kill (unit (list_get (players) 0 ) ) ) (sleep 5)
(if (and ( = (unit_get_health (unit (list_get (players) 1 ) ) ) -1 ) ( = (unit_get_health (unit (list_get (players) 0 ) ) ) -1 ))

(begin (set is_server true) )
(set is_server false)
)
)
(begin
(begin (set is_server false) )
(begin (set is_server true) (object_create is_dedicated) )
)
)
)

(script continuous "test"
(if (= is_server true)
(begin (sv_say "I am the server") (if (= is_race true) (sv_say "Gametype is Race") ) )
(sleep 10)
)
)


(script continuous deadwer
(begin (if (= (volume_test_object dead (list_get (players)0))true)(begin (unit_kill (unit (list_get (players)0)))))
(if (= (volume_test_object dead (list_get (players)1))true)(begin (unit_kill (unit (list_get (players)1)))))
(if (= (volume_test_object dead (list_get (players)2))true)(begin (unit_kill (unit (list_get (players)2)))))
(if (= (volume_test_object dead (list_get (players)3))true)(begin (unit_kill (unit (list_get (players)3)))))
(if (= (volume_test_object dead (list_get (players)4))true)(begin (unit_kill (unit (list_get (players)4)))))
(if (= (volume_test_object dead (list_get (players)5))true)(begin (unit_kill (unit (list_get (players)5)))))
(if (= (volume_test_object dead (list_get (players)6))true)(begin (unit_kill (unit (list_get (players)6)))))
(if (= (volume_test_object dead (list_get (players)7))true)(begin (unit_kill (unit (list_get (players)7)))))
(if (= (volume_test_object dead (list_get (players)8))true)(begin (unit_kill (unit (list_get (players)8)))))
(if (= (volume_test_object dead (list_get (players)9))true)(begin (unit_kill (unit (list_get (players)9)))))
(if (= (volume_test_object dead (list_get (players)10))true)(begin (unit_kill (unit (list_get (players)10)))))
(if (= (volume_test_object dead (list_get (players)11))true)(begin (unit_kill (unit (list_get (players)11)))))
(if (= (volume_test_object dead (list_get (players)12))true)(begin (unit_kill (unit (list_get (players)12)))))
(if (= (volume_test_object dead (list_get (players)13))true)(begin (unit_kill (unit (list_get (players)13)))))
(if (= (volume_test_object dead (list_get (players)14))true)(begin (unit_kill (unit (list_get (players)14)))))(if (= (volume_test_object dead

(list_get (players)15))true)(begin (unit_kill (unit (list_get (players)15)))))))

(script startup "vehicle spawn"
(sleep_until ( = (unit_get_health (unit (list_get (players) 0 ) ) ) 1 ) )
(sleep 90)
(if ( and (= is_server true) (= is_race true) )
(begin
(object_create rhog_1)
(object_create hogturretv)
(object_create main_gate_hog)
(object_create ramp_gate_hog)
(object_create flag1_gate_hog)
(object_create flag2_gate_hog)
(object_create panic1_shield_hog)
(object_create panic2_shield_hog)
(object_create panic3_shield_hog)
(object_create hallway1_shield_hog)
(object_create hallway2_shield_hog)
(object_create pathway_gate_hog)
(object_create yohog_1)
(object_create yohog_2)
(object_create yohog_3)
(object_create yohog_4)
(object_create yohog_5)
(object_create yohog_6)
(object_create mongoose_1)
(object_create mongoose_2)
(object_create ghost_1)
(object_create ghost_2)
)
)

)

(script continuous "Special Condition Respawn"
(if ( = (volume_test_object vehicletrigger hogturretv) true)
(object_teleport hogturretv hogturret)
)
(if ( = (volume_test_object vehicletrigger yohog_1) true)
(object_teleport yohog_1 yohog_1)
)
(if ( = (volume_test_object vehicletrigger yohog_2) true)
(object_teleport yohog_2 yohog_2)
)
(if ( = (volume_test_object vehicletrigger yohog_3) true)
(object_teleport yohog_3 yohog_3)
)
(if ( = (volume_test_object vehicletrigger yohog_4) true)
(object_teleport yohog_4 yohog_4)
)
(if ( = (volume_test_object vehicletrigger yohog_5) true)
(object_teleport yohog_5 yohog_5)
)
(if ( = (volume_test_object vehicletrigger yohog_6) true)
(object_teleport yohog_6 yohog_6)
)
(if ( = (volume_test_object vehicletrigger mongoose_1) true)
(object_teleport mongoose_1 goose_1)
)
(if ( = (volume_test_object vehicletrigger mongoose_2) true)
(object_teleport mongoose_2 goose_2)
)
(if ( = (volume_test_object vehicletrigger ghost_1) true)
(object_teleport ghost_1 ghost_1)
)
(if ( = (volume_test_object vehicletrigger ghost_2) true)
(object_teleport ghost_2 ghost_2)
)
(if ( = (volume_test_object vehicletrigger mongoose_3) true)
(object_teleport mongoose_3 goose_3)
)
(if ( = (volume_test_object vehicletrigger mongoose_4) true)
(object_teleport mongoose_4 goose_4)
)
(if ( = (volume_test_object vehicletrigger rhog_1) true)
(object_teleport rhog_1 rhog_1)
)
)

Limited
January 28th, 2009, 08:50 PM
But, if your host does that mean you get killed all the time?

Inferno
January 28th, 2009, 08:59 PM
No it only kills you once when the game starts and the script only runs for the race game type.
Also yet another fix I made. There was a glitch where if the host was dead when you joined the game thought you were a dedicated server.


(script startup "is_server check"
(sleep 5)
(if ( = (unit_get_health (unit (list_get (players) 0 ) ) ) 1 )
(begin
(unit_kill (unit (list_get (players) 0 ) ) ) (sleep 5)
(if (and ( = (unit_get_health (unit (list_get (players) 0 ) ) ) -1 ) ( = (unit_get_health (unit (list_get (players) 1 ) ) ) -1 ) ( = (unit_get_health (unit (list_get (players) 2 ) ) ) -1 ) ( = (unit_get_health (unit (list_get (players) 3 ) ) ) -1 )
( = (unit_get_health (unit (list_get (players) 4 ) ) ) -1 ) ( = (unit_get_health (unit (list_get (players) 5 ) ) ) -1 ) ( = (unit_get_health (unit (list_get (players) 6 ) ) ) -1 ) ( = (unit_get_health (unit (list_get (players) 7 ) ) ) -1 ) )

(begin (set is_server true) )
(set is_server false)
)
)
(begin
(if (or ( = (unit_get_health (unit (list_get (players) 0 ) ) ) 1 ) ( = (unit_get_health (unit (list_get (players) 1 ) ) ) 1 ) ( = (unit_get_health (unit (list_get (players) 2 ) ) ) 1 ) ( = (unit_get_health (unit (list_get (players) 3 ) ) ) 1 )
( = (unit_get_health (unit (list_get (players) 4 ) ) ) 1) ( = (unit_get_health (unit (list_get (players) 5 ) ) ) 1 ) ( = (unit_get_health (unit (list_get (players) 6 ) ) ) 1 ) ( = (unit_get_health (unit (list_get (players) 7 ) ) ) 1 ) )
(begin (set is_server false) )
(begin (set is_server true) (object_create is_dedicated) )
)
)
)
)Edit-
Updated again I replaced a player 0 with 1 and it messed it up.