Solved Outside of Screen View code

Question that is answered or resolved.

PS_VITA

Active member
Does anyone know what are the words used to be able to create an outside of screen view script? I know of the offscreen (kill) in the settings of the entity.txt but I was wondering what looks like on script.
 
Last edited:
Solution
Hi, thanks for asking. I'm trying to create a script that can detect if an entity is outside of the view where the players are currently playing for example.

I'm searching in the forum and the manual (but no luck). I've used to program with game maker and the code language was called viewport , you could make scripts like if enemy is outside of viewport destroy enemy or whatever really.

Oh! That's easy. You just need the current scroll position and screen size. Scroll position is the left edge. Add the horizontal screen size to that and you get the right edge. All you need to do from there is compare them to an entity's X position. This assumes you don't have any scripted camera offset positions in play.

C:
int...
@PS_VITA

do you mean something like the cop car you summon on streets of rage or the elevated camera intro of aztec level in NSlashers?
Hi, thanks for asking. I'm trying to create a script that can detect if an entity is outside of the view where the players are currently playing for example.

I'm searching in the forum and the manual (but no luck). I've used to program with game maker and the code language was called viewport , you could make scripts like if enemy is outside of viewport destroy enemy or whatever really.
 
Hi, thanks for asking. I'm trying to create a script that can detect if an entity is outside of the view where the players are currently playing for example.

I'm searching in the forum and the manual (but no luck). I've used to program with game maker and the code language was called viewport , you could make scripts like if enemy is outside of viewport destroy enemy or whatever really.

Oh! That's easy. You just need the current scroll position and screen size. Scroll position is the left edge. Add the horizontal screen size to that and you get the right edge. All you need to do from there is compare them to an entity's X position. This assumes you don't have any scripted camera offset positions in play.

C:
int screen_size_x = 0;
int scroll_x = 0;
int edge_right = 0;

screen_size_x = openborvariant("hresolution");
scroll_x = openborvariant("xpos");

edge_right = scroll_x + screen_size_x;

HTH,
DC
 
Solution
Oh! That's easy. You just need the current scroll position and screen size. Scroll position is the left edge. Add the horizontal screen size to that and you get the right edge. All you need to do from there is compare them to an entity's X position. This assumes you don't have any scripted camera offset positions in play.

C:
int screen_size_x = 0;
int scroll_x = 0;
int edge_right = 0;

screen_size_x = openborvariant("hresolution");
scroll_x = openborvariant("xpos");

edge_right = scroll_x + screen_size_x;

HTH,
DC
Hi,

Thanks, this is great.
 
@PS_VITA,

I forgot to mention that depending on the situation you may not have to use script at all. The engine automatically kills entities that reach a certain distance offscreen. You can adjust this with offscreenkill {value} model setting.

DC
 
@PS_VITA,

I forgot to mention that depending on the situation you may not have to use script at all. The engine automatically kills entities that reach a certain distance offscreen. You can adjust this with offscreenkill {value} model setting.

DC
Yes thanks, it's the reason why I made this topic is to find out how offscreenkill works. (I actually mentioned it in the very first post) I'm not particularly using this to kill any entities atm, but it's very usefull for NPCs that tend to hang out a bit to much offscreen and other useful things.
 
Yes thanks, it's the reason why I made this topic is to find out how offscreenkill works. (I actually mentioned it in the very first post) I'm not particularly using this to kill any entities atm, but it's very usefull for NPCs that tend to hang out a bit to much offscreen and other useful things.
On that front - what is your solution @PS_VITA - to entiities that are supposed to wander, but you want them to be "scared" of want them to avoid staying off screen too much -
basically how would you make them wanderers, but only within the confines fo the screen ?
 
On that front - what is your solution @PS_VITA - to entiities that are supposed to wander, but you want them to be "scared" of want them to avoid staying off screen too much -
basically how would you make them wanderers, but only within the confines fo the screen ?

I'm using several scripts including some pieces of the code that DC provided in this very topic. And I mainly have noticed the A.i wondering to much offscreen when I have enabled NPCs that help me. So one of the best solutions for me was to use a changeproperty "hostile" to TYPE_PLAYER only script on the anim rise of the enemy mixed with randomized script of a 40% chance to an anim follow that mimics anim rise with change property "hostile" to NPC Only.( You can of course make hostile towards both player and NPC in another anim of your choice to add more unpredictable a.i results.)

Enemies and NPC used to fight offscreen alot, but I noticed now the fight stays within the view of the screen.

It's probably not the best way of doing this,but I'm learning and hopefully one day I can improve it thanks in part to @DCurrent help and Co.
 
Last edited:
@PS_VITA - Ok if you have any chance too look into how to make "Wander" enemies scared of the edges let me know,
i did suspect that its a script to change the AI based on position, but such a solution means editing every single "wanderer' on my module....
 
@PS_VITA - Ok if you have any chance too look into how to make "Wander" enemies scared of the edges let me know,
i did suspect that its a script to change the AI based on position, but such a solution means editing every single "wanderer' on my module....
@oldyz I always used custom chase scripts and I believe that's the reason I never got wanders to actually work and as for editing every wanderers I know it can be alot of work. There's is an option you can toggle to change all entities that go offscreen but it didn't work for me but I wonder if you ever tried it. unfortunately, I can't remember what it was called but I will search and try to get back to you.


edit:it's

offscreen_noatk_factor {bi}

  • This command determines the ability of an entity to be able to attack while off screen. Useful to prevent entities that use ranged attacks like shots for example, they can attack without being in the visible area.
    • 0 Means that the entity can attack outside the visible area (default)
    • 1 Means that the entity CAN NOT attack outside the visible area.


several members are discussing this down here...

 
Last edited:
@PS_VITA
no, that toggle would not work, I like the entities to launch attacks offscreen, if you use that toggle it means that an entity would not try and punch you or do antything if its beyond the visible border - in this case i would like the wanderers to be offscreen enough to be realsitic -

meaning , they can be offscreen, but not too far or not too long - one way is to add this code as a #include on their think script and this code to only work on offscreen coordinates say about 50 pixles off & you are right , it has to change to chase or normal, and change back to wander a at about 80 pixels in visible space -
why the think script? and not animation script? - bacause think seem to be more realistic and less predictable than anim script & if im not mistaken wanderers stop to "think" more often -
and edit has to be made to every entity ( in my module every enemy is a potentiel wanderer) tho - but at least is only one line of code
 
@PS_VITA
no, that toggle would not work, I like the entities to launch attacks offscreen, if you use that toggle it means that an entity would not try and punch you or do antything if its beyond the visible border - in this case i would like the wanderers to be offscreen enough to be realsitic -
You are absolutely right, and actually I think offscreen_noatk_factor effects all entities....

Post in thread 'Limit attack subjet to screen' Solved - Limit attack subjet to screen

I don't know if this post could help you without having custom follow scripts but it might be worth a read. otherwise I would post a new topic with your specific question as I'm sure someone could chime in and help you further.
 
On that front - what is your solution @PS_VITA - to entiities that are supposed to wander, but you want them to be "scared" of want them to avoid staying off screen too much -
basically how would you make them wanderers, but only within the confines fo the screen ?


Hey @oldyz ,

I remember you asking this a while ago and I found out that creating hidden actual walls at certain points of the stage works really well .

All you have to do is change the values of them to enable and disable them.

check this post for more info:

 
@PS_VITA

i am afraid that using walls would force and limit the other types of entities and make them more vulnerable to projectile attack or other spams from players

i think that a boundary check and ai move check script would work well, problem is most of my script knowledge is evaporating fast thansk to my current situation.

anyway, this would would have to be some kind of script that is integrated in all enemy entities, something like
"if entity is -12 pixes out of view or + 12 pixels out of view, and the ai move type is avoid, then change ai move type to normal or chase for 4 seconds and then back to avoid"

next issue is figure out where to implement it , - Onthink?
 
Back
Top Bottom