Page 1 of 1
Automatic weapon add script
Posted: October 7th, 2010, 9:21 pm
by XeloX
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-
Re: Automatic weapon add script
Posted: October 7th, 2010, 9:27 pm
by Rezil
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.

Re: Automatic weapon add script
Posted: October 7th, 2010, 9:37 pm
by XeloX
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-
Re: Automatic weapon add script
Posted: October 7th, 2010, 9:54 pm
by XeloX
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?");
}
}
Re: Automatic weapon add script
Posted: October 7th, 2010, 10:37 pm
by IzNoGoD
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
Re: Automatic weapon add script
Posted: October 8th, 2010, 3:11 am
by megazor
self giveweapon();
why did u overwrite the stock function 'giveWeapon()'? give it a different name.
Re: Automatic weapon add script
Posted: October 8th, 2010, 3:33 am
by iCYsoldier
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
Posted: October 8th, 2010, 9:13 am
by XeloX
thanks, i got it working!
you sir, are a legend
Re: Automatic weapon add script
Posted: April 20th, 2011, 9:45 pm
by Nekoneko
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");
Re: Automatic weapon add script
Posted: April 21st, 2011, 11:36 am
by Nekoneko
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
Re: Automatic weapon add script
Posted: April 21st, 2011, 12:11 pm
by Nekoneko
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.
Re: Automatic weapon add script
Posted: April 21st, 2011, 12:27 pm
by iCYsoldier
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
Re: Automatic weapon add script
Posted: April 21st, 2011, 12:51 pm
by Nekoneko
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.
Re: Automatic weapon add script
Posted: April 21st, 2011, 1:33 pm
by Opel
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.
Re: Automatic weapon add script
Posted: April 21st, 2011, 1:50 pm
by iCYsoldier
Ah ok, I just tested what I wrote and it didn't work

Yeh, it should work in a public server