Automatic weapon add script

Have questions about CoD4 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
User avatar
XeloX
CJ Newbie
CJ Newbie
Posts: 74
Joined: February 13th, 2010, 9:58 pm

Automatic weapon add script

Post by XeloX » October 7th, 2010, 9:21 pm

Dear community,
I am in the process of making my 2nd map.
What i want added to this map is the following script, I want to make a script that gives me a certain weapon whenever i enter my map.
This should be based on my GUID.
I have experimented and failed before so if anybody can create such a script please help me!

With regards,

-XeloX-
Image

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Automatic weapon add script

Post by Rezil » October 7th, 2010, 9:27 pm

Wait till a player connects. When he does, check his GUID with your own. If there's a match, give that player the weapon you want. Simple. :)
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
XeloX
CJ Newbie
CJ Newbie
Posts: 74
Joined: February 13th, 2010, 9:58 pm

Re: Automatic weapon add script

Post by XeloX » October 7th, 2010, 9:37 pm

Well, im rather new to scripting.. i totally understand that part, but how do i go about doing this lol

Code: Select all

     
onPlayerConnect()
{
   for(;;)
   {
      level waittill("connected", player);
      player thread onPlayerSpawned();
   }
}
     
onPlayerSpawned()
{
   for(;;)
   {
      self waittill("spawned_player");
      if(self getGuid() == "****************************")//Guid Here!
      iprintlnbold("onplayerspawned ^2activated");
      {
         self thread xelox();
      }
   }
}

xelox()
{
   self iprintlnbold("Xelox ^2Activated");
   self giveweapon();
}

giveWeapon()
{
   wait 0.05;
   iprintlnbold("wep give ^2Activated"); 
   if(self HasWeapon("remington700_mp"))
      {
        self giveWeapon( "m40a3_mp", 1, false );
        self giveMaxammo("m40a3_mp");
	iprintln("does it workz?"); 
      }
}
that is what i have so far, well..
(dont laugh please)

-XeloX-
Last edited by XeloX on October 7th, 2010, 10:36 pm, edited 1 time in total.
Image

User avatar
XeloX
CJ Newbie
CJ Newbie
Posts: 74
Joined: February 13th, 2010, 9:58 pm

Re: Automatic weapon add script

Post by XeloX » October 7th, 2010, 9:54 pm

Found out that all parts get activated but it does not give a weapon,
Would this mean this part is wrong?

Code: Select all

giveWeapon()
{
   wait 0.05;
   iprintlnbold("wep give ^2Activated"); 
   if(self HasWeapon("remington700_mp"))
      {
        self giveWeapon( "m40a3_mp", 1, false );
        self giveMaxammo("m40a3_mp");
	iprintln("does it workz?"); 
      }
}
Image

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

Re: Automatic weapon add script

Post by IzNoGoD » October 7th, 2010, 10:37 pm

meh you give gun on entering server
try a self waittil("spawned") or somthing (search some .gsc files for waittils for more info, and some notifies to see where it does give weap)

Also: add a for(;;) loop around it, so it just gives you weapon every spawn

I can code it for you, add me to xfire: imbackagainiba
LMGTFY!

Its not a glitch... Its the future!

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

Re: Automatic weapon add script

Post by megazor » October 8th, 2010, 3:11 am

self giveweapon();
why did u overwrite the stock function 'giveWeapon()'? give it a different name.

User avatar
iCYsoldier
CJ Worshipper
CJ Worshipper
Posts: 289
Joined: December 5th, 2009, 7:12 am
Location: Australia

Re: Automatic weapon add script

Post by iCYsoldier » October 8th, 2010, 3:33 am

Code: Select all

onPlayerConnect()
{
   for(;;)
   {
      level waittill("connected", player);
      player thread onPlayerSpawned();
   }
}
     
onPlayerSpawned()
{
   for(;;)
   {
      self waittill("spawned_player");
      if(self getGuid() == "****************************")//Guid Here!
      iprintlnbold("onplayerspawned ^2activated");
      {
         self thread xelox();
      }
   }
}

xelox()
{
   self iprintlnbold("Xelox ^2Activated");
   self giveWeap(); // Changes function name, there's already a built-int function with the same name
}

giveWeap() // Here's YOUR function
{
   wait 0.05;
   iprintlnbold("wep give ^2Activated");
   if(!self HasWeapon("remington700_mp")) // You will only get an M40A3 if you already have an R700. Do you? If not, write this
      {
        self giveWeapon( "m40a3_mp");
        self giveMaxammo("m40a3_mp");
        wait 0.1;
        self switchToWeapon("m40a3_mp"); // Switches to the m40a3, so you know you have it.
   iprintln("does it workz?");
      }
}

User avatar
XeloX
CJ Newbie
CJ Newbie
Posts: 74
Joined: February 13th, 2010, 9:58 pm

Re: Automatic weapon add script

Post by XeloX » October 8th, 2010, 9:13 am

thanks, i got it working!

you sir, are a legend
Image

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

Re: Automatic weapon add script

Post by Nekoneko » April 20th, 2011, 9:45 pm

iCYsoldier wrote:

Code: Select all

      if(self getGuid() == "****************************")//Guid Here!
      iprintlnbold("onplayerspawned ^2activated");
      {
         self thread xelox();
      }
im very new to scripting and tbh dont have much clue what everything means, but shouldnt it be like this?

Code: Select all

      if(self getGuid() == "****************************")//Guid Here!
      {
         self thread xelox();
      }
      iprintlnbold("onplayerspawned ^2activated");

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

Re: Automatic weapon add script

Post by Nekoneko » April 21st, 2011, 11:36 am

Btw.
I tested this myself and i cant get the getGuid() function to work.
if i have
MyGuid = self getGuid();
iprintln(MyGuid);
it shows as blank.
Why wont the function work

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

Re: Automatic weapon add script

Post by Nekoneko » April 21st, 2011, 12:11 pm

Ah ok sorry then.
So it wont work on a test-map when i click on run selected map.
It needs to be running on a server.

User avatar
iCYsoldier
CJ Worshipper
CJ Worshipper
Posts: 289
Joined: December 5th, 2009, 7:12 am
Location: Australia

Re: Automatic weapon add script

Post by iCYsoldier » April 21st, 2011, 12:27 pm

Nekoneko wrote:Btw.
I tested this myself and i cant get the getGuid() function to work.
if i have
MyGuid = self getGuid();
iprintln(MyGuid);
it shows as blank.
Why wont the function work
The problem may lie when you write 'self'. 'self' refers to what entity you called the function on (I made this mistake when I first learnt). For example, if I had:

Code: Select all

for(;;)
{
     level waittill("connected", player);
     player thread printGUID(); // Runs the 'printGUID' function on the player
}
printGUID()
{
     myGuid = self getGuid(); // You can now start referring to 'player' as 'self'
     self iprintln(myGuid);
}
Also, Xelox's code above, I did forget about that part you pointed out, and you we're right, except that the iprintln statement should be within the if block

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

Re: Automatic weapon add script

Post by Nekoneko » April 21st, 2011, 12:51 pm

Sorry for being so noob, but it still doesnt work..

Running printguid on player still keeps it blank.
Would it work on a server, if so then its fine.

User avatar
Opel
CJ Fan
CJ Fan
Posts: 188
Joined: September 15th, 2008, 12:28 pm
Location: Scotland

Re: Automatic weapon add script

Post by Opel » April 21st, 2011, 1:33 pm

It would work on a server, its just not showing because it's a local server your running. Put it on a dedi server and it will show.

User avatar
iCYsoldier
CJ Worshipper
CJ Worshipper
Posts: 289
Joined: December 5th, 2009, 7:12 am
Location: Australia

Re: Automatic weapon add script

Post by iCYsoldier » April 21st, 2011, 1:50 pm

Ah ok, I just tested what I wrote and it didn't work :P Yeh, it should work in a public server

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests