Project X Forums http://px.worms2d.info/forum/ |
|
Mitosis http://px.worms2d.info/forum/viewtopic.php?f=15&t=342 |
Page 1 of 1 |
Author: | Virtu [ Wed Sep 14, 2011 9:00 pm ] | ||
Post subject: | Mitosis | ||
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: ![]() 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! ![]() If it's of any help, px_errors.txt is attached below.
|
Author: | Entuser [ Thu Sep 15, 2011 8:16 am ] |
Post subject: | Re: Mitosis |
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. |
Author: | Virtu [ Fri Sep 16, 2011 4:11 am ] |
Post subject: | Re: Mitosis |
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? |
Author: | Zed [ Fri Sep 16, 2011 2:50 pm ] |
Post subject: | Re: Mitosis |
http://px.worms2d.info/px080wiki/index.php/CWorm DispHealth field change should help. |
Author: | Twicken [ Mon Aug 06, 2012 11:09 am ] |
Post subject: | Re: Mitosis |
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 |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |