• All, Gmail is currently rejecting messages from my host. I have a ticket in process, but it may take some time to resolve. Until further notice, do NOT use Gmail for your accounts. You will be unable to receive confirmations and two factor messages to login.
Check For Entity and Change Animation

[SCRIPT] Check if there is an specific entity and change animation

O Ilusionista

Captain 80K
This tutorial provides an example of switching animations if a specific entity is on screen.
 
Last edited by a moderator:
@O Ilusionista,

I've moved the tutorial to the resources area and associated this as a discussion thread. As I mentioned before, I want all new tutorials going there. Also, because it is a very, very serious optimization issue, I updated the sample code to use upstream constants.

I'd recommend (but didn't do because I'm not trying to step on your toes too much) mentioning the underlying principal is an enumeration, and there's an existing tutorial for that.

DC
 
Oh, I also added a link to this tutorial in the enumeration tutorial:

1701096953155.png
 
Also, because it is a very, very serious optimization issue, I updated the sample code to use upstream constants.
Thanks I am aware of the upstream constants (I haven't updated my codes to reflect it yet). But how serious is this?
Nevermind, I found it Tutorial - Optimizing Scripts

Also, I always uses animation variables as "void" but you changed for "int". Is there any specific reason for this?

Thanks
 
Last edited:
But how serious is this?

Not enough that I'd stop everything I was doing and retrofit a whole game, but bad enough it shouldn't ever be done in a new project or posted as a technique.

Also, I always uses animation variables as "void" but you changed for "int". Is there any specific reason for this?

Technically, it doesn't matter. OpenBOR is weak typed, meaning it's just going to determine the type itself and ignore you. However, it's good coding practice (for a lot of reasons) to define the type as intended. Animation IDs are integers, thus the int type. For strings, I recommend char.

DC
 
void ent = getentity(i);
if ( getentityproperty(ent, "exists")

Can someone please explain the differences between the two codes below?

Code:
void player = getplayerproperty(i, "entity");

1. if(getentityproperty(player, "exists")) {

vs

2. if(player != NULL()){

Thank you so much
 
Can someone please explain the differences between the two codes below?
@DCurrent could explain it better but as far as I know, both check for a player but using different methods: one check if it exists, the other checks it the player isn't NULL().
If I am not mistaken, something that don't exist is different than somenthing NULL().
 
@DCurrent could explain it better but as far as I know, both check for a player but using different methods: one check if it exists, the other checks it the player isn't NULL().
If I am not mistaken, something that don't exist is different than somenthing NULL().
Thanks alot.
What I really liked to find out if there are situations where one works better than the other or they work exactly the same.
So far I haven't had any problems with either the two.
 
NULL is not specfic to OpenBOR. It's coding parlance for a variable that is undefined. If you try to reference something that is NULL, you're going to get a NULL pointer error (instant shutdown by the OS), or worse, what all coding languages call an "undefined behavior". Depending on the hardware you might discover secret nudes of Anna Kendrick... or accidentally divide by 0 and break the space time continuum. Who knows?

For obvious reasons, code is usually written so that variables are always defined. In the case where it's unavoidable to have a possible NULL reference, you always check for a NULL first.

getentityproperty(player, "exists") is specific to OpenBOR. It has to do with OpenBOR having a lot of asynchronous actions going on. It's possible that one loop might remove an entity before another loop completes that still has a reference to that entity in it. Without some flag to let the second loop know, you'd be referencing something that does not exist. That's called a segmentation fault (similar to the NULL reference), and will produce similarly undefined behavior. So, OpenBOR has some internal code to deal with that. That's what the "exists" does.

HTH,
DC
 
NULL is not specfic to OpenBOR. It's coding parlance for a variable that is undefined. If you try to reference something that is NULL, you're going to get a NULL pointer error (instant shutdown by the OS), or worse, what all coding languages call an "undefined behavior". Depending on the hardware you might discover secret nudes of Anna Kendrick... or accidentally divide by 0 and break the space time continuum. Who knows?

For obvious reasons, code is usually written so that variables are always defined. In the case where it's unavoidable to have a possible NULL reference, you always check for a NULL first.

getentityproperty(player, "exists") is specific to OpenBOR. It has to do with OpenBOR having a lot of asynchronous actions going on. It's possible that one loop might remove an entity before another loop completes that still has a reference to that entity in it. Without some flag to let the second loop know, you'd be referencing something that does not exist. That's called a segmentation fault (similar to the NULL reference), and will produce similarly undefined behavior. So, OpenBOR has some internal code to deal with that. That's what the "exists" does.

HTH,
DC
I am getting this error and I think it has to do with NULL?

Code:
Assertion `list->solidlist != NULL' failed in function 'ImportNode_Init' at source/scriptlib/ImportCache.c:136.
This is an OpenBOR bug.  Please report this at www.chronocrash.com.

It doesn't let me know anything else beside this.
Thank you
 
I am getting this error and I think it has to do with NULL?

Code:
Assertion `list->solidlist != NULL' failed in function 'ImportNode_Init' at source/scriptlib/ImportCache.c:136.
This is an OpenBOR bug.  Please report this at www.chronocrash.com.

It doesn't let me know anything else beside this.
Thank you


Most likely you have too many freespecials & cancels. You need to increase maxfreespecials.

DC
 
Most likely you have too many freespecials & cancels. You need to increase maxfreespecials.

DC
I found the issue. I was trying to setup the didhitscript and I had
#import "data/scripts/MainScript.c" instead of #include "data/scripts/MainScript.c"

I copied it from another game and I had no clue the difference between
#import vs #include

I changed it to #include and it is working now,

thank you
 
I found the issue. I was trying to setup the didhitscript and I had
#import "data/scripts/MainScript.c" instead of #include "data/scripts/MainScript.c"

I copied it from another game and I had no clue the difference between
#import vs #include

I changed it to #include and it is working now,

thank you

Ahh, glad to know you found it!

DC
 
A quick question please.
Is it possible for this code to work with enemy or npc entities? It works flawlessly on "type player" entities, but it is ignored on any other entity I am trying to use this code.

Edit: Apologies, it took me a while but I made it work for the exact reason I needed on very specific situations. 😁
 
Last edited:
Back
Top Bottom