Author Topic: money save/load script  (Read 2489 times)

0 Members and 1 Guest are viewing this topic.

Offline Galaxyman

  • Major(1)
  • Posts: 14
money save/load script
« on: January 09, 2010, 09:41:42 pm »
well, for my server im trying to make a script that does the following:

when a player leaves the server it should write the name of that player and his/her money (which is an int called money[ID] used by another script) into a .txt file, and when the player joins the server again he should get his money back :P

to read out the money-amount i started like this but it doesnt work =O
Code: [Select]
procedure OnJoinTeam(ID, Team: byte);
begin
if (FileExists('scripts/money/player/'+inttostr(GetPlayerStat(ID,'Name'))+'.txt')) then begin

money[ID] := WriteLn(ReadFile('scripts/money/player/'+inttostr(GetPlayerStat(ID,'Name'))+'.txt')) -50;


    end;
end;


can somebody write a (working) script for me?

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: money save/load script
« Reply #1 on: January 09, 2010, 10:51:24 pm »
Code: [Select]
procedure OnJoinGame(ID, Team: byte);
var fname: string;
begin
fname := 'scripts/money/player/' + getplayerstat(ID,'name') + '.txt');
if fileexists(fname) then begin
     money[ID] := strtoint(readfile(fname)) - 50;
     end
end

Untested


Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: money save/load script
« Reply #2 on: January 10, 2010, 02:56:40 am »
dont forget that player names could contain illegal filename characters (such as /?* \). Using HTTPEncode() on the names should be a good enough workaround (if you dont want to mess with regex etc)

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: money save/load script
« Reply #3 on: January 10, 2010, 04:10:39 am »
I guess ill put this out here. (i never learned how to use regex lol)

Code: [Select]
function BadCharByNum(Num: integer): string;
begin
result := '';
case num of
0: result := '\';
1: result := '/';
2: result := ':';
3: result := '*';
4: result := '?';
5: result := '"';
6: result := '<';
7: result := '>';
8: result := '|';
end;
end;

function SafeName(Name: string): string;
var still: boolean; i,temp: integer;
begin
result := name;
still := true;
while(still=true) do begin
still := false;
for i := 0 to 8 do begin
if containsstring(name,badcharbynum(i)) then begin
temp := pos(badcharbynum(i),name);
delete(name,temp,1);
still := true;
end;
end;
end;
result := name;
end;


Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: money save/load script
« Reply #4 on: January 10, 2010, 04:42:11 am »
Hacktank, that will delete only 1 bad char of a type. Anyway, what if player's nick is *** and other player's nick is ///?
« Last Edit: January 10, 2010, 04:43:49 am by Gizd »

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: money save/load script
« Reply #5 on: January 10, 2010, 05:33:21 am »
Hacktank, that will delete only 1 bad char of a type. Anyway, what if player's nick is *** and other player's nick is ///?

? It goes in the while loop until the string no longer contains any special characters.
Emm... Good point. Its never come up, heh. Guess i could change it to replace it with a different character that is legal but unique


Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: money save/load script
« Reply #6 on: January 10, 2010, 05:51:18 am »
Pasted from Fistbox:
Quote
function FilterFilename(const filename: string):string;
var
   i,len: byte;
   c: string;
begin
   len := length(filename);
   result := '';
   for i := 1 to len do begin
      c := copy(filename,i,1);
      if (c=chr(92)) or (c='/') or (c=':') or (c='*') or (c='?') or (c='"') or (c='<') or (c='>') or (c='|') then
         result := result + '_'
      else
         result := result + c;
      end;
   result := LowerCase(result);
end;

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: money save/load script
« Reply #7 on: January 10, 2010, 06:25:54 am »
Pasted from Fistbox:
Quote
function FilterFilename(const filename: string):string;
var
   i,len: byte;
   c: string;
begin
   len := length(filename);
   result := '';
   for i := 1 to len do begin
      c := copy(filename,i,1);
      if (c=chr(92)) or (c='/') or (c=':') or (c='*') or (c='?') or (c='"') or (c='<') or (c='>') or (c='|') then
         result := result + '_'
      else
         result := result + c;
      end;
   result := LowerCase(result);
end;
Still doesn't solve the problem of nick made of invalid chars.

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: money save/load script
« Reply #8 on: January 10, 2010, 06:30:29 am »
Still doesn't solve the problem of nick made of invalid chars.
that (if you mean collisions), and you dont have to do c := copy(filename,i,1);, you can just filename

Offline Galaxyman

  • Major(1)
  • Posts: 14
Re: money save/load script
« Reply #9 on: January 10, 2010, 06:58:38 am »
Code: [Select]
procedure OnJoinGame(ID, Team: byte);
var fname: string;
begin
fname := 'scripts/ws/playermoney/' + getplayerstat(ID,'name') + '.txt';
if fileexists(fname) then begin
     money[ID] := strtoint(readfile(fname));
    writeConsole(ID, 'Your Money is: $' + inttostr(money[ID]), RGB(0,255,255));
  end else
begin
    money[ID] := 50;
    writeConsole(ID, 'Your Money is: $' + inttostr(money[ID]), RGB(0,255,255));
     end;
end;

now when i use this script no error occurs while recompiling but it doesnt work,too...as if it was deaktivated x/

and when i join the game the console says:

(13:19:19) 
  • [Error] ws -> OnJoinTeam: '500

(13:19:20) ' is not a valid integer value

the "500" is what i have written in the "Galaxyman.txt" =P
« Last Edit: January 10, 2010, 07:21:51 am by Galaxyman »

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: money save/load script
« Reply #10 on: January 10, 2010, 09:25:13 am »
There's a new line sequence #13#10 at the end of each line and that's why "500#13#10" is not a valid integer value. Make sure you remove it.

Code: ( Pascal) [Select]
function GetMoney(ID: byte): integer;
var
  money: string;
begin
  money:= ReadFile('scripts/ws/playermoney/' + getplayerstat(ID,'name') + '.txt');
  Result:= StrToInt(Copy(money, 0, length(money) - 2));
end;
« Last Edit: January 10, 2010, 11:18:36 am by CurryWurst »
Soldat Global Account System: #soldat.sgas @ quakenet

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: money save/load script
« Reply #11 on: January 10, 2010, 01:54:58 pm »
You can also save as in example |money| and use GetPiece(ReadFile(...),'|',1)

Offline Galaxyman

  • Major(1)
  • Posts: 14
Re: money save/load script
« Reply #12 on: January 10, 2010, 02:08:22 pm »
got it. thx all =D
« Last Edit: January 10, 2010, 06:23:36 pm by Galaxyman »

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: money save/load script
« Reply #13 on: January 19, 2010, 04:09:07 pm »
can you put a download of the script plese ?

Offline Furai

  • Administrator
  • Veteran
  • *****
  • Posts: 1908
    • TransHuman Design
Re: money save/load script
« Reply #14 on: January 19, 2010, 04:29:20 pm »
What for? Can't you copy&paste code?
"My senses are so powerful that I can hear the blood pumping through your veins."

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: money save/load script
« Reply #15 on: January 19, 2010, 04:36:00 pm »
yea i can but how i install it

From: January 19, 2010, 07:27:18 pm
where i paste the code how i make the script work ? HELP ME !!!!!!!!!
« Last Edit: January 19, 2010, 07:27:18 pm by mich1103 »

Offline y0uRd34th

  • Camper
  • ***
  • Posts: 325
  • [i]Look Signature![/i]
Re: money save/load script
« Reply #16 on: January 20, 2010, 07:45:23 am »
What for? Can't you copy&paste code?
I told him in his thread where he asked after an "money save/load script" to ask galaxyman after his script, the code the people here pasted does not help him atleast ;)

When he does not give you the script or you can not contact him, ill maybe make it for you.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: money save/load script
« Reply #17 on: January 20, 2010, 03:53:03 pm »
huuuuummmmmmmmm idont understand :-\

Offline Norbo

  • Camper
  • ***
  • Posts: 338
Re: money save/load script
« Reply #18 on: January 20, 2010, 04:32:08 pm »
ok, here is a step by step guide:

right click anyware on your desktop
go to new > new text document (or something like that)
copy and paste the script that you want to install
click on file > save as
select all files in file type
type in script.pas
then save
now create another text file
name it Includes
now open the file and type in script.pas
then save the file
then make a new folder and put includes.txt and script.pas in that folder, name the folder whatever you want
now drag and drop that folder into the folder scripts on your server
now go to server.ini
change Scripting=0 to Scripting=1
now run your server
if your not an idiot the script should run with no problems