Scripting Healthpacks that drop on death

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: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Scripting Healthpacks that drop on death

Post by Drofder2004 » July 12th, 2011, 1:10 pm

where is dropHealth being called?
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: Scripting Healthpacks that drop on death

Post by F |Madness| U » July 12th, 2011, 1:31 pm

It's in various other functions, but each of these functions are only called once, and it originates from onPlayerSpawned.
-

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

Re: Scripting Healthpacks that drop on death

Post by Nekoneko » July 12th, 2011, 2:15 pm

what I would do for debug is:

at the start of the script put in a

self endon("delete_healthpack");
self notify("delete_healthpack");

So, if it is running twice, it'll stop.
If it now only gives you health once, you know it's being called twice.

Also
Your do_healthtrigger never ends, unless it's triggered (not a bad problem, but it's still running in the background forever)
So you could also end the do_healthtrigger on a notify and in the first script after 30 secs, notify, so that it will stop.

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

Re: Scripting Healthpacks that drop on death

Post by IzNoGoD » July 12th, 2011, 2:21 pm

Nekoneko wrote:what I would do for debug is:

at the start of the script put in a

self endon("delete_healthpack");
self notify("delete_healthpack");

So, if it is running twice, it'll stop.
If it now only gives you health once, you know it's being called twice.

Also
Your do_healthtrigger never ends, unless it's triggered (not a bad problem, but it's still running in the background forever)
So you could also end the do_healthtrigger on a notify and in the first script after 30 secs, notify, so that it will stop.
exactly why i made the self endon("spawned_player") in my script.
LMGTFY!

Its not a glitch... Its the future!

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

Re: Scripting Healthpacks that drop on death

Post by Nekoneko » July 12th, 2011, 2:27 pm

Yours could still run twice, if the onPlayerSpawned is run twice.

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

Re: Scripting Healthpacks that drop on death

Post by IzNoGoD » July 12th, 2011, 7:17 pm

Nekoneko wrote:Yours could still run twice, if the onPlayerSpawned is run twice.
Onplayerspawned sends out a nice notify: "spawned_player" :) :) :)
LMGTFY!

Its not a glitch... Its the future!

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

Re: Scripting Healthpacks that drop on death

Post by Nekoneko » July 12th, 2011, 8:23 pm

I don't get it..
When the player spawns the script will stop.
But onPlayerSpawned runs the script.
So if onPlayerSpawned is run twice, it will run twice too.

More on topic:
And did it work? ^^

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

Re: Scripting Healthpacks that drop on death

Post by Drofder2004 » July 12th, 2011, 8:31 pm

F |Madness| U wrote:It's in various other functions, but each of these functions are only called once, and it originates from onPlayerSpawned.
If I had 10 functions calling one function once EACH, there would be 10 functions.

The likelyhood is that this function is being called twice... because of two separate functions.
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: Scripting Healthpacks that drop on death

Post by F |Madness| U » July 12th, 2011, 9:51 pm

Drofder2004 wrote:
F |Madness| U wrote:It's in various other functions, but each of these functions are only called once, and it originates from onPlayerSpawned.
If I had 10 functions calling one function once EACH, there would be 10 functions.

The likelyhood is that this function is being called twice... because of two separate functions.
EDIT: It was infact called twice..most bizarrely however. Since I have been testing the mod with bots (I used somebody elses code for spawning bots since I was a pure noob when I started), in the thread where bots are spawned, I found the line bot thread onPlayerSpawned(). No idea why he needed to call it there, so yeah basically there was onPlayerSpawned() being called when the bots were initiated, and when the bots connected to the server. Anyway the problem has solved and it has also fixed many other smaller issues in my mod :)
-

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

Re: Scripting Healthpacks that drop on death

Post by F |Madness| U » July 12th, 2011, 10:52 pm

I also have a small problem regarding custom Dvars however, (kinda aimed at Drofder since I read his guide on them).

When I create a custom dvar in my gsc, I go into my mod and type the dvar, however it simply says unknown command.
Eg.

Code: Select all

sayCommand()
{
        if(getdvar("scr_say") == "")
        {
                setdvar("scr_say", "nothing");
        }
        while(1)
        {
                if(getDvar("scr_say") != "nothing")
                {
                        abc = getDvar("scr_say");
                        iprintlnbold(abc);
                        setDvar("scr_say", "nothing");
                }
                wait 0.1;
        }
}
Threaded on the level when the server starts. I load my map, type /scr_say testing into console, and I just get "unknown cmd scr_say".Arghh
-

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

Re: Scripting Healthpacks that drop on death

Post by IzNoGoD » July 12th, 2011, 11:37 pm

Nekoneko wrote:I don't get it..
When the player spawns the script will stop.
But onPlayerSpawned runs the script.
So if onPlayerSpawned is run twice, it will run twice too.

More on topic:
And did it work? ^^

Lets simplify things:

Code: Select all

 
onplayerspawned()
{
 self notify("spawned_player"); //this is in the stock function
 self thread drophealth();
}
 
drophealth()
{
 self endon("spawned_player");
 while(true)
  wait 0.05;
}
 
see that the function can only be running once?
LMGTFY!

Its not a glitch... Its the future!

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

Re: Scripting Healthpacks that drop on death

Post by Drofder2004 » July 13th, 2011, 2:27 am

F |Madness| U wrote:I load my map, type /scr_say testing into console, and I just get "unknown cmd scr_say".Arghh
The Dvar does not exist until you "set" it..

So, you can either do "/set scr_say hello" in console or commonly

Code: Select all

if(getDvar("customDvar") == "")
   setDvar("customDvar", "customValue")
or, if you are making a DVAR you want to start empty:

Code: Select all

setDvar("customDvar", "");
Now, you can simply load "/customDvar customValue" without the need to set it first.
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

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

Re: Scripting Healthpacks that drop on death

Post by Nekoneko » July 13th, 2011, 11:47 am

Am I missing something?
You do not have the required permissions to view the files attached to this post.

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

Re: Scripting Healthpacks that drop on death

Post by F |Madness| U » July 13th, 2011, 12:35 pm

@Drofder, I still don't see what's wrong with my code?

It checks to see if the dvar scr_say exists (which it doesn't), and then sets the dvar to equal "nothing".

Then it infinitely checks to see if the dvar equals something other than "nothing", and prints what it equals. Surely when I type in console /scr_say TEST , that will change the value of the dvar from "nothing" to "TEST", and it will then print it? Am I missing something? ALso with dvars in Black Ops you can't use `set` ingame for some reason. Ie. /set g_gametype dm wouldn't work, but /g_gametype dm does.
-

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

Re: Scripting Healthpacks that drop on death

Post by Nekoneko » July 13th, 2011, 1:11 pm

well does it say "nothing" once you connect and type in /scr_say

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests