* *
Welcome, Guest. Please login or register.
Did you miss your activation email?
August 17, 2017, 05:44:02 AM

Login with username, password and session length

[SOLVED] weapon change issues

  • 12 Replies
  • 790 Views
*

Offline O Ilusionista

  • Global Moderator
  • Hero Member
  • *****
  • 4692
  • >> I WILL BE AWAY FOR SOME TIME <<
    • BMT - Brazil Mugen Team
[SOLVED] weapon change issues
« on: March 15, 2017, 03:46:13 PM »
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: [Select]
void self = getlocalvar("self");
int Map = getentityproperty(self, "map");
   if(Map>2){
performattack(self, openborconstant("ANI_FOLLOW2"));
}

where I change the weapon
Quote
   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: [Select]
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: [Select]
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
« Last Edit: March 19, 2017, 09:34:04 PM by O Ilusionista »

*

Offline Damon Caskey

  • Administrator
  • Hero Member
  • *****
  • 1707
    • DC Current
Re: weapon change issues
« Reply #1 on: March 16, 2017, 10:18:32 AM »
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: [Select]
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
Projects in progress are now available here: https://github.com/DCurrent

*

Offline O Ilusionista

  • Global Moderator
  • Hero Member
  • *****
  • 4692
  • >> I WILL BE AWAY FOR SOME TIME <<
    • BMT - Brazil Mugen Team
Re: weapon change issues
« Reply #2 on: March 16, 2017, 10:23:11 AM »
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?

*

Offline msmalik681

  • Hero Member
  • *****
  • 716
Re: weapon change issues
« Reply #3 on: March 16, 2017, 02:38:57 PM »
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.

*

Offline BeasTie

  • Hero Member
  • *****
  • 2451
Re: weapon change issues
« Reply #4 on: March 16, 2017, 05:59:00 PM »
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: [Select]
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.

Quote
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. 

Quote
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: [Select]
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: [Select]
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

*

Offline O Ilusionista

  • Global Moderator
  • Hero Member
  • *****
  • 4692
  • >> I WILL BE AWAY FOR SOME TIME <<
    • BMT - Brazil Mugen Team
Re: weapon change issues
« Reply #5 on: March 16, 2017, 06:08:20 PM »
Quote
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.

Quote
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)

*

Offline msmalik681

  • Hero Member
  • *****
  • 716
Re: weapon change issues
« Reply #6 on: March 17, 2017, 03:31:54 PM »
The 1st few frames could be empty frames its worth a try.

*

Offline O Ilusionista

  • Global Moderator
  • Hero Member
  • *****
  • 4692
  • >> I WILL BE AWAY FOR SOME TIME <<
    • BMT - Brazil Mugen Team
Re: weapon change issues
« Reply #7 on: March 18, 2017, 02:02:23 PM »
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.

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

Its more or less what I am doing but not luck:
Quote
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.

*

Offline O Ilusionista

  • Global Moderator
  • Hero Member
  • *****
  • 4692
  • >> I WILL BE AWAY FOR SOME TIME <<
    • BMT - Brazil Mugen Team
Re: [SOLVED] weapon change issues
« Reply #8 on: March 19, 2017, 07:12:38 PM »
Tried Beastie's solution, no good.

Code: [Select]
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: [Select]
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.

« Last Edit: March 19, 2017, 10:15:41 PM by O Ilusionista »

*

Offline msmalik681

  • Hero Member
  • *****
  • 716
Re: [SOLVED] weapon change issues
« Reply #9 on: April 02, 2017, 01:52:34 PM »

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: [Select]
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

*

Offline O Ilusionista

  • Global Moderator
  • Hero Member
  • *****
  • 4692
  • >> I WILL BE AWAY FOR SOME TIME <<
    • BMT - Brazil Mugen Team
Re: [SOLVED] weapon change issues
« Reply #10 on: April 02, 2017, 01:56:24 PM »
That is a bug.
Dc pointed me that there is no entityproperty called "weapon". It should be "weaponum"

*

Offline msmalik681

  • Hero Member
  • *****
  • 716
Re: [SOLVED] weapon change issues
« Reply #11 on: April 02, 2017, 02:58:54 PM »
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.

*

Offline O Ilusionista

  • Global Moderator
  • Hero Member
  • *****
  • 4692
  • >> I WILL BE AWAY FOR SOME TIME <<
    • BMT - Brazil Mugen Team
Re: [SOLVED] weapon change issues
« Reply #12 on: April 02, 2017, 03:21:58 PM »
Its weapnum sorry I am on my phone.
See Dc 's reply http://www.chronocrash.com/forum/index.php?topic=3178.msg45934#msg45934

 

Recent

Members
Stats
  • Total Posts: 45372
  • Total Topics: 3113
  • Online Today: 68
  • Online Ever: 316
  • (January 04, 2013, 09:43:02 AM)
Users Online
Users: 3
Guests: 36
Total: 39