Project X Forums



It is currently Thu Mar 28, 2024 2:48 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Mitosis
PostPosted: Wed Sep 14, 2011 9:00 pm 
Offline
Betatester

Joined: Sun Dec 06, 2009 12:11 am
Posts: 21
Hi again guys, I'm having trouble again >.<
This time I wanted to get started with scripting, and I decided to try to code this weapon after taking a look at other scripts and how they worked (namely CTF's Health code and ResurrectWormEx) and I ended up with a rather small buggy script:

Code:
require utils;
//Spawn New Worm on top of current worm

override void CWorm::FireFinal(CWeapon* Weap,CShootDesc* Desc)
{
         if (Weap->CheckName("Mitosis"))
         {
               local currentworm = GetCurrentWorm();
               if (currentworm != NullObj)
               {
                  local HP = GS->Info.GetWormHealth(WormTeam, WormNumber);
                  if (HP > 1)
                  {
                     GS->Info.SetWormHealth(WormTeam, WormNumber, HP/2 );
                     local mitX = currentworm->PosX ;
                     local mitY = currentworm->PosY-16 ;
                     local mitTeam = currentworm->WormTeam ;
                     local mitIndex = currentworm->WormNumber ;
                     local mitName = "Test" ;
                     local mitHealth = HP/2 ;
                     //New Worm
                     CWormParams wParam;
                     zero(&wParam);
                     wParam.SetName(mitName);
                     wParam.SetPosition(mitHealth, mitX, mitY, true);
                     //Expand Team
                     GS->Info.Teams[mitTeam-1].Worms[mitIndex-1].Health = mitHealth;
                     mitWorm = new CWorm(NullObj, mitTeam, mitIndex, &wParam);
                     GS->Info.Teams[mitTeam-1].Worms[mitIndex-1].Health = mitHealth;
                     
                     if (mitIndex > GS->Info.Teams[mitTeam-1].NWorms)
                     {
                      ExpandNWorms(mitTeam, mitIndex);
                     }
                     return;
                  }
                  ShowMessage("Not enough HP!");
                  return;
               }
               return;         
         }
  super;   
}


My intention was to split the worm's HP in half and spawn a new worm on top of it, with as much HP as the user lost.
The result was this:

Image

Right after selecting the weapon, those animated crates appeared around the worm (which for some reason displayed the red headband like the Kamikaze/Fire Punch/Dragonball one when no custom sprites were assigned). The game froze for a second and crashed after attempting to use it.

I'm a total newbie when it comes to EAX, if someone would kindly point me in the right direction it would be greatly appreciated! :D

If it's of any help, px_errors.txt is attached below.


Attachments:
File comment: PX Errors.
px_errors.zip [6.02 KiB]
Downloaded 440 times
Top
 Profile  
Reply with quote  
 Post subject: Re: Mitosis
PostPosted: Thu Sep 15, 2011 8:16 am 
Offline
PX Developer

Joined: Mon Aug 17, 2009 12:01 pm
Posts: 91
Hi. I recommend you to use RessurectWormEx/GetFreeWormIndex functions for that, two worms can't share the same number. It crashes because you pass NullObj as parent to the CWorm constructor here:
Code:
mitWorm = new CWorm(NullObj, mitTeam, mitIndex, &wParam);


Try something like that :
Code:
require utils;
//Spawn New Worm on top of current worm

override void CWorm::FireFinal(CWeapon* Weap,CShootDesc* Desc)
{
         if (Weap->CheckName("Mitosis"))
         {
               local currentworm = this;
                  local HP = GS->Info.GetWormHealth(WormTeam, WormNumber);
                  if (HP > 1)
                  {
                     GS->Info.SetWormHealth(WormTeam, WormNumber, HP/2 );
                     local mitX = currentworm->PosX ;
                     local mitY = currentworm->PosY-16 ;
                     local mitTeam = currentworm->WormTeam ;
                     local mitIndex = GetFreeWormIndex(mitTeam);
                     local mitName = "Test" ;
                     local mitHealth = HP/2 ;
                     if (mitIndex < 0) return; //no free worms, team has 8 worms already
                     RessurectWormEx(mitIndex, mitTeam, mitX, mitY, mitName, mitHealth);
                     return;
                  } else {
                     ShowMessage("Not enough HP!");
                     return; 
                  } 
         }
  super;   
}


Also, GetCurrentWorm call was useless, you could use "this" , that is the worm that called FireFinal function.


Top
 Profile  
Reply with quote  
 Post subject: Re: Mitosis
PostPosted: Fri Sep 16, 2011 4:11 am 
Offline
Betatester

Joined: Sun Dec 06, 2009 12:11 am
Posts: 21
Thank you very much Entuser! :)
The only issue I'm having now is that even though the worm HP gets halved (since, if used two times in a row, it will create a worm with 1/4 of the original HP) the label on top of it will show the health unaltered. Is there any way around this?


Top
 Profile  
Reply with quote  
 Post subject: Re: Mitosis
PostPosted: Fri Sep 16, 2011 2:50 pm 
Offline
Betatester

Joined: Fri Oct 16, 2009 3:26 pm
Posts: 155
http://px.worms2d.info/px080wiki/index.php/CWorm

DispHealth field change should help.

_________________
Skype - verygooder1
ICQ - 420622934
Steam - http://steamcommunity.com/id/jarent/

use steam coz im too lazy to log into icq and skype


Top
 Profile  
Reply with quote  
 Post subject: Re: Mitosis
PostPosted: Mon Aug 06, 2012 11:09 am 
Offline
User avatar

Joined: Tue Oct 04, 2011 2:44 pm
Posts: 294
oh thats funny! thats one of the first px weapons i thought of too! like a real life worm, multiplying! never saw this topic until now

_________________
“If you can't explain it simply, you don't understand it well enough” - Albert Einstein.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 34 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Skin by Lucas Kane