ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
Scripting function

1 2 | Next 10 events »| All Messages
Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  02:32:26  30 April 2014
profilee-mailreply Message URLTo the Top
BegunValkery
Senior Resident
 

 
On forum: 02/23/2013
Messages: 221
Scripting function

I'm starting with actual scripting for the first time. The first thing I want to do is make a task from Barkeep to find a special medkit within the Bar. I looked at the Mod Portal, however I don't know what the function is to spawn the item. The tutorial said spawn_zombies, but what is the function for spawning an object?
  02:45:54  30 April 2014
profilee-mailreply Message URLTo the Top
TKGP
Senior Resident
 

 
On forum: 01/25/2013
Messages: 454
alife():create( [section name], [position], [level vertex id], [game vertex id], [object id for inventory (optional)] )
I think this is probably what you were looking at already, but if you look in one of the code blocks near the top you'll see an example of spawning a bolt at the player.
http://sdk.stalker-game.com/en/index.php?title=Spawning_through_script
  17:14:03  30 April 2014
profilee-mailreply Message URLTo the Top
BegunValkery
Senior Resident
 

 
On forum: 02/23/2013
Messages: 221

---QUOTATION---
alife():create( [section name], [position], [level vertex id], [game vertex id], [object id for inventory (optional)] )
I think this is probably what you were looking at already, but if you look in one of the code blocks near the top you'll see an example of spawning a bolt at the player.
http://sdk.stalker-game.com/en/index.php?title=Spawning_through_script
---END QUOTATION---



Yes, that I saw. It's just that I want an object that will be the target of the quest to spawn when the quest is activated. That's what I'm aiming for is for a scripted spawn to be activated when you accept the task. Not like in Call of Pripyat, the Dredge Station, for example, where you can get the altered wheel artifact before starting the quest.
  22:17:12  30 April 2014
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
Messages: 685
I think you need more info how to create a quest.
http://sdk.stalker-game.com/en/index.php?title=Quest_creation
Here is a description for quest creation.

In the action tag you need to put your spawning script when task is accepted.
  22:26:22  30 April 2014
profilee-mailreply Message URLTo the Top
BegunValkery
Senior Resident
 

 
On forum: 02/23/2013
Messages: 221
I've already added the action of my script spawn but it did absolutely nothing. The game did not crash, but the object did not spawn at the coordinates I have made.
  16:29:31  3 May 2014
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
Messages: 685
Post the code you wrote. Maybe you have a typo in the script.
  05:42:25  4 May 2014
profilee-mailreply Message URLTo the Top
BegunValkery
Senior Resident
 

 
On forum: 02/23/2013
 

Message edited by:
BegunValkery
05/04/2014 5:43:36
Messages: 221
;;;;This is my FIRST test script for a quest to find a special medkit in the Bar.


local medkit_types = {"medkit_test_1"}

function spawn_medkit ( position, total )
local medkit_index
local new_pos, x_offset, z_offset
for medkit_index=1, total do
x_offset = math.random(1)
z_offset = math.random(1)
new_pos = position
new_pos.x = new_pos.x + x_offset
new_pos.z = new_pos.z + z_offset

alife():create(medkit_types[math.random(1)], new_pos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
end
end

function medkit_test( actor, npc )
local spawn_point = vector():set(112, 4, 73)
spawn_medkit( spawn_point, 1 )
end
  15:29:01  4 May 2014
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
 

Message edited by:
ThunderFreak
05/04/2014 15:29:26
Messages: 685
See my comments in the script.

function spawn_medkit ( position, total )
	--local medkit_index			-- no need to declare the variable because the for loop declares it automatically
	local new_pos, x_offset, z_offset
	for medkit_index=1, total do
		--x_offset = math.random(1)	-- makes no sense
		--z_offset = math.random(1)
		new_pos = position
		--[[
		new_pos.x = new_pos.x + x_offset
		new_pos.z = new_pos.z + z_offset 
		--]]
		-- I would suggest to to use y especially when you stand on a slope
		-- with x or z it might be your spawn is inside of that hill
		-- let it fall from above the spawn point then the final position of the medkit is much more random
		new_pos.y = new_pos.y + 1
		
		-- medkit_types[math.random(1,#medkit_types)] : you need to make sure that the random function starts at number 1
		-- because a table starts at 1 except it is set to 0 explicitly
		-- the expression #medkit_types returns the amount of entries in a table
		alife():create(medkit_types[math.random(1,#medkit_types)], new_pos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
	end
end

  16:58:47  4 May 2014
profilee-mailreply Message URLTo the Top
BegunValkery
Senior Resident
 

 
On forum: 02/23/2013
Messages: 221

---QUOTATION---
See my comments in the script.

function spawn_medkit ( position, total )
	--local medkit_index			-- no need to declare the variable because the for loop declares it automatically
	local new_pos, x_offset, z_offset
	for medkit_index=1, total do
		--x_offset = math.random(1)	-- makes no sense
		--z_offset = math.random(1)
		new_pos = position
		--[[
		new_pos.x = new_pos.x + x_offset
		new_pos.z = new_pos.z + z_offset 
		--]]
		-- I would suggest to to use y especially when you stand on a slope
		-- with x or z it might be your spawn is inside of that hill
		-- let it fall from above the spawn point then the final position of the medkit is much more random
		new_pos.y = new_pos.y + 1
		
		-- medkit_types[math.random(1,#medkit_types)] : you need to make sure that the random function starts at number 1
		-- because a table starts at 1 except it is set to 0 explicitly
		-- the expression #medkit_types returns the amount of entries in a table
		alife():create(medkit_types[math.random(1,#medkit_types)], new_pos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
	end
end


---END QUOTATION---



Wait, hill? Do the coordinates point to a different location than I was expecting? I wanted it to spawn on top of a building in the Bar area.
  21:11:30  4 May 2014
profilee-mailreply Message URLTo the Top
rkr5
(Novice)
 
On forum: 09/05/2009
Messages: 41

---QUOTATION---
I wanted it to spawn on top of a building in the Bar area.
---END QUOTATION---



You won't be able to do that via script. There is no AI map up on Bar rooftops, anything you spawn up there will fall through the surface to the nearest AI node.
If there is no AI node underneath the item, it'll just keep falling forever and will probably lead you to some pretty nasty crashes.
 
Each word should be at least 3 characters long.
Search:    
Search conditions:    - spaces as AND    - spaces as OR   
 
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
 

All short dates are in Month-Day-Year format.


 

Copyright © 1995-2022 GSC Game World. All rights reserved.
This site is best viewed in Internet Explorer 4.xx and up and Javascript enabled. Webmaster.
Opera Software products are not supported.
If any problem concerning the site functioning under Opera Software appears apply
to Opera Software technical support service.