A syntax error that I can't see whats causing it.

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13315
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: A syntax error that I can't see whats causing it.

Post by Drofder2004 » June 21st, 2011, 8:07 pm

Indeed, it is not the loop that causes stress. An empty loop is no more stressful than calling a blank function.
It is very dependant on what is being called inside the loops.

Generally, player loops will cause more stress, simply because there are more players than there is a 'level'.
There are few if no situation that can substitute a player to level loop (or opposite) effectively. The loop is either designed to run on a level a player.

For example, updating a players HUD would be pointless to loop in a level, updating every players HUD just so one player is up-to-date, you would just use a player loop, and the same would apply for a 'level' and team scores.

This is why we use 'Notify' calls, so that loops that require player events (kills, deaths, etc) can be acknowledged by a level based loop.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: A syntax error that I can't see whats causing it.

Post by F |Madness| U » June 21st, 2011, 8:35 pm

I already guessed that an empty loop would cause no server stress :P

But from what your saying, something like my code below wouldn't cause too much stress? (being called on the level btw).

Code: Select all

timescale()
{
        if(getDvarFloat("scr_timescale") != 1.0)
        {
                setdvar("scr_timescale", 1.0);
        }
        timecmd = getDvarFloat("scr_timescale");
        
        for(;;)
        {
                wait 0.5;
                timecmd;
                SetTimeScale(timecmd);//--- expected 2 args?
        }
}
Oh ye the `SetTimeScale();` function apprently requires 2 arguments, however after searching through many .gscs all I found was `SetTimeScale(2);` or `SetTimeScale(1);` etc, any idea on what second argument could be other than the number? This isn't CoD4 remember :|
-

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: A syntax error that I can't see whats causing it.

Post by IzNoGoD » June 21st, 2011, 8:59 pm

setcvar("timescale",2); or smthing
You can write write-protected cvars from script...
LMGTFY!

Its not a glitch... Its the future!

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: A syntax error that I can't see whats causing it.

Post by F |Madness| U » June 21st, 2011, 9:07 pm

You sure? I know there is a command in black ops (something like g_scoreboard_axiscolour) that exists, but even if you change it in script it doesn't work ingame :S
-

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13315
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: A syntax error that I can't see whats causing it.

Post by Drofder2004 » June 21st, 2011, 10:51 pm

F |Madness| U wrote:You sure? I know there is a command in black ops (something like g_scoreboard_axiscolour) that exists, but even if you change it in script it doesn't work ingame :S
Most likely because it is being reverted by another function elsewhere.

All cheat protected server values, can, as said, be written by script.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: A syntax error that I can't see whats causing it.

Post by megazor » June 22nd, 2011, 1:43 am

as written on zeroy's script index page, setTimeScale() is only for sp.

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: A syntax error that I can't see whats causing it.

Post by F |Madness| U » June 23rd, 2011, 2:10 pm

megazor wrote:as written on zeroy's script index page, setTimeScale() is only for sp.
Is there no way to use functins from SP in MP? Seems kinda stupid that any good functions in SP have to go to waste for mods..
-

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: A syntax error that I can't see whats causing it.

Post by megazor » June 23rd, 2011, 3:20 pm

to change the timescale, you can use:

setCvar("timescale", 2);

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: A syntax error that I can't see whats causing it.

Post by IzNoGoD » June 23rd, 2011, 3:47 pm

IzNoGoD wrote:setcvar("timescale",2); or smthing
You can write write-protected cvars from script...
Was already here :)
LMGTFY!

Its not a glitch... Its the future!

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: A syntax error that I can't see whats causing it.

Post by F |Madness| U » June 23rd, 2011, 3:56 pm

Doesn't work in black ops, no idea why. But if there was some other functions in SP that arn't in MP, is tehre anyway to use them?

And also I must be really dumb, I'm trying to make something happen when a certain person is killed, and i also want damage to show when you shoot a person. I found a function which I think I should use, but I have no idea how to use it.

Code: Select all

CodeCallback_PlayerDamage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, timeOffset)
{
        self endon("disconnect");
        [[level.callbackPlayerDamage]](eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, timeOffset);
}
CodeCallback_PlayerKilled(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
{
        self endon("disconnect");
        [[level.callbackPlayerKilled]](eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration);
}
I'm guessing I should use them, but I really have no idea how to. To give you an idea of what I want to do, some example script:

Code: Select all

Showdamagereceived()
{
        for(;;)
        {
                self waittill("been_damaged");
                self iprintln(AttackerName + "inflicted " + damage " on you.");
        }
}
 
Showdamagedone()
{
        for(;;)
        {
                self waittill("done_damage");
                self iprintln("You inflicted " + damage + " on " + DamagedName);
        }
}
 
specialpersonkilled()
{
        if(KilledPerson == level.specialperson)
        {
                ...
        }
}
-

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: A syntax error that I can't see whats causing it.

Post by IzNoGoD » June 23rd, 2011, 4:55 pm

Do you run this mod from a dedicated server? (Lan or internet in cod2..)
Cause if you dont, it wont work. Have been messing around with that a lot myself.


Edit: the code you requested:

Code: Select all

 
onserverstart()
{
        wait 1; //to ensure the callbacks are already written
        //store the old callbacks
        level.oldcallbackPlayerDamage=level.callbackplayerdamage;
        level.oldcallbackplayerkilled=level.callbackplayerkilled;
        //now, create new callbacks
        level.callbackplayerdamage=::damage;
        level.callbackplayerkilled=::killed;
}
 
 
damage(eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, timeOffset)
{
        if(isdefined(eAttacker)&&isplayer(eAttacker)&&eAttacker!=self)
        {
                self iprintln(eAttacker.name+" did "+iDamage+" damage on you");
                eAttacker iprintln("You did "+iDamage+" damage to "+self.name);
        }
        //now, do the normal callback
        [[level.oldcallbackplayerdamage]](eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, timeOffset);
}
 
killed(eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration)
{
        if(isdefined(self)&&isplayer(self)&&isdefined(level.specialperson)&&isplayer(level.specialperson)&&self==level.specialperson)
        {
                iprintlnbold("The special person has been killed, it was "+self.name);
                iprintlnbold("Now all should cry");
        }
        //do the normal callback after this
        [[level.oldcallbackplayerkilled]](eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration);
}
 
Its untested, but should work.
LMGTFY!

Its not a glitch... Its the future!

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: A syntax error that I can't see whats causing it.

Post by F |Madness| U » June 23rd, 2011, 10:29 pm

Thanks for the help, and I'm running a listen server (other friends can connect to it, but I am the client/level at the same time).

I'll test that code you provided soon, just wondering would the damage()/killed() functions need to be infinitely looped once a player spawns? Or just called when a player spawns?

Lastly, I don't really understand the reason for the first function, nor do I understand the `callback code` at the end of damage/killed functions. This bit:

Code: Select all

[[level.oldcallbackplayerdamage]](eInflictor, eAttacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, timeOffset);
-

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: A syntax error that I can't see whats causing it.

Post by IzNoGoD » June 23rd, 2011, 11:03 pm

The game creates a callback for killed/damage and stores it in level.callbackplayerdamage or level.callbackplayerkilled
This is done at the start of the game

After one second, i copy this callback into the var with OLD in the name, and overwrite the existing ones with my own functions.

Now every time a player is damaged, it will be redirected to the level.callbackplayerdamage which i created (damage()), but as you want to keep the original too, i added the [[level.oldcallbackplayerdamage]], which directs the player to the finishplayerdamage() and stuff of the original game.


Also: try NOT to be client and server at the same time when messing with server cvars.
LMGTFY!

Its not a glitch... Its the future!

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: A syntax error that I can't see whats causing it.

Post by F |Madness| U » June 23rd, 2011, 11:11 pm

Okay I think I understand it better, thanks. Would this mean I only have to call the damage/killed functions once, when a player connects?

And I don't think its posssible to not be client/server at the same time on Blops, unless you buy an official server, which atm I don't want to do :P
-

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: A syntax error that I can't see whats causing it.

Post by IzNoGoD » June 23rd, 2011, 11:20 pm

You only need to call the onserverstart() when the game starts
Script takes care of the rest


For the servercvar problem: set the cvar on clients when they connect
LMGTFY!

Its not a glitch... Its the future!

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest