Page 2 of 3

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

Posted: June 21st, 2011, 8:07 pm
by Drofder2004
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.

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

Posted: June 21st, 2011, 8:35 pm
by F |Madness| U
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 :|

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

Posted: June 21st, 2011, 8:59 pm
by IzNoGoD
setcvar("timescale",2); or smthing
You can write write-protected cvars from script...

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

Posted: June 21st, 2011, 9:07 pm
by F |Madness| U
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

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

Posted: June 21st, 2011, 10:51 pm
by Drofder2004
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.

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

Posted: June 22nd, 2011, 1:43 am
by megazor
as written on zeroy's script index page, setTimeScale() is only for sp.

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

Posted: June 23rd, 2011, 2:10 pm
by F |Madness| U
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..

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

Posted: June 23rd, 2011, 3:20 pm
by megazor
to change the timescale, you can use:

setCvar("timescale", 2);

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

Posted: June 23rd, 2011, 3:47 pm
by IzNoGoD
IzNoGoD wrote:setcvar("timescale",2); or smthing
You can write write-protected cvars from script...
Was already here :)

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

Posted: June 23rd, 2011, 3:56 pm
by F |Madness| U
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)
        {
                ...
        }
}

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

Posted: June 23rd, 2011, 4:55 pm
by IzNoGoD
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.

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

Posted: June 23rd, 2011, 10:29 pm
by F |Madness| U
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);

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

Posted: June 23rd, 2011, 11:03 pm
by IzNoGoD
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.

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

Posted: June 23rd, 2011, 11:11 pm
by F |Madness| U
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

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

Posted: June 23rd, 2011, 11:20 pm
by IzNoGoD
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