Author Topic: need scripting help  (Read 2508 times)

0 Members and 1 Guest are viewing this topic.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
need scripting help
« on: April 02, 2010, 04:14:28 am »
i need some help with a basic script

how do i spawn a full circle of bullets around a player, if i give x and y values i get compile errors, but if i give x values only or y values only it works, say if x relative to player pos was 0 and y was say 50, that would work, if x was 1 and y was 0, that would work

but if x is 20 and y is 20 that returns an error

i need an example of a working script that does this, thanks

From: April 01, 2010, 08:56:11 pm
how do i write to ini files and update ini values
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline croat1gamer

  • Veteran
  • *****
  • Posts: 1327
  • OMG CHANGING AVATAR!!! ^ω^
Re: need scripting help
« Reply #1 on: April 02, 2010, 04:25:16 am »
Last year, I dreamt I was pissing at a restroom, but I missed the urinal and my penis exploded.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: need scripting help
« Reply #2 on: April 02, 2010, 05:09:06 am »
perfect that what i needed :) tx, solved

now for ini...
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline freestyler

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 326
Re: need scripting help
« Reply #3 on: April 02, 2010, 05:41:33 am »
You can use WriteINI script made by rhide and NTxC - the original post is here, and here is the fully working version I use.

Syntax:
Code: [Select]
WriteINI ( 'file directory' , 'section' , 'key' , 'value' );

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: need scripting help
« Reply #4 on: April 03, 2010, 07:18:08 pm »
ok i have another problem, some if statements seem to be getting skipped

heres the section of code:
Code: (pascal) [Select]
if Text = '/buy bes' then begin
if Cash < 65 then begin
WriteConsole(0,IdtoName(ID)+' just tried to purchase berserker, not enough funds!',$EE81FAA1);
end;
if Cash <= 65 then begin
Cash :=Cash-65;
end;
WriteConsole(0,IdtoName(ID)+' has just bought berserker for 65 Cash',$EE81FAA1);
GiveBonus(ID, 2);
end;

the problem:
-If Statements are being launched regardless of the conditions, if Cash is lower than 65 as the code is stating then it should ONLY write to console that theres not enough funds, as the code to buy the item are between a different if and end, which leads me to believe that the if statements are wrong and so they are getting skipped when the event occurs, however if that is the case the script shouldn't compile and yet it does, when /buy pred is used, both if statements are being triggered if Cash is less than 65, but if above 65 only the buying part is triggered, why are both parts being triggered when Cash is less than 65 when it should only be the writeconsole? Or have i made another rookie mistake?

From: April 03, 2010, 07:31:13 pm
nvm fixed it but
Code: (pascal) [Select]
if Text = '/buy bes' then begin
if Cash < 65 then begin
WriteConsole(0,IdtoName(ID)+' just tried to purchase berserker, not enough funds!',$EE81FAA1);
end;
if Cash > 65 then begin
Cash :=Cash-65;
WriteConsole(0,IdtoName(ID)+' has just bought berserker for 65 Cash',$EE81FAA1);
GiveBonus(ID, 2);
end;
end;

how do i now make it so that if it equals OR more than 65 then it does it

if i use >= that returns a compile error

=> also returns an error

can i use an OR statement and how would i put that in??
« Last Edit: April 03, 2010, 07:32:57 pm by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: need scripting help
« Reply #5 on: April 03, 2010, 07:37:26 pm »
if i use >= that returns a compile error

are you sure?
Come join: EliteCTF
Listen to: My Music

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: need scripting help
« Reply #6 on: April 03, 2010, 08:17:00 pm »
hmm, nvm

is there a way to change how many cluster grenades a player can hold?

From: April 03, 2010, 09:29:48 pm
i need help
Code: (pascal) [Select]
//function OnCommand(ID: Byte; Text: string): boolean;
//begin
//if GetPiece(Text,' ',0) = '/raisecash' then begin
//Cash := Cash + GetPiece(Text,' ',0);
//WriteConsole(0,'Admin has just deposited '+Inttostr(Getpiece(Text,' ',1))' //Cash!',$EE81FAA1);
//end;

this section of code is currently commented out because it seems to cause a type mismatch error somewhere else in the script, if i uncomment this section and try to compile i get the error, but once i comment it out it compiles, so part of this code must be wrong, but i cant see what the error is (my rookie eyes?)

thanks in advance

From: April 03, 2010, 10:52:11 pm
nvm that error is fixed but now im getting comma expected when this code is uncommented, again its not pointing at this section of code but once this section is commented, the error no longer exists
Code: (pascal) [Select]
//function OnCommand(ID: Byte; Text: string): boolean;
//begin
//if GetPiece(text,' ',0) = '/raisecash' then begin
//Cash := Cash + Strtoint(GetPiece(Text,' ',0));
//WriteConsole(0,'Admin has just deposited '+Inttostr(Getpiece(Text,' ',1))
//Cash!',$EE81FAA1);
//end;

From: April 03, 2010, 11:23:38 pm
nevermind, figured it out, it was getting confused with the converted value in writeconsole, soon as i got rid of inttostr and added a + to it, it compiled and now works perfect

new code:
Code: (pascal) [Select]
function OnCommand(ID: Byte; Text: string): boolean;
begin
if GetPiece(text,' ',0) = '/raisecash' then begin
Cash := Cash + Strtoint(GetPiece(Text,' ',1));
WriteConsole(0,'Admin has just deposited '+Getpiece(Text,' ',1)+' Global Player Cash!',$EE81FAA1);
end;
end;

also removed another conversion and added an end
« Last Edit: April 03, 2010, 11:23:38 pm by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline ShadowDancer

  • Major(1)
  • Posts: 22
Re: need scripting help
« Reply #7 on: April 04, 2010, 05:00:03 am »
Tip: When server returns error you can go to logs dir and fing console log. There you will find line where is bug(ctrl + g in notepad).
Sorry, I'm not native English speaker...

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: need scripting help
« Reply #8 on: April 04, 2010, 09:23:43 pm »
ok whats the best way to get to the most recent log i have like 100000 logs to go through (enesce server host)
« Last Edit: April 04, 2010, 11:53:57 pm by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: need scripting help
« Reply #9 on: April 05, 2010, 02:45:18 am »
ok whats the best way to get to the most recent log i have like 100000 logs to go through (enesce server host)
sort by date modified

Also, use a local server to test your scripts...

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: need scripting help
« Reply #10 on: April 05, 2010, 05:37:12 am »
What I do is setting in server.ini OldLogFilesFormat=1. Then it's just "consolelog-#.txt".
And if you've got so damn much logs just remove them  ;D

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: need scripting help
« Reply #11 on: April 10, 2010, 02:51:39 am »
ok how do i do this..

i am trying to add a bugs/feedback/suggestions script so ppl can leave the respective comments and whatnot

but the file isnt being written, this is just a test:
Code: (pascal) [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin
   if Containsstring(Text,'/bug') then begin
      WriteConsole(0,'bug filing acknowledged',$EE81FAA1);
      WriteFile('scripts/BugReport/Bugs/test.txt','Hello World!');
   end;
end;

am trying to make it so that when player text contains /bug it creates and writes the respective file within the Bugs folder located in the root of my script

if statement is being triggered and writeconsole is showing

why is the file not being created? and what would be the best way to separate the comment from the command?

Bugs folder does exist btw

syntax will be: /bug <message>

thanks guys


@Swompie, how do i remove all of them without having to remove them one at a time or removing the entire folder?
« Last Edit: April 10, 2010, 02:54:01 am by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: need scripting help
« Reply #12 on: April 10, 2010, 03:05:01 am »
Go into the log folder, press ctrl-A, then dismark the kills folder and the gamestat.txt through holding ctrl and clicking on them. Then simple DELETE it?



Do you have permissions to write files in your folder?

Btw. that's way better: (:D)
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
var Temp: string;
begin
  Result := false;
  if LowerCase(Copy(Text, 1, 5)) = '/bug ' then begin // Using Containstring here is a bad idea..
    Temp := Copy(Text, 6, length(Text)); // Then I copy anything after the first space into a var
    if Temp <> '' then begin // Check if it containts sth.
      WriteLnFile('scripts/' + ScriptName + '/Bugs/Test.txt', Temp);
      WriteConsole(ID, 'Your bug has been reported - thanks for help!', $00FF00); // Message that it was successful
    end else WriteConsole(ID, 'NOOB!', $FF0000); // error messagez
  end;
end;
What do you mean with seperating the comment from the cmd?

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: need scripting help
« Reply #13 on: April 10, 2010, 03:15:27 am »
thats the problem its not done from my computer, its done from enesce file hosting so every file is a link unless i find out the ftp details and do it with an ftp client

i have no idea if i have write permissions, as its not done through my computer, but i can edit any file, if that counts
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: need scripting help
« Reply #14 on: April 10, 2010, 03:25:50 am »
Try WriteLnFile('doesthiswork.txt', 'hi!'); on ActivateServer and see if it works.
You access the server via FTP or through a application which uploads things for you from enesce?

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: need scripting help
« Reply #15 on: April 10, 2010, 03:38:20 am »
what i meant was: so i dont end up writing /bug to the file also

thanks for the code,  now i know what to work off

From: April 10, 2010, 05:07:33 am
normally i use the browser to access it via a website which i log into and i then have access to a file manager
« Last Edit: April 10, 2010, 05:07:33 am by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: need scripting help
« Reply #16 on: April 10, 2010, 08:02:08 am »
Yea, use Copy() when you want specific parts of a text, mostly the best solution.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: need scripting help
« Reply #17 on: April 10, 2010, 07:39:05 pm »
btw swompie, whats the syantax for copy?

i know its Copy(source,numfromstart?,numendchar?)

Code: (pascal) [Select]
  if LowerCase(Copy(Text, 1, 9)) = '/suggest ' then begin // Using Containstring here is a bad idea..
    Temp := Copy(Text, 6, length(Text)); // Then I copy anything after the first space into a var
    if Temp <> '' then begin // Check if it containts sth.
      WriteLnFile('scripts/' + ScriptName + '/Suggestions/'+IDtoname(ID)+'.txt', Temp);
      WriteConsole(ID, 'Your suggestion has been filed - thanks for your help!', $00FF00); // Message that it was successful
    end else WriteConsole(ID, 'NOOB!', $FF0000); // error messagez
  end;
writes 'est' to every line just before the player message which means its getting triggered on /sugg and not /suggest

Code: (pascal) [Select]
  if LowerCase(Copy(Text, 1, 10)) = '/feedback ' then begin // Using Containstring here is a bad idea..
    Temp := Copy(Text, 6, length(Text)); // Then I copy anything after the first space into a var
    if Temp <> '' then begin // Check if it containts sth.
      WriteLnFile('scripts/' + ScriptName + '/Feedback/'+IDtoname(ID)+'.txt', Temp);
      WriteConsole(ID, 'Your Feedback has been filed - thanks!', $00FF00); // Message that it was successful
    end else WriteConsole(ID, 'NOOB!', $FF0000); // error messagez
  end;
writes 'back' to the start of every line just before the player message which means its being triggered on /feed and not /feedback

which brings me to the belief that my Copy is written wrong on these sections of code, working off your section for /bug

thanks swompie

its working ok i just want it to stop writing est and back to the start of the lines in each respective file is all, makes the suggestions/feedback easier to read
« Last Edit: April 10, 2010, 07:40:54 pm by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: need scripting help
« Reply #18 on: April 11, 2010, 02:33:13 am »
Code: [Select]
Copy(Source: string; StartPos, Count: byte): string;The StopPos is StartPos + Count.
When Starting pos is 5 it would start at the 5th char in the Source, Count tells how many chars to copy from the StartPos.
Example:
Code: [Select]
var test: string;
begin
  test := '12345678';

  WriteLn(Copy(Test, 1, 8)); // Will output "12345678"
  WriteLn(Copy(Test, 5, 2)); // Will output "567"

end;
I think you'll get it.

Offline SpiltCoffee

  • Veteran
  • *****
  • Posts: 1579
  • Spilt, not Split!
    • SpiltCoffee's Site
Re: need scripting help
« Reply #19 on: April 11, 2010, 02:40:11 am »
Actually, Swompie, the output of the second Copy will be 56, not 567. :D
When life hands you High Fructose Corn Syrup, Citric Acid, Ascorbic Acid, Maltodextrin, Sodium Acid Pyrophosphate,
Magnesium Oxide, Calcium Fumarate, Yellow 5, Tocopherol and Less Than 2% Natural Flavour... make Lemonade!

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: need scripting help
« Reply #20 on: April 11, 2010, 03:50:02 am »
Oh, yea your right  ::)

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: need scripting help
« Reply #21 on: April 11, 2010, 01:01:23 pm »
tx Swompie and Spilt :)
check out my server! click here

If at first you don't succeed, Improvise! :D