[SOLVED] weapon change issues

O Ilusionista

Captain 100K
Guys, I need a help here.
I have a player with two weapons (so it has 3 modes). On a specific level, I set the weapon to 1 and it works.
But if the player is using a map > 2 (3, 4  or 5), I need him to change to weapon 2.

This is working for now, since I force the player to go to a different state,

Code:
void self = getlocalvar("self");
int Map = getentityproperty(self, "map");
   if(Map>2){
performattack(self, openborconstant("ANI_FOLLOW2"));
}

where I change the weapon
weaponframe 0 2

But everything starts to fail once the player dies. On her respawn, the player returns with the first weapon, not the second.
If I put that code on the respawn, it gets ignored (I noticed that you can't change to a different animation while you are in RESPAWN anim, but you can do it while in SPAWN anim).

Even if I try to change the weapon by script, it gets ignored:

Code:
void self = getlocalvar("self");
int Map = getentityproperty(self, "map");
if(Map>2){
changeentityproperty(self, "weapon", 2);
}

Should I use a spawnscript? Or even modelcopyscript?
Edit:
- spawnscript gets ignored
- onmodelcopy crashes the engine
- ondrawscript works, but the entity keeps changing from one weapon to another. If I try to check which weapon I am using, the engine closes saying "Script function 'getentityproperty' returned an exception, check the manual for details."

Code:
ondrawscript @script
void main()
{
void self = getlocalvar("self");
int Map = getentityproperty(self, "map");
int Weap = getentityproperty(self, "weapon");
    if(Map>2 && Weap==1){
    changeentityproperty(self, "weapon", 2);
}
}@end_script
 
Switching models on drawframe is just going to make a mess, throw that idea out right now and thank me later.  :P

As far as it being ignored, generally when I find that happening my first action is to verify the function is running at all.

This is when the log method wants to be your friend. Put a log method into your function, load the OpenBOR log into a web browser and refresh it as you test play. You should see your message in the log. If not, the function isn't running at all and we can begin to debug why or find a workaround.

Code:
log("Running \n");

When you get used to the log method, then you can also start using it to output useful debug info instead of just static messages.

DC
 
Thanks DC, I will make a try. Most of times, I use a on-game debug, setting a global var I have for that.
What I don't understand is why the "int Weap = getentityproperty(self, "weapon");" makes the engine to close. Any clues?
 
I had a issue changing enemy weapons on spawn only way I could fix was for them to switch once they reach their idle animation.


Or try activating your script after the 4th frame of spawn you can set delay to 1 so it reaches that frame quickly.
 
Weapon models actually use RESPAWN anim when they appear instead of SPAWN.  I had a problem with my mod because switching weapons would cause the respawn animation to play every time.  You can just remove respawn anim, but I really needed to have this animation when the char respawned.

The work around was having a script named respawn1.c (respawn2.c etc for multiplayer) that switches animation.  just rename RESPAWN anim to FOLLOW# anim and call this anim in the respawn1.c

RESPAWN1.C
Code:
void main(){
	int player = getlocalvar("player");
	void self = getplayerproperty(player, "ent");
	{
	changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW1"), 1);
	}
}

Put other code you need to run here instead of spawn anim, you could also try making a ONSPAWN script for each char/model.

What I don't understand is why the "int Weap = getentityproperty(self, "weapon");" makes the engine to close. Any clues?
@ O ilusionista

There's a few bugs with weapons in openbor, setweap has issues now with weapon #1 -  try not using weapon number 1, just use 2 and onwards.  Make the first entry a 'dummy' or copy of the default.  Sorry I can't remember that clearly at the moment, I found a lot of weird behaviour with weapons while working on my mods, but it was a while ago now and I can't really remember all the details. 

It looks like the engine is skipping/ignoring the first weapon.  Trying to use weapnum 1 in an item will not work, engine will crash and say char does not have this weapon.

So you have a player with weapons set like this

Code:
weapons knife gun player

it won't work properly, you can't use the first entry, if you use weapnum 1 it crashes, if you use weapnum 2 for the gun there's no effect (player will pick up item but doesn't change models)

to make it switch to knife you must do this

Code:
weapons knife knife gun player

but 'weapnum 1' will still not work, but you can use weapnum 2 and up instead.
http://www.chronocrash.com/forum/index.php?topic=1504.msg17941#msg17941
 
Weapon models actually use RESPAWN anim when they appear instead of SPAWN.
In my tests, they use RESPAWN anim when you respawn and SPAWN when you spawn. What they ignore is SPAWSCRIPT, in favor of ONMODELCOPYSCRIPT.

But in my case, the issue is - When executing a respawn animation, the engine doesn't let you change the animation (at least, not on the first seconds) as you can do in SPAWN animation.

Thanks for the ideas, I will take a look.

Or try activating your script after the 4th frame of spawn you can set delay to 1 so it reaches that frame quickly.
Maybe, but this could break the effect (since it would show someone flying which should not fly)
 
I had some progress:
Using DC's tip, I noticed that ONSPAWNSCRIPT runs only the chracter respawn after you lose all the lifes (IOW uses a continue).
But if you die and respawn, the engine doesn't read it - and I can confirm by reading the log.

msmalik681 said:
The 1st few frames could be empty frames its worth a try.

Its more or less what I am doing but not luck:
anim respawn
loop 1 2 7
offset 4 4
bbox 46 78 35 37
delay 30
@script
    void self = getlocalvar("self");
    if (frame==0)
    {
    changeentityproperty(self, "position", -200,150, 0);
    }
    int x = getentityproperty(self, "x");
    int Map = getentityproperty(self, "map");

    if(Map>2){
    changeentityproperty(self, "weapon", 1);
    performattack(self, openborconstant("ANI_FOLLOW2")); //Attack!
    }
    if(x>=100)
    {
      performattack(getlocalvar("self"), openborconstant("ANI_FOLLOW61"));
    }
@end_script
@cmd subjectScreen 0
@cmd checkPal3 "ANI_FOLLOW2" 2
frame data/sprites/0empty.gif
delay 6
@cmd velo001 2.75 0 0
sound data/chars/nave/vic.wav
frame data/sprites/0empty.gif
frame data/sprites/0empty.gif
frame data/sprites/0empty.gif
frame data/sprites/0empty.gif
frame data/sprites/0empty.gif
frame data/sprites/0empty.gif

I will try Beasti's solution.
 
Tried Beastie's solution, no good.

Code:
void main(){
	void self = getlocalvar("self");
	int Map = getentityproperty(self, "map");
	if(Map>2){
	log("RespawnWeapon \n");
	changeentityproperty(self, "weapon", 2);
	}
}
The log doesn't shows anything, so the code is ignored. even if I move the code to a onmodelcopyscript.
Something is really wrong with Weapons on OpenBOR.

EDIT: I managed to make it to work, using ondrawscript + globalvar

Code:
ondrawscript @script
void main()
{
void self = getlocalvar("self");
int Map = getentityproperty(self, "map");
int SWNaveControl = getglobalvar("SWNaveControl");
    if(Map>2 && Map <6 && SWNaveControl==NULL()){
    setglobalvar("SWNaveControl", 1);
    log("SWNaveControl \n");
    changeentityproperty(self, "weapon", 2);

}
}@end_script

It checks it the palette is 3, 4 or 5 (because 6 is the hit one) and the global, set a globalvar (if is not set) and change the weapon.

 
I have this script wcheck that changes the weapon based on current model name if I move it to frame 1-2 it wont work only frame 3 or above will work.

Code:
anim spawn
	 loop       0
	 delay      2
	 offset     19 117
	frame	    data/chars/0gamefx/empty.png
	frame	    data/chars/0gamefx/empty.png
	@cmd	wcheck 
	frame	    data/chars/0gamefx/empty.png
 
O Ilusionista said:
That is a bug.
Dc pointed me that there is no entityproperty called "weapon". It should be "weaponum"

"weaponum" command did not work for me and I could not find it in the source code either but I found "weapnum" but that did not work also so I am sticking with "weapon" for now.

This is a bug that should be fixed as it would so much more efficient to have this code running as a onspawn script.
 
Back
Top Bottom