UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

How do I write a script that allows the player to collect and place models?

broken avatar :(
Created 7 years ago
by worstgabena
0 Members and 1 Guest are viewing this topic.
2,080 views
broken avatar :(
×
broken avatar :(
Location: usAnywhere but here
Date Registered: 31 October 2016
Last active: 6 years ago
Posts
32
Respect
Forum Rank
Legless Crawler
Primary Group
Member
×
worstgabena's Groups
worstgabena's Contact & Social Links
I want a script that will allow the player to find an object in game hold 'F' on it, then go to a point in the game that they can hold 'F' again and place it there, but it needs to allow the player to mix and match different objects, say there are 3 gate worms, each one can then go into any of the others' place.
Thanks
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
Signature
Let he who has not sinned cast the first stone.
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
Sounds interesting.

There exists an unspoken law in coding: Thou shall not beg for mercy if thy has not done his due diligence. Basically it is a generally accepted etiquette to educate yourself to a finger-bleeding degree in the subject of your interest before calling "write me a script plz"

The mod tools come with a folder labled docs_modtools, look in there and read the gsc help file for basic scripting guidelines. Also read the other documents when you have time, you'll learn a lot from the developers. With that being said I don't mind helping, but just remember most people will either ignore you, or scold you for not taking the basic steps to learn the ropes - reading beginner tutorials, watching youtube videos, trial & error etc. Not to be a dick or anything, I'm just trying to help you.


For each item you want to pick up, put down a script_model, and a trigger_use. Select the trigger first, then select the model, and hit W. Next select only the trigger, hit N to bring up entity_info pane, add these KVP's:

targetname - part
script_noteworthy - name_of_part's_xmodel

You can get the name of the xmodel by selecting the script_model, hit N, then copy the text from the ''model" KVP.

Make sure every pick-up trigger has the targetname - part, but a script_noteworthy value unique to the item's xmodel name for the following script to work. This way in script you can collect all pick-up triggers by the 'part' targetname, store them all in a single array variable, then sort them individually or uniquely identify them based on their script_noteworthy value, which you set to be the name of the xmodel, so this string can be stored and re-used later to spawn the model back at a different trigger.

Next, for each part you have, drop down an equal number of trigger_use brushes for the locations to place the items after the player picks them up. Give them all this KVP:
targetname - end_location

Now open your mapname.gsc and navigate to
function main() then follow the instructions below.

Code Snippet
Plaintext
function main()
{





//Add this line at the bottom in your main() function:
level thread part_setup();
}


//Then add these functions outside of, and below the main() function:
function part_setup(){
level flag::wait_till("all_players_connected");
level.part_trigs = GetEntArray("part", "targetname");
foreach(trig in level.part_trigs){ //Get an array of all triggers that have the targetname 'part'
trig.id = self.script_noteworthy;
trig.part_model = GetEnt(self.target, "targetname");
trig SetCursorHint("HINT_NOICON");
trig SetHintString("Press &&1 to pickup part");
trig thread pickup_item_logic(); //Execute a function on every trigger in that array
}
level.end_locs = GetEntArray("end_location", "targetname");
foreach(trig in level.end_locs){
trig SetCursorHint("HINT_NOICON");
trig SetHintString("Press &&1 to place part");
trig thread place_item_logic(); //EDIT* - was just 'thread place_item_logic();' fixed so 'trig' gets threaded as self, sorry I forgot that part.
}
}

function pickup_item_logic(){ //Each trigger becomes 'self' in this function
while(1){
self waittill("trigger", player);
if(!isDefined(player.has_part) || player.has_part == false){
player.has_part = true;
player.current_part = self.id;
self.part_model Delete();
self Delete();
break;
}else
wait(1);
}
}

function place_item_logic(){ //Each trigger becomes 'self' in this function
while(1){
self waittill("trigger", player);
if(isDefined(player.has_part){
new_part = Spawn("script_model", self.origin);
new_part SetModel(player.current_part);
player.current_part = undefined;
player.has_part = false;
self TriggerEnable(false);
//Add your own code where needed. This is only a basic skeleton of grabbing and placing items
}else
wait(1);
}

I would also advise you to download my custom buildables script here https://ugx-mods.com/forum/index.php/topic,15031.0.html and study the main gsc file, a lot of functions I wrote already do some of what you want. There are many other examples and addons on ugx which have helped me tremendously in learning the codscript system in general as well as mapping and other subjects. Read some of the WAW tutorials here too, the format is nearly identical as far as the scripting part. It's amazing realizing the potential of what you can do with script and a little mapping experience. Good luck.
Last Edit: April 29, 2017, 07:54:13 pm by Archaicvirus
broken avatar :(
×
broken avatar :(
Location: usAnywhere but here
Date Registered: 31 October 2016
Last active: 6 years ago
Posts
32
Respect
Forum Rank
Legless Crawler
Primary Group
Member
×
worstgabena's Groups
worstgabena's Contact & Social Links
Thanks, but once I compiled and linked, I got and error about this line:
Code Snippet
Plaintext
foreach (trig in GetEnt("end_location"))
Saying that "GetEnt" had an unresolved external.
Thanks again :)
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
Copy the functions again and replace them. The code is fixed.
Last Edit: April 05, 2017, 04:14:35 am by Archaicvirus
broken avatar :(
×
broken avatar :(
Location: usAnywhere but here
Date Registered: 31 October 2016
Last active: 6 years ago
Posts
32
Respect
Forum Rank
Legless Crawler
Primary Group
Member
×
worstgabena's Groups
worstgabena's Contact & Social Links
Gotcha, thanks.
broken avatar :(
×
broken avatar :(
Location: usSouth Florida
Date Registered: 10 July 2016
Last active: 12 months ago
Posts
106
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
×
Archaicvirus's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Archaicvirus's Contact & Social Links
Sure, glad to help. Let me know if you need more explanation.

 
Loading ...