Page 1 of 6 123 ... LastLast
Results 1 to 10 of 59

Thread: Grenads

  1. #1

    Default Grenads

    Main:

    thread dm1ammo

    end

    dm1ammo:

    //=====================================================================\\

    level.spot[0] = ( 203 -574 0.125 )
    level.spot[1] = ( 236 -899 0.125 )
    level.spot[2] = ( 218 -71 48 )

    local.random = randomint((level.spot.size )-1)

    local.model = spawn script_model
    local.model model "models/weapons/steilhandgranate.tik"
    local.model.origin = level.spot[local.random]
    local.model.scale = 1
    local.model light 0.00 1.50 0.00 50
    local.model targetname steilhandgranate

    local.trig setsize ( -20 -20 0 ) ( 20 20 80 )
    local.trig setthread gotammo

    //=====================================================================\\

    //$ammotrigger waittill trigger//

    gotammo:

    local.player = parm.other

    if(local.player == NULL) end

    $ammotrigger waittill trigger

    wait 0.25

    if ( local.player.dmteam == "allies" )
    {
    local.player give "models/weapons/m2frag_grenade.tik"
    local.player ammo grenade 1
    wait 0.5

    local.player stufftext "say You picked 1 grenade!"
    }

    if ( local.player.dmteam == "axis" )
    {

    local.player give "models/weapons/steilhandgranate.tik"
    local.player ammo grenade 1
    wait 0.5

    local.player stufftext "say You picked 1 grenade!"

    }
    }

    $ammo delete


    end
    Last edited by Old Fox; March 25th, 2019 at 10:36 PM.

  2. #2

    Default

    You removing the wrong targetname is to be this one:

    Code:
    $steilhandgranate remove
    Last edited by DoubleKill; July 11th, 2018 at 03:19 AM.

  3. #3

    Default

    Yep, what DoubleKill said. You're not deleting the model ($ammo doesn't exist). Some points:

    I'd use quotes around the targetname.
    You don't need the 'waittill trigger' as you've already made the setthread as your gotammo function.
    There's no end to your dm1ammo function which looks messy.
    You may find referencing the entity by its targetname from the start more intuitive.

    You also have some redundancies in your code I think. For example, the only difference between the two teams is the type of grenade, so you don't need to have two sets of ammo, wait, and stufftext commands.

    Again, just to help you (included the changes I mentioned plus added some extra thoughts as comments):
    Code:
    Main:
    
    	thread dm1ammo
    
    end
    
    dm1ammo:
    //=====================================================================\\
    
    	level.spot[0] = ( 203 -574 0.125 )
    	level.spot[1] = ( 236 -899 0.125 )
    	level.spot[2] = ( 218 -71 48 )
    
    	local.random = randomint (level.spot.size) - 1
    
    	spawn script_model "targetname" "steilhandgranate"
    	
    	$steilhandgranate model "models/weapons/steilhandgranate.tik"
    	$steilhandgranate.origin = level.spot[local.random]
    	$steilhandgranate light 0.00 1.50 0.00 50
    
    	//Spawn trigger//
    	spawn trigger_use "targetname" "ammotrigger" // maybe make it a useonce?
    	
    	$ammotrigger.origin = $steilhandgranate.origin
    	$ammotrigger setsize ( -20 -20 0 ) ( 20 20 80 )
    	$ammotrigger setthread gotammo
    
    //=====================================================================\\
    end
    
    gotammo:
    
            // $ammotrigger nottriggerable // add this in if you keep it your way (grenades deleted at the end) as the new way it becomes redundant as there is already an inherent trigger delay
    
    	local.player = parm.other
    
    	if(local.player == NULL) end // would the player ever be null at this point? Plus, if it does end here then the grenades will no longer spawn... This should be different 
    
    	//moved them here as it makes it more intuitive to the player that they go immediately?? Plus, what if the player dies then the grenades delete? Seems weird having these at the end.
    	$steilhandgranate delete	
    	$ammotrigger delete //if you change it to a useonce then it deletes itself I believe.
    
    	if ( local.player.dmteam == "allies" || local.player.dmteam == "axis" ) // is this needed?
    	{
    		local.player take "models/weapons/steilhandgranate.tik" // also needs to take m2frag_grenade ?? perhaps add these inside the if statements below
    
    		wait 0.25
                    // you'll probably need to check if player is alive and exists here onwards (perhaps even if they are in their team still)
    
    		if ( local.player.dmteam == "allies" )
    		{
    			local.player give "models/weapons/m2frag_grenade.tik"	
    		}
    		else // use if-else as it has to be one or the other
    		{
    			local.player give "models/weapons/steilhandgranate.tik"
    		}
    
    		local.player ammo grenade 1	
    		wait 0.25
    		local.player stufftext "say You picked 1 grenade!"
    	}
    
    	wait 2
    
    	// does function ammo1 exist??? Should it be dm1ammo???
    	thread ammo1 // dm1ammo 
    end
    Oh, and I find using single digit integers not that effective for randomisation. I usually have to have ranges in at least double digits to help randomisation.

    Also, just a question, are spectators able to trigger this? I don't do multiplayer so don't know, but as you're checking if they are either allies or axis this suggests they can. If so, it looks like spectators can delete the grenades too.

    Edit: thanks DoubleKill for confirming they can't. So I guess the first conditional statement is unneeded?
    Last edited by 1337Smithy; July 11th, 2018 at 07:21 AM.

  4. #4

    Default

    that is a random ammo script I fix to use in one of the mods i did, it wasn't meant to spawn a grenade but an ammo box that disappeared until the wait time was over then respawn at a new location.

    $ammo delete
    $ammotrigger delete

    wait 2

    thread ammo1 // dm1ammo

  5. #5

    Default

    Ah OK, sorry, no wonder it's confusing if he's changing scripts.

  6. #6

    Default

    i ask here for only the hard things bec i know ill find my way here.
    thankx for easymeat i own you one


    After testing ...
    Code:
    Main:

    thread dm1ammo

    end

    dm1ammo:
    //=====================================================================\\

    level.spot[0] = ( 203 -574 0.125 )
    level.spot[1] = ( 236 -899 0.125 )

    //=====================================================================\\

    gotammo:

    local.player = parm.other

    if(local.player == NULL) end

    $steilhandgranate delete
    $ammotrigger delete

    if ( local.player.dmteam == "allies" || local.player.dmteam == "axis" )
    {
    local.player take "models/weapons/steilhandgranate.tik"

    wait 0.25

    if ( local.player.dmteam == "allies" )
    {
    local.player give "models/weapons/m2frag_grenade.tik"
    }
    else
    {
    local.player give "models/weapons/steilhandgranate.tik"
    }

    local.player ammo grenade 1

    local.player stufftext "say You picked a grenade!"

    }

    wait 1

    thread dm1ammo
    end
    Last edited by Old Fox; March 25th, 2019 at 10:37 PM.

  7. #7

    Default

    Hi, Old Fox. When you post can you try and put your script inside a code tag? It keeps the structure and makes it much easier to read.

    I think what is happening is the index is out of range sometimes (level.spot[-1]). I added the script to a map to test it out and got it working.

    I noticed that the grenade was solid - do you want this? The player gets stuck if it spawns where they stand. Also, I notice that it's jarring when the player has his grenades taken if he's holding them. Do you need to take them away? Or does the give command only add an item if we don't have it already? It seems fine superficially.

    Code:
    Main:
    
    	level.spot[1] = ( 203 -574 0.125 )
    	level.spot[2] = ( 236 -899 0.125 )
    /*	level.spot[3] = (  )
    	level.spot[4] = (  )
    	level.spot[5] = (  )
    	level.spot[6] = (  )
    	level.spot[7] = (  )
    	level.spot[8] = (  )
    	level.spot[9] = (  )
    	level.spot[10] = (  )
    	level.spot[11] = (  )
    	level.spot[12] = (  )
    	level.spot[13] = (  )
    	level.spot[14] = (  )
    	level.spot[15] = (  )
    */
    	level.allies_grenade = "models/weapons/m2frag_grenade.tik"
    	level.axis_grenade = "models/weapons/steilhandgranate.tik"
    
    	thread dm1ammo
    end
    
    dm1ammo:
    //=====================================================================\\
    
    	local.random = randomint (level.spot.size) + 1
    
    	iprintlnbold_noloc "*************** random spot is " local.random // take this out when you are done testing...
    
    	spawn script_model "targetname" "steilhandgranate"
    
    	$steilhandgranate model level.axis_grenade
    	$steilhandgranate.origin = level.spot[local.random]
    	$steilhandgranate light 0.00 1.50 0.00 50
    	$steilhandgranate notsolid
    
    	//Spawn trigger//
    	spawn trigger_useonce "targetname" "ammotrigger"
    
    	$ammotrigger.origin = $steilhandgranate.origin
    	$ammotrigger setsize ( -20 -20 0 ) ( 20 20 80 )
    	$ammotrigger setthread gotammo
    
    end
    //=====================================================================\\
    
    gotammo:
    
    	$steilhandgranate delete
    
    	local.player = parm.other
    	local.team = local.player.dmteam
    
    	if ( local.team == "allies" )
    	{
    		local.player give level.allies_grenade
    		local.player ammo agrenade 1
    	}
    	else
    	{
    		local.player give level.axis_grenade
    		local.player ammo grenade 1
    	}	
    	local.player stufftext "say You picked a grenade!"
    
    	wait 2
    
    	thread dm1ammo
    end
    Edit: Oh, noticed you wanted a few grenades spawned at the same time. Maybe something like this:

    Code:
    Main:
    
    	level.spot[1] = ( 203 -574 0.125 ) 	// add any number of origins here - start at 1
    	level.spot[2] = ( 210 -899 0.125 )
    	level.spot[3] = ( 200 -899 0.125 )
    	level.spot[4] = ( 190 -899 0.125 )
    	level.spot[5] = ( 180 -899 0.125 )
    	level.spot[6] = ( 170 -899 0.125 )
    	level.spot[7] = ( 160 -899 0.125 )
    	level.spot[8] = ( 150 -899 0.125 )
    	level.spot[9] = ( 140 -899 0.125 )
    	level.spot[10] = ( 130 -899 0.125 )
    	level.spot[11] = ( 120 -899 0.125 )
    	level.spot[12] = ( 110 -899 0.125 )
    	level.spot[13] = ( 100 -899 0.125 )
    	level.spot[14] = ( 90 -899 0.125 )
    	level.spot[15] = ( 80 -899 0.125 )
    
    	level.allies_grenade = "models/weapons/m2frag_grenade.tik"
    	level.axis_grenade = "models/weapons/steilhandgranate.tik"
    
    
    	thread spawn_grenades 4	// number of grenades spawned - change this number
    end
    
    spawn_grenades local.grenade_count:
    
    	for (local.i = 1; local.i <= local.grenade_count; local.i++)
    		thread dm1ammo local.i
    
    end
    
    dm1ammo local.num:
    //=====================================================================\\
    	if (local.num > level.spot.size)
    	{
    		println "*********** removing grenade spawn - not enough spots!"
    		end
    	}
    
    	while (1)
    	{
    		local.random = randomint (level.spot.size) + 1
    
    		if (level.spot_used[local.random])
    		{
    			waitframe							// spot already taken - try again
    		}
    		else
    		{
    			level.spot_used[local.random] = 1			// free spot found
    			break
    		}
    	}
    	
    	spawn script_model "targetname" ("steilhandgranate" + local.num)
    
    	local.grenade = $("steilhandgranate" + local.num)
    	local.grenade model level.axis_grenade
    	local.grenade.origin = level.spot[local.random]
    	local.grenade light 0.00 1.50 0.00 50
    	local.grenade notsolid
    
    	spawn trigger_use "targetname" ("ammotrigger"  + local.num)
    
    	local.trigger = $("ammotrigger" + local.num)
    	local.trigger.origin = local.grenade.origin
    	local.trigger setsize ( -20 -20 0 ) ( 20 20 80 )
    	local.trigger.grenade = local.grenade
    	local.trigger.id = local.num
    	local.trigger.spot_index = local.random
    	local.trigger setthread gotammo
    //=====================================================================\\
    end
    
    gotammo:
            
    	local.trigger = self
    	
    	local.num = local.trigger.id 
    	local.spot_index = local.trigger.spot_index
    
    	local.trigger.grenade delete
    	local.trigger delete
          
    	local.player = parm.other
    	local.team = local.player.dmteam
    
    	if ( local.team == "allies" )
    	{
    		local.player give level.allies_grenade
    		local.player ammo agrenade 1
    	}
    	else
    	{
    		local.player give level.axis_grenade
    		local.player ammo grenade 1
    	}	
    	local.player stufftext "say You picked a grenade!"
    
    	wait 2
    
    	level.spot_used[local.spot_index] = 0
    
    	thread dm1ammo local.num
    end
    Last edited by 1337Smithy; July 12th, 2018 at 02:02 PM.

  8. #8
    Senior Member Ancient Order's Avatar
    Join Date
    Aug 2015
    Location
    Paris, Fr.
    Posts
    256

    Default

    If you delete the nade, there's no chances it'll reappear, better use show/hide in the setthread. But you'd better just spawn a nade model and set its classname as ammoentity and set its spawndelay property, thus just walking on it would give the right model according to nationality and the model will reappear at the end of the set delay. Also if you spawn many triggers you're going to make a mess as parm.other is the last entity that triggered whatever trigger you have in the map. If you want to keep them tho, add a istouching self condition in the setthread on the player.

  9. #9

    Default

    Quote Originally Posted by Ancient Order View Post
    If you delete the nade, there's no chances it'll reappear, better use show/hide in the setthread. But you'd better just spawn a nade model and set its classname as ammoentity and set its spawndelay property, thus just walking on it would give the right model according to nationality and the model will reappear at the end of the set delay. Also if you spawn many triggers you're going to make a mess as parm.other is the last entity that triggered whatever trigger you have in the map. If you want to keep them tho, add a istouching self condition in the setthread on the player.
    The old one is removed and a new one is spawned, so they do reappear. Same with the triggers so that shouldn't be an issue. They only need to be used once and then they go. So there is only ever max 4 triggers and 4 nade models in the map at any given time.

    He wants only 4 max spawned and their positions randomised.
    Last edited by 1337Smithy; July 12th, 2018 at 12:09 PM.

  10. #10

    Default

    Smithy ...
    I think you did not understand me well

    All I want is for the bomb to disappear after it is taken


    Main:

    thread dm1ammo

    end

    dm1ammo:
    //=====================================================================\\

    thread spawn_grenades 4

    level.spot[0] = ( -194 987 48 )
    wait 1
    level.spot[1] = ( -94 987 48 )
    wait 1

    local.random = randomint (level.spot.size) - 1

    spawn script_model "targetname" "steilhandgranate"

    end

    //=====================================================================\\

    gotammo:

    local.player = parm.other

    if(local.player == NULL) end

    $steilhandgranate delete
    $ammotrigger delete

    if ( local.player.dmteam == "allies" || local.player.dmteam == "axis" )
    {
    local.player take "models/weapons/steilhandgranate.tik"

    wait 0.25

    if ( local.player.dmteam == "allies" )
    {
    local.player give "models/weapons/m2frag_grenade.tik"
    }
    else
    {
    local.player give "models/weapons/steilhandgranate.tik"
    }

    local.player ammo grenade 1

    local.player stufftext "say You picked a grenade!"

    }

    wait 1

    thread dm1ammo
    end
    Last edited by Old Fox; March 25th, 2019 at 10:39 PM. Reason: Put the code in xcode tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •