Author Topic: Need some help with this script  (Read 1369 times)

0 Members and 1 Guest are viewing this topic.

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Need some help with this script
« on: August 18, 2007, 02:04:46 pm »
Code: [Select]
process OnCommand(ID:Byte;Text:string):boolean;
var
  PCrd, XCrd, XVar, XOff, YCrd, YVar, YOff, XVel, YVel, HitM, BStl, Owns: Byte;
begin
  if GetPiece(LowerCase(Text), ' ', 0) = '/create' then begin
    Pnum := strtoint(GetPiece(Text, ' ', 1));
    XCrd := strtoint(GetPlayerStat(Pnum,'X'));
    XVar := strtoint(GetPiece(Text, ' ', 2);
    XOff := strtoint(GetPiece(Text, ' ', 3));
    YCrd := strtoint(GetPlayerStat(Pnum,'Y'));
    YVar := strtoint(GetPiece(Text, ' ', 4);
    YOff := strtoint(GetPiece(Text, ' ', 5));
    XVel := strtoint(GetPiece(Text, ' ', 6));
    YVel := strtoint(GetPiece(Text, ' ', 7));
    HitM := strtoint(GetPiece(Text, ' ', 8));
    BStl := strtoint(GetPiece(Text, ' ', 9));
    Owns := strtoint(GetPiece(Text, ' ', 10));
    if GetPlayerStat(Pnum,'Active') then begin
    if GetPlayerStat(Pnum,'Team') < 5 then begin
    if (XVar = '-') then
      XCrd:=XCrd-XOff;
    if (XVar = '+') then
      XCrd:=XCrd+XOff;
    if (YVar = '-') then
      YCrd:=YCrd-YOff;
    if (YVar = '+') then
      YCrd:=YCrd+YOff;
      if (BStl > 0) and (BStl < 16) then begin
      if (GetPlayerStat(Owns,'Active') = true) then begin
      if (GetPlayerStat(Owns,'Team') < 5) then begin
        CreateBullet(XCrd XVar XOff,YCrd YVar,YOff,XVel,YVel,HitM,BStl,Owns)
      end;
      end;
      end;
    end;
    end;
  end;
Result := false;
end;

it's sposed to create a bullet in this format:
/create [Player number] [- or +] [what to add or subtract from x] [- or +] [what to - or + from y] [x vel] [y vel] [hit multiplier] [bullet type] [owner of bullet]
« Last Edit: August 18, 2007, 02:07:21 pm by Kavukamari »
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: Need some help with this script
« Reply #1 on: August 18, 2007, 02:11:36 pm »
CreateBullet uses the variable type single for X,Y,VelX,VelY and HitM; not integer.
Thus you need to change strtoint into strtofloat where needed (and also the type declarations for the variables, of course).

I'd change it into working properly for you right away if I wasn't so tired. Good luck finishing it up.

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: Need some help with this script
« Reply #2 on: August 18, 2007, 02:17:51 pm »
it still doesn't work
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: Need some help with this script
« Reply #3 on: August 18, 2007, 02:33:28 pm »
Riiight... your CreateBullet is also a bit borked. Make sure you read the documentation for CreateBullet. These are the proper arguments you need to use:

CreateBullet(X,Y,VelX,VelY,HitM,sStyle,Owner);

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: Need some help with this script
« Reply #4 on: August 18, 2007, 03:50:48 pm »
but what if the admin wants to offset the bullet?
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: Need some help with this script
« Reply #5 on: August 18, 2007, 03:57:15 pm »
That's not really related to how CreateBullet actually works.

Let's compare the two:

Proper:
CreateBullet(X,Y,VelX,VelY,HitM,sStyle,Owner);
Wrong;
CreateBullet(XCrd XVar XOff,YCrd YVar,YOff,XVel,YVel,HitM,BStl,Owns)

Yours is using 8 arguments whereas it really should be 7, thus causing a compilation error.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Need some help with this script
« Reply #6 on: August 18, 2007, 07:36:12 pm »
Code: [Select]
    XCrd := strtoint(GetPlayerStat(Pnum,'X'));
    YCrd := strtoint(GetPlayerStat(Pnum,'Y'));
The result of those are the datatype single, not a string. I would get rid of "strtoint" there and change the datatypes of XCrd and YCrd to single.

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: Need some help with this script
« Reply #7 on: August 18, 2007, 09:58:39 pm »
Current:
Code: [Select]
process OnCommand(ID:Byte;Text:string):boolean;
var
  Pnum, BStl, Owns: Byte; XCrd, XOff, YCrd, YOff, XVel, YVel, HitM: single; XVar, YVar: string;
begin
  if GetPiece(LowerCase(Text), ' ', 0) = '/create' then begin
    Pnum := strtoint(GetPiece(Text, ' ', 1));
    XCrd := strtofloat(GetPlayerStat(Pnum,'x'));
    XVar := strtofloat(GetPiece(Text, ' ', 2);
    XOff := strtofloat(GetPiece(Text, ' ', 3));
    YCrd := strtofloat(GetPlayerStat(Pnum,'y'));
    YVar := strtofloat(GetPiece(Text, ' ', 4);
    YOff := strtofloat(GetPiece(Text, ' ', 5));
    XVel := strtofloat(GetPiece(Text, ' ', 6));
    YVel := strtofloat(GetPiece(Text, ' ', 7));
    HitM := strtofloat(GetPiece(Text, ' ', 8));
    BStl := strtoint(GetPiece(Text, ' ', 9));
    Owns := strtoint(GetPiece(Text, ' ', 10));
    if GetPlayerStat(Pnum,'Active') then begin
    if GetPlayerStat(Pnum,'Team') < 5 then begin
    if XVar = - then
      XCrd:=XCrd-XOff;
    if XVar = + then
      XCrd:=XCrd+XOff;
    if YVar = - then
      YCrd:=YCrd-YOff;
    if YVar = + then
      YCrd:=YCrd+YOff;
      if (BStl > 0) and (BStl < 16) then begin
      if GetPlayerStat(Owns,'Active') = true then begin
      if GetPlayerStat(Owns,'Team') < 5 then begin
        CreateBullet(XCrd XVar XOff,YCrd YVar YOff,XVel,YVel,HitM,BStl,Owns)
      end;
      end;
      end;
    end;
    end;
  end;
Result := false;
end;

and it still doesn't work
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: Need some help with this script
« Reply #8 on: August 19, 2007, 01:21:27 am »
* Toumaz sighs

Okay, here's the proper way to do it in. To be honest I couldn't get why the hell you'd want to use the XVar and YVar stuff since you could just write a negative number as a command argument to achieve the same effect.

Code: [Select]
function OnCommand(ID: Byte; Text: string): boolean;
var
x,y,xoffset,yoffset,xvel,yvel,hitm: single;
player,style,owner: integer;
begin
  if GetPiece(LowerCase(Text), ' ', 0) = '/create' then begin
try
player:=strtoint(GetPiece(Text, ' ', 1));
   
x:=GetPlayerStat(player,'x');
y:=GetPlayerStat(player,'y');
xoffset:=strtofloat(GetPiece(Text, ' ', 2));
yoffset:=strtofloat(GetPiece(Text, ' ', 3));
xvel:=strtofloat(GetPiece(Text, ' ', 4));
yvel:=strtofloat(GetPiece(Text, ' ', 5));
hitm:=strtofloat(GetPiece(Text, ' ', 6));
style:=strtoint(GetPiece(Text, ' ', 7));
owner:=strtoint(GetPiece(Text, ' ', 8));
except
SayToPlayer(ID,'Invalid parameters.');
end;

if (GetPlayerStat(player,'Active')=false) then exit;
if (GetPlayerStat(player,'Team')=5) then exit;
if (style<0) or (style>16) then exit;
if GetPlayerStat(owner,'Active')=false then exit;
if GetPlayerStat(owner,'Team')=5 then exit;

CreateBullet(x+xoffset,y+yoffset,xvel,yvel,hitm,style,owner);
end;
Result := false;
end;

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: Need some help with this script
« Reply #9 on: August 19, 2007, 03:00:04 pm »
what is 'try' and 'except' ?
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: Need some help with this script
« Reply #10 on: August 19, 2007, 03:02:12 pm »
It's exception handling.

Code: [Select]
try
//Do Something
except
//If we encounter any runtime error, break out and do this.
end;

Basically, if you'd try to do strtoint('not a number') or anything else that would cause an exception the except block would be executed.