Author Topic: Frosty's scripting thread  (Read 17983 times)

0 Members and 1 Guest are viewing this topic.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: Frosty's scripting thread
« Reply #20 on: July 17, 2010, 06:48:50 am »
srry, see edit :)

thanks for da help dark :)

edit: is there any way to change player names to add rank inits? like "pvt.<playername>"
« Last Edit: July 17, 2010, 06:53:42 am by frosty »
check out my server! click here

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

DarkCrusade

  • Guest
Re: Frosty's scripting thread
« Reply #21 on: July 17, 2010, 07:07:03 am »
No, because it is not only unnecessary but abusable. Like /setname ID ToothyVagina

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Frosty's scripting thread
« Reply #22 on: July 17, 2010, 06:28:31 pm »
I had a question myself, but I didn't wanna start a brand new thread *cough*
what is the best (and most accurate name) to keep track of in-game time (ie: starting at the beginning of map) to be used, for example, in OnPlayerKill.  does something like GetTicks() exist?
Can't think of anything original to put here...

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Frosty's scripting thread
« Reply #23 on: July 17, 2010, 08:29:59 pm »
@tyxstand:
Code: [Select]
function GetTickCount(): cardinal;It is the same "tick unit" used by AppOnIdle. Return type is cardinal, or integer; not certain, but if I recall correctly I saw it first posted with type cardinal, which does not match AppOnIdle :/ not sure why but whatever, they are still interchangeable usually.

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Frosty's scripting thread
« Reply #24 on: July 17, 2010, 08:51:49 pm »
@tyxstand:
Code: [Select]
function GetTickCount(): cardinal;It is the same "tick unit" used by AppOnIdle. Return type is cardinal, or integer; not certain, but if I recall correctly I saw it first posted with type cardinal, which does not match AppOnIdle :/ not sure why but whatever, they are still interchangeable usually.

uhhhm, GetTickCount is a real function? i've never heard of that anywhere. or are you suggesting that it should be implemented?
Can't think of anything original to put here...

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Frosty's scripting thread
« Reply #25 on: July 17, 2010, 10:24:19 pm »
@tyxstand:
Code: [Select]
function GetTickCount(): cardinal;It is the same "tick unit" used by AppOnIdle. Return type is cardinal, or integer; not certain, but if I recall correctly I saw it first posted with type cardinal, which does not match AppOnIdle :/ not sure why but whatever, they are still interchangeable usually.

uhhhm, GetTickCount is a real function? i've never heard of that anywhere. or are you suggesting that it should be implemented?
It is real. Test it out yourself if you do not believe me.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: Frosty's scripting thread
« Reply #26 on: July 18, 2010, 12:23:26 am »
ok this is annoying me, for some reason its not reading the ini file correctly and keeps returning the set error when i use /char

Code: (pascal) [Select]
Procedure OnPlayerCommand()
if Text = '/char' then begin
    WriteConsole(ID,'Your stats',$EE81FAA1);
    WriteConsole(ID,'Total Kills: '+inttostr(trKills[ID])+'!',$EE81FAA1);
    WriteConsole(ID,'Rank: '+ReadINI('Players/'+GetPlayerStat(ID,'Name')+'.ini','stats','rank','*ERROR while loading rank*')+'!',$EE81FAA1);
    WriteConsole(ID,'Class: '+ReadINI('Players/'+GetPlayerStat(ID,'Name')+'.ini','stats','class','*ERROR while loading kills*')+'!',$EE81FAA1);
    WriteConsole(ID,'Total number of Predators used: '+ReadINI('Players/'+GetPlayerStat(i,'Name')+'.ini','stats','tupred','*ERROR while loading pred num*')+'!',$EE81FAA1);
    WriteConsole(ID,'Total number of Achievements: '+ReadINI('Players/'+GetPlayerStat(i,'Name')+'.ini','stats','kills','*ERROR while loading achievements*')+'!',$EE81FAA1);
  end;
end;

why is it erroring, thats the only line that is erroring, every other line is fine

the var should be updating when someone uses "/buy pred" or "/buy tpred' but its not updating for some reason

and heres the contents of the ini file that its reading from
Code: [Select]
[stats]
IP=
reg=1
kills=0
rank=1
class=1
tupred=0
tna=1

[achievements]
TP=1

Total Number of Preds used should be "0" not "*error while loading pred num*"

in fact that line isnt even being written to and i dont see why, should be when i type /save, but EVERYTHING else is writing so i dont see how debugging will do anything as the rest of the section thats its in is working perfect, including the line below thats is giving me the error

edit: also Total number of achievements is returning its error which is 0, atm it should be saying 1 ingame cuz thats what it says in the char file, tna=1, yet ingame tna=0 so something isnt right

full code is attached
« Last Edit: July 18, 2010, 12:36:56 am by frosty »
check out my server! click here

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

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Frosty's scripting thread
« Reply #27 on: July 18, 2010, 01:06:31 am »
first rule of debugging:
you can ALWAYS debug. if you honestly thing you cannot debug, you probably are: a) not debugging correctly, or b) not using your debug information correctly.

anyway, what is this "i" variable. maybe you mean "ID"?
Code: [Select]
GetPlayerStat(i,'Name')
yet another question:
which is programming-wise smarter:

a -> boolean
if (a) then a := false;

or sipmly:

a := false;

also, i'm about 70% of time a will be false when getting to this point.
« Last Edit: July 18, 2010, 01:16:40 am by zyxstand »
Can't think of anything original to put here...

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: Frosty's scripting thread
« Reply #28 on: July 18, 2010, 03:27:46 am »
uhh which line u reading from?

nvm another silly error
« Last Edit: July 18, 2010, 03:31:09 am by frosty »
check out my server! click here

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

DarkCrusade

  • Guest
Re: Frosty's scripting thread
« Reply #29 on: July 18, 2010, 04:37:55 am »
OnPlayerCommand is a function, not a procedure:

Code: (pascal) [Select]
Function OnPlayerCommand(ID:Byte; Text:String):Boolean;
begin

  Result := false // set to true to disallow commands
end;


Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: Frosty's scripting thread
« Reply #30 on: July 18, 2010, 01:28:23 pm »
lol oops, u get the point tho, thanks dark

From: July 18, 2010, 11:53:10 pm
omg how the feck do i debug this?

for some reason lines are disappearing from the ini file, and some are being changed randomly

but there is nothing used in the code to remove keys from the ini file, only think that is is the code for the iniremovekey or whatever they were, but those functions arent being used, as for the randomly changing keys...., maybe theres somehing else thats causing this, but i got a headache and cant think at the moment, this is aggrivating


From: July 18, 2010, 11:57:05 pm
seems to be caused on lag spike
« Last Edit: July 18, 2010, 11:57:05 pm by frosty »
check out my server! click here

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

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Frosty's scripting thread
« Reply #31 on: July 19, 2010, 12:00:34 pm »
lol oops, u get the point tho, thanks dark

From: July 18, 2010, 11:53:10 pm
omg how the feck do i debug this?

for some reason lines are disappearing from the ini file, and some are being changed randomly

but there is nothing used in the code to remove keys from the ini file, only think that is is the code for the iniremovekey or whatever they were, but those functions arent being used, as for the randomly changing keys...., maybe theres somehing else thats causing this, but i got a headache and cant think at the moment, this is aggrivating


From: July 18, 2010, 11:57:05 pm
seems to be caused on lag spike

are you quoting yourself or something?
are you saying you've figured it out?

if not, DEBUG!
is the error consistent?
  YES: your code is wrong.
  NO: does the error occur consistently with something happening in the game (ie, player joins, leaves, and joins again later, and THEN the error happens)
    YES: check your code (now you have better idea where to look for errors)
    NO: keep trying to figure out what causes it. at worst, it's something your code is vulnerable to (ie: lag spike?) - in which case you need to try another approach that would circumvent this issue.

this is example of basic debugging (at least so from the limited information we have from what you explained)
Can't think of anything original to put here...

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: Frosty's scripting thread
« Reply #32 on: July 19, 2010, 01:32:31 pm »
yes but im only using iniwrite in the lag spike which i have removed and replaced with "saving all accounts"

which is causing all players files who are online to remove most of the lines, and leave only the lines that were written to and reset the lines that arent kills, but the lines that are being reset arent being written to on save in that section
theres only iniwrite and inisave so it shouldnt be doing it, i have also tried removing sleep(), same thing happens

so how would i save the accs every 5 mins when this happens, right now i have to /save manually, and when this does happen i have to delete the player file and get them to start over i have even tried getting the /save command to be triggered every 5 mins but that didnt work

i know where the problem is , but the problem with the problem is that the problem shouldnt be happening, look:

Code: (pascal) [Select]
procedure apponidle
if Timer = 0 then begin
//Writeconsole(0,'saving all accounts',$0000FFFF);
//Command('/save');
for i:= 1 to 32 do if Getplayerstat(i,'Ping') > 0 then begin
iniWrite('Players/'+GetPlayerStat(i,'Name')+'.ini','stats','kills',inttostr(trKills[i]));
iniWrite('Players/'+GetPlayerStat(i,'Name')+'.ini','stats','tupred',inttostr(TUPred[i]));
iniWrite('Players/'+GetPlayerStat(i,'Name')+'.ini','stats','barkills',inttostr(barKills[i]));
inisave('Players/'+GetPlayerStat(i,'Name')+'.ini',iniLoad('Players/'+GetPlayerStat(ID,'Name')+'.ini'));
end;
iniWrite('scripts/Shop/profit.ini','profit','cash',inttostr(Cash));
//Sleep(2000);
//Timer:=300;
end;
end;

what is wrong with this section, in the ini file, class and rank are changed and tna and the achieveemnts section are removed, but why is class and rank being changed and tna ancd achievements section being removed when this is triggered? theres no class or rank, or tna or achieveemnts here, so WTF, only thing i can think of is that using apponidle to save accs isnt a good way to do it, so how then without using timers would i save accs every 5 mins as i need apponidle to do it so idk what else to do. having that section in its own function being triggered by apponidle also does the same thing :(

From: July 19, 2010, 01:33:42 pm
edit: omg!!!!! i thin i just saw the problem, srry guys and thanks
check out my server! click here

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

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Frosty's scripting thread
« Reply #33 on: July 19, 2010, 02:37:30 pm »
few questions:
apponidle is called every second.  it seems your function is also then called every second (I don't see anything modifying variable "Timer").
also: in line 9 of what you've shown, what is the variable "ID" in "GetPlayerStat(ID,'Name')" ?

READ THIS:  If i understand correctly, this chunk of code is supposed to update the 3 keys for all players (namely kills, tupred, and barkills).  If this is so, then all you need to have is the iniWrite lines. i don't understand what the inisave line is supposed to do.  iniwrite loads the ini, modifies the desired line, and saves the ini - all you need to effectively update any section.
so explain to me what inisave is!

if i'm correct, and you don't need inisave, then take this lesson:
part of programming is understanding what the computer goes through, line-by-line!  look at where you call iniwrite, look at what iniwrite does, and then look at how the whole thing continues from there.  it's very important to know what steps the computer will go through (or, in this case, at least what the code will go through)!

also:
lagspikes may be caused if you're overloading the engine at one point and not allowing it to deal with non-scripting soldat-related tasks (including processing and sending out packets) - so if you make your engine do a lott of computations, and only after one whole second will it continue to do soldat stuff, then everyone in the server will get a lagspike (on their end, it looks like the server hasn't responded for a whole second, just like when there's very slow connection).
« Last Edit: July 19, 2010, 02:41:32 pm by zyxstand »
Can't think of anything original to put here...

DarkCrusade

  • Guest
Re: Frosty's scripting thread
« Reply #34 on: July 19, 2010, 02:44:59 pm »
ID is an identifier for the player who called a procedure. To clarify who is who in some procedures ID is replaced by something more specific like "Victim" or "Shooter" (example: Procedure OnPlayerKill(Killer,Victim:Byte; Weapon:String);.


Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Frosty's scripting thread
« Reply #35 on: July 19, 2010, 02:52:06 pm »
but this section of code is contained in apponidle. i don't see parameters or argument calls that determine ID.
to me, it looks like the point is to update all ini files of all the players in the game once every 10 seconds or so (although as it stands, it seems to do so every second)
Can't think of anything original to put here...

DarkCrusade

  • Guest
Re: Frosty's scripting thread
« Reply #36 on: July 19, 2010, 03:03:13 pm »
What ... ID as a global var? :|

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Frosty's scripting thread
« Reply #37 on: July 19, 2010, 03:10:17 pm »
well forgive me if i'm wrong, but then wouldn't line 09 overwrite what's been updated by the previous iniwrite lines??

Code: [Select]
08:  iniWrite('Players/'+GetPlayerStat(i,'Name')+'.ini','stats','barkills',inttostr(barKills[i]));
09:  inisave('Players/'+GetPlayerStat(i,'Name')+'.ini',iniLoad('Players/'+GetPlayerStat(ID,'Name')+'.ini'));
Can't think of anything original to put here...

DarkCrusade

  • Guest
Re: Frosty's scripting thread
« Reply #38 on: July 19, 2010, 03:16:16 pm »
Right ;)

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Frosty's scripting thread
« Reply #39 on: July 19, 2010, 03:19:37 pm »
so... is something wrong with his code? or is that its correct function???  also, i dunno if it was just for demonstration purposes, but why isn't there any code limiting how often this gets called. i don't think it can be too good for any server to rewrite files every second!
Can't think of anything original to put here...