Project X Forums



It is currently Thu Mar 28, 2024 8:36 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [0.6.5] Useful Code Snippets
PostPosted: Fri Jun 25, 2010 8:29 am 
Offline
Betatester

Joined: Wed Oct 07, 2009 8:21 pm
Posts: 73
Location: my home
Forbidding the worm to shoot when he's not on his side (fort) :

Code:
procedure InitHooks;
begin
  RegisterHook('Fire', ON_BEGIN_FIRE);
end;

function Fire : boolean;
var
CurW : TWorm;
wpns : integer;
begin
 
  CurW := GetTekWormObj;
  if CurW = nil then exit;
  if CurW.SelWeapon = nil then exit;
  Result := True;
 
 // Team 1 : right side
 // Team 2 : left side
 
   if CurW.Team = 2 then begin
   if ObjInBox(CurW,1154,5,1916,694) then begin // Right side position
    wpns := CurW.SelWeapon.WN;
    case wpns of
    1,2 : // All the weapons we want to forbid
    begin
    Result := False;
    end;
   end;
  end;
 
   if CurW.Team = 1 then begin
   if ObjInBox(CurW,8,14,702,814) then begin // Left side position
    case wpns of
    1,2 :
    begin
    Result := False;
    end;
    end;
    end;
    end;
    end;
    end; // So many ends ...


Automatic placement for towers, rope races..

Code:
procedure Init;
var
i, wCount : Integer;
obj : TWPobj;
begin
wCount := 0;
for i := 1 to GetPObjCount - 1 do begin
  Obj := GetPObj(i);
  if Obj = nil then continue;
  if Obj.ObjType = OBJ_WORM then begin
    Obj.PosX := 831 + 10 * wCount; // X Pos
    Obj.PosY := 351 - (wCount div 6); // Y Pos
    Inc(wCount);
  end;
end;


Adding gravity :

Code:
if (ObjInBox(obj,1115,27,1425,356)) then begin // Position of the gravity
  obj.SpY := obj.SpY + 0.7; //0.7 is the force of the gravity
end;
// Use your brain and you'll understand why I use ObjInBox for gravity


Last edited by Undefined on Sat Jun 26, 2010 8:19 am, edited 5 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: [0.6.5] Useful Code Snippets
PostPosted: Fri Jun 25, 2010 9:00 am 
Offline

Joined: Fri May 28, 2010 1:05 pm
Posts: 11
nice code with good comments, just on thing it would be really nice if you could indent your code so its easier to see where if's start and end, and stuff.


Top
 Profile  
Reply with quote  
 Post subject: Re: [0.6.5] Useful Code Snippets
PostPosted: Fri Jun 25, 2010 9:10 am 
Offline
Site Admin
User avatar

Joined: Mon Aug 17, 2009 12:29 pm
Posts: 91
Stickied.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 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