Code snippets
From Project X Wiki
Contents
- 1 Simple
- 1.1 Iteration through every object, excluding landscape:
- 1.2 Creating a mine:
- 1.3 Allowing the player to shoot again (inside FireFinal, for example):
- 1.4 Getting a worm's team color:
- 1.5 Retrieving the mouse pos (for example, for airstrike-type weapons):
- 1.6 Checking if place is occupied by landscape at spawning object
- 2 Complicated
Simple
Iteration through every object, excluding landscape:
for(local i = 1; i < Env->Objs.Count; i+=1) { local obj = Env->Objs.Objs[i]; if(obj == NullObj) continue; //do something with obj };
Creating a mine:
CMineParams MParams; CShootDesc SDesc; zero(&MParams); zero(&SDesc); MParams.Prefuse = 0; //time before ability to activate MParams.Flags = 60; //flags of objects to react on MParams.Bias = 0; //Y shift of explosion MParams.Damage = 48; //damage MParams.BlastPower = 100; MParams.Fuse = 0; MParams.Radius = 10; SDesc.Team = 0; SDesc.X = PosX; //position SDesc.Y = PosY; SDesc.SpX = 0; //speed SDesc.SpY = 0; local Mine = new CMine(Root->Store->GetObject(25, 0), &MParams, &SDesc, false, 0);
Allowing the player to shoot again (inside FireFinal, for example):
nAvalShoots = 1; nTotalShoots = 0;
Getting a worm's team color:
GetTeamColor(worm->WormTeam)
Retrieving the mouse pos (for example, for airstrike-type weapons):
override void CWorm::FireFinal(CWeapon* Weap, CShootDesc* Desc) { local x = Desc->AddX; local y = Desc->AddY; //.... }
Checking if place is occupied by landscape at spawning object
override void CWorm::FireFinal(CWeapon* Weap,CShootDesc* Desc) { if (Weap->CheckName("Construct Detector")) { Detector = new CDetector(Root->GetObject(25, 0), -100, -100); local Obje = Env->CheckCollision( Detector, PosX+20*TurnSide, PosY-5); Detector->PosX = PosX+20*TurnSide; Detector->PosY = PosY-5; if(Obje != NullObj){if(Obje->ClType == OC_Landscape){Detector->Free(true);};} } super; }
Complicated
Determining what object is at certain position
For this one, you need to create a collision mask. Utils.pxl has some nice functions for this. Say your script is named "postest":
CColMask* circle; void postest::InitGraphic() { circle = new CColMask(10,10,MakeCircleMask(10)); }
Then, whenever you need to find the object...
local obj = CheckMaskAt(CGObject(Env->Objs.Objs[0]), circle, x, y, -1);