Automatic weapon add script
Moderator: Core Staff
Automatic weapon add script
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-
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-

-
- 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
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.
[...]
#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.
Re: Automatic weapon add script
Well, im rather new to scripting.. i totally understand that part, but how do i go about doing this lol
that is what i have so far, well..
(dont laugh please)
-XeloX-
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?");
}
}
(dont laugh please)
-XeloX-
Last edited by XeloX on October 7th, 2010, 10:36 pm, edited 1 time in total.

Re: Automatic weapon add script
Found out that all parts get activated but it does not give a weapon,
Would this mean this part is wrong?
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?");
}
}

Re: Automatic weapon add script
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
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
Re: Automatic weapon add script
why did u overwrite the stock function 'giveWeapon()'? give it a different name.self giveweapon();
-
- CJ Worshipper
- Posts: 289
- Joined: December 5th, 2009, 7:12 am
- Location: Australia
Re: Automatic weapon add script
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?");
}
}
Re: Automatic weapon add script
im very new to scripting and tbh dont have much clue what everything means, but shouldnt it be like this?iCYsoldier wrote:Code: Select all
if(self getGuid() == "****************************")//Guid Here! iprintlnbold("onplayerspawned ^2activated"); { self thread xelox(); }
Code: Select all
if(self getGuid() == "****************************")//Guid Here!
{
self thread xelox();
}
iprintlnbold("onplayerspawned ^2activated");
Re: Automatic weapon add script
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
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
Re: Automatic weapon add script
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.
So it wont work on a test-map when i click on run selected map.
It needs to be running on a server.
-
- CJ Worshipper
- Posts: 289
- Joined: December 5th, 2009, 7:12 am
- Location: Australia
Re: Automatic weapon add script
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: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
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);
}
Re: Automatic weapon add script
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.
Running printguid on player still keeps it blank.
Would it work on a server, if so then its fine.
Re: Automatic weapon add script
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.
-
- CJ Worshipper
- Posts: 289
- Joined: December 5th, 2009, 7:12 am
- Location: Australia
Re: Automatic weapon add script
Ah ok, I just tested what I wrote and it didn't work
Yeh, it should work in a public server

Who is online
Users browsing this forum: No registered users and 8 guests