Having problem atm with adding one Moon door in map. I got it mostly working, but atm if you go near it, it opens and closes constantly and when there is no zombies alive, it stays closed. Everything else works Here is the Radiant setup:
door_trig = getEnt("door_trig", "targetname"); door_trig setCursorHint("HINT_NOICON"); door_trig setHintstring("Press & hold &&1 to Open Door [Cost: 1000]");
If you want scripts / features made for you, then contact me by PM or email / skype etc it will cost you tho so if you have no intention of reciprocating don't even waste my time
I will test that first option. Didnt want to use your tutorial, cos 1. Seemed complicated to modify to my needs and Im just going to have one door 2. Wanted to try script it myself and 3. This map for some reason has a lot of false errors regarding "missing" scripts, so I didnt want to add more scripts in the mod
using array_thread for both zombies and players would probably be a better idea. Less code usage. Whicher way i guess.
Equal signs in both your if statement operators isn't a great idea. If both player and AI are 200 units apart then they are probably going to open and close randomly.
Also, use developer and developer_script. Might have something to help you debug further.
Your script is a bit exponential, with the checking each zombie for each player bit and won't do anything if all the zombies are dead atm. Also you use level.moving_done which will only allow you to have one door, which may be your intent seeing the way you set up your functions. You may try to modify your script like this or consider rethinking the process if you are going to have more than one.
door_trig = getEnt("door_trig", "targetname"); door_trig setCursorHint("HINT_NOICON"); door_trig setHintstring("Press & hold &&1 to Open Door [Cost: 1000]");
FYI only: My auto doors I make a prefab and setup with structs as targets for each door, and a trigger multiple. (Everything is setup as the target of something else) Then when touching the trigger if it hasn't been bought or unlocked, it shows a hint and doesn't open until you buy it. Then in a while loop I check zombies and players for touching it, and if they are it just keeps continuing. Then when they are not, the while loop ends and closes the doors. I use another struct outside the prefab to set my flags, which I get using an array and then checking for the closest struct in that array to the doors, get it's kvps and set the flag.
Last Edit: December 03, 2015, 11:03:47 pm by MakeCents
using array_thread for both zombies and players would probably be a better idea. Less code usage. Whicher way i guess.
Equal signs in both your if statement operators isn't a great idea. If both player and AI are 200 units apart then they are probably going to open and close randomly.
Also, use developer and developer_script. Might have something to help you debug further.
How would I put it to be then? Just < or do I need something else for it? @Blunt Second issue is fixed with door not moving, but immediately when zombie spawns, it starts moving back and forth like in first issue
// One struct for doors, with targetname - moon_door // two other models for your actual doors, both targeting that struct. // targetname - moon_left_door // targetname - moon_right_door // onr clip per door, also targeting the door // thread script in zombiemode, along with the others
init() { moon_doors_main(); }
moon_doors_main() { doors = getEntArray( "moon_door", "targetname" ); // Get array of all door locations doors_left = getEntArray( "moon_door_left", "targetname" ); // Get array of all "left" doors doors_right = getEntArray( "moon_door_left", "targetname" ); // Get array of all "right" doors door_clips = getEntArray( "moon_door_clips", "targetname" ); // Get array of the clips used for the doors
level.doors = []; for ( i = 0; i < doors.size; i++ ) // loop through each door location { level.doors[ i ] = doors[ i ]; // Add location to main array level.doors[ i ].open = false; // Set door to start "closed" for ( d = 0; d < doors_left.size; d++ ) // Loop through the left doors { if ( doors_left[ d ].target == doors[ i ] ) // If this left door, is targeting this door "location" level.doors[ i ].left_door = doors_left[ d ]; // Store as a property against this location. Door belongs to it
} for ( d = 0; d < doors_right.size; d++ ) { if ( doors_right[ d ].target == doors[ i ] ) // If this right door, is targeting this door "location" level.doors[ i ].right_door = doors_right[ d ]; // Store as a property against this location. Door belongs to it
} for ( d = 0; d < doors_clips.size; d++ ) { if ( doors_clips[ d ].target == doors[ i ] ) // If this clip, is targeting this door "location" level.doors[ i ].door_clip = doors_clips[ d ]; // Store as a property against this location. clip belongs to it
} level.doors[ i ] thread moon_door_watcher(); // Thread the wathcer thats checking for things coming close to the door } }
moon_door_watcher() { while( 1 ) { triggered = false; // set triggered to false zombs = getaispeciesarray("axis","all"); // Get array of AI if ( isDefined( zombs ) && zombs.size > 0 ) // Check array is real { for ( i = 0; i < zombs.size; i++ ) // Loop through AI array { if( distance( zombs[ i ].origin, self.origin ) >= 200 ) && !self.open ) // Check if zombie is in range and door is closed atm { triggered = true; // If it is, mark this loop as triggered self moon_door_open(); // Open the door break; // break from this AI checking loop, weve already found a target } } } if ( !triggered ) // Now, only cgeck the players, if the door hasnt already been triggered in this loop when checking the AI { players = get_players(); // Get player array if ( isDefined( players ) && players.size > 0 ) // Check array is real { for ( i = 0; i < players.size; i++ ) // Loop through player array { if( distance( players[i].origin, self.origin ) >= 200 ) && !self.open ) // Check if player is in range and door is closed atm { triggered = true; // If it is, mark this loop as triggered self moon_door_open(); // Open the door break; // break from this player checking loop, weve already found a target } } } } if ( !triggered && self.open ) // If we didnt find a target - and the door IS already open, close it coz nothing is in range self moon_door_close(); // Close door
id try to start of scripts by making sure they can handle more than one instance, as changing it later to allow "multiples" can be tricky. Start with arrays
Havent tested this, stuffys are prob beter for it, but was bored so wrote up a prototype
* Edit - not sure if show/hiding a clip works, might do tho, as does with anything else - just never tested collision
Last Edit: December 03, 2015, 11:12:26 pm by Harry Bo21
How would I put it to be then? Just < or do I need something else for it?
If the distance is greater than 200 you shouldn't have the equal sign. If its less, you should. That way if an ai/player is 199 OR 200 units from the door then it will open. Otherwise if they are farther away than 200 units it should remain closed.
Your script is a bit exponential, with the checking each zombie for each player bit and won't do anything if all the zombies are dead atm. Also you use level.moving_done which will only allow you to have one door, which may be your intent seeing the way you set up your functions. You may try to modify your script like this or consider rethinking the process if you are going to have more than one.
door_trig = getEnt("door_trig", "targetname"); door_trig setCursorHint("HINT_NOICON"); door_trig setHintstring("Press & hold &&1 to Open Door [Cost: 1000]");
FYI only: My auto doors I make a prefab and setup with structs as targets for each door, and a trigger multiple. (Everything is setup as the target of something else) Then when touching the trigger if it hasn't been bought or unlocked, it shows a hint and doesn't open until you buy it. Then in a while loop I check zombies and players for touching it, and if they are it just keeps continuing. Then when they are not, the while loop ends and closes the doors. I use another struct outside the prefab to set my flags, which I get using an array and then checking for the closest struct in that array to the doors, get it's kvps and set the flag.
Okay, I see your method working, except doors are going in wrong ways now, which is easy fix Was thinking about the new function part, but didnt know how to execute it. Marked as best one. Thanks for helping, guys, learning something new now, lol