Sign in to follow this  
Followers 0
Pixel

Script Help

10 posts in this topic

Basically, I got a beginner's challenge to modding from Lossy, and he gave me this:

 

[00:36] [Raid]Lossy: spawn a random weapon trigger with a box model on a random spawn and if you press F on it, it will give you a random gun

 

So, I tried this, went on Zeroy's script reference etc, but I am getting an error in my script which I don't know what is causing it.

 

Code: http://hastebin.com/aqikonunay.coffee

 

Error:

 

6d77bce4c0a221b39b865fdfdef45d27.png

0

Share this post


Link to post
Share on other sites

Hmm think I found it. Supposed to be a : instead of ; ... my bad. But I can see another error popping up so I will edit this thread if I do

 

EDIT: Updated 

0

Share this post


Link to post
Share on other sites
precache()
{
    precacheModel("ch_crate64x64");
}

box1()
{
    box = spawn("script_model", (-254 , 274 , 26));
    box setModel("ch_crate64x64");
    trigger = spawn( "trigger_radius", (-254, 274, 26), 0, 64, 64 );
    trigger.targetname = "box1";
    trigger waittill("trigger", player );
    
    weapon = randomInt(3);

    switch(weapon)
    {
    
        case 0:
            player giveWeapon(" m40a3_mp ");
            player giveMaxAmmo(" m40a3_mp ");
            player switchToWeapon(" m40a3_mp ");
        break;
            
                
        case 1:
            player giveWeapon(" ak47_mp ");
            player giveMaxAmmo(" ak47_mp ");
            player switchToWeapon( " ak47_mp ");
        break;
                
        case 2:
            player giveWeapon(" usp_mp ");
            player giveMaxAmmo(" usp_mp ");
            player switchToWeapon( " usp_mp ");
        break;
                    
    }
    
}

I think it should be something like this.

0

Share this post


Link to post
Share on other sites

Why have you done precache()?

 

Can't I do that in main() ?

 

Yes you can but i put it there so you know it ;)

 

Added some new stuff for ya ;)

precache()
{
    precacheModel("ch_crate64x64");
}

box1()
{
	box = spawn("script_model", (-254 , 274 , 26));
	box setModel("ch_crate64x64");
	trigger = spawn( "trigger_radius", (-254, 274, 26), 0, 64, 64 );
	trigger.targetname = "box1";
	
	for(;;)
	{
		trigger waittill("trigger", player );
		if ( player isTouching( trigger ) && player useButtonPressed() )
		{
			weapon = randomInt(3);

			switch(weapon)
			{
			
				case 0:
					player giveWeapon(" m40a3_mp ");
					player giveMaxAmmo(" m40a3_mp ");
					player switchToWeapon(" m40a3_mp ");
				break;
					
						
				case 1:
					player giveWeapon(" ak47_mp ");
					player giveMaxAmmo(" ak47_mp ");
					player switchToWeapon( " ak47_mp ");
				break;
						
				case 2: 
					player giveWeapon(" usp_mp ");
					player giveMaxAmmo(" usp_mp ");
					player switchToWeapon( " usp_mp ");
				break;
							
			}
		}
		else
		{
		wait 0.5;
		}
	}
}

Not sure if it works but you could use something like that ;)

0

Share this post


Link to post
Share on other sites

Psst... :ph34r: Had to wait for someone so challenge accepted  :P

 

 

It will not work on a server but it gives you the impression  :P

init()
{
    // The model used for the box.
    level.boxModel = "ch_crate64x64";
 
    // The weapons that are available from the box.
    level.boxWeapons = [];
    level.boxWeapons[level.boxWeapons.size] = "ak47_mp";
    level.boxWeapons[level.boxWeapons.size] = "m40a3_mp";
    level.boxWeapons[level.boxWeapons.size] = "usp_mp";
    
    // The origins the box may spawn at.
    level.boxOrigins = [];
    level.boxOrigins[level.boxOrigins.size] = (-254, 274, 26);
    level.boxOrigins[level.boxOrigins.size] = (-254, 786, 26);
    level.boxOrigins[level.boxOrigins.size] = (  18, 338, 26);
    level.boxOrigins[level.boxOrigins.size] = (  18, 530, 26);
    level.boxOrigins[level.boxOrigins.size] = (  18, 722, 26);
    
    preCache();
}
 
preCache()
{
    preCacheModel(level.boxModel);
    
    for (i = 0; i < level.boxWeapons.size; i++)
        preCacheItem(level.boxWeapons[i]);
}
 
gibzWeapon()
{
    weapon = level.boxWeapons[randomInt(level.boxWeapons.size)];
    player takeAllWeapons();
    player giveWeapon(weapon);
    player giveMaxAmmo(weapon);
    player switchToWeapon(weapon);
}
 
box(idx, org)
{
    box = spawn("script_model", org);
    box setModel(level.boxModel);
    
    trigger = spawn("trigger_radius", org, 0, 64, 64);
    //trigger.targetname = ("box" + idx); // Not needed...
    
    for (;;)
    {
        trigger waittill("trigger", player);
        trigger thread playerTouching(player);
    }
}
 
playerTouching(player)
{
    if (!isDefined(player.boxTouch))
        player.boxTouch = false;
    
    if (player.boxTouch)
        return;
    player.boxTouch = true;
    
    while (player isTouching(self))
    {
        if (player useButtonPressed())
        {
            player gibzWeapon();
            break;
        }
        
        wait .05;
    }
 
    player.boxTouch = false;
}
 
spawnRandomBox()
{
    idx = randomInt(level.boxOrigins.size);
    box(idx + 1, level.boxOrigins[idx]);
}
 
0

Share this post


Link to post
Share on other sites

Always having to confuse things aren't you Scillman ;)

 

He makes you do a little bit yourself so you can learn :).

0

Share this post


Link to post
Share on other sites

Always having to confuse things aren't you Scillman ;)

I think his way is less confusing :wat:

0

Share this post


Link to post
Share on other sites

He makes you do a little bit yourself so you can learn :).

I didn't realise, thank you, I thought he tried the challenge himself and posted it haha

0

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  
Followers 0