0 registered members (),
1,089
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Aquiring/Equipting Items
#81803
07/16/06 03:39
07/16/06 03:39
|
Joined: Sep 2005
Posts: 38
Krammit
OP
Newbie
|
OP
Newbie
Joined: Sep 2005
Posts: 38
|
Ok. So a small project im working on, is getting to the stage where advanced scripting is almost needed. I've worked out all the kinks in the main engine, so the basics are done (with the exception of enemies, enemy intelligence, etc) There are some things I've never programmed before, and that is being able to aquire an object, and then have it equippted as a weapon. What I have is this: You play as a knight, but when you start, I wanted it to not have weapons. Instead have to search the map, to get them. Basically have it so; If you come in contact with the weapon (the sword) it becomes equippted to your hand, then follows the hand during animations (moving, attacking, jumping, etc) Same as the shield, upon collision, attack itself to the left arm (not the hand) I'm wondering if theres a script capable of that? Or an example/tutorial available somewhere. (I'm guessing it would involve rotating the shield, so it hangs lenght wise on the arm not holding the sword) If it helps, all my scripts are included to the game with the Code:
include <nameoffile.wdl>; So help is definitly appriciated, seeing as it helps the overall development. And if it isnt too much trouble, my music wont play. I've worked out a script I thought would play midi files, but notihng plays during the game, but the script appears to load file, heres the script: Code:
var LoopMusic = 0;
// Plays the given MIDI file function DMusicPlay(SA2Death.mid) { LoopMusic = 0; PlayDMusic(SA2Death.mid); }
But it doesnt seem to actually start any music.. So, am I doing something wrong? o_O Thanks.
Last edited by Krammit; 07/16/06 12:39.
|
|
|
Re: Aquiring/Equipting Items
[Re: Krammit]
#81804
07/16/06 09:02
07/16/06 09:02
|
Joined: Mar 2005
Posts: 309 Germany, Bavaria
Sinthoras
Senior Member
|
Senior Member
Joined: Mar 2005
Posts: 309
Germany, Bavaria
|
I am not into music, so I'll try to fix the 'weapon' problem first At the beginning, you should think of "how many weapons / shields / overall equipment should my character be able to handle at the same time". If there's more than one weapon and one shield, the code will have either a very complex structure - or it will be just more, nearly copied code. But I assume you want to have just one / one, so lets start with that. We have to create an array, where the items found can be stored in. Code:
var equipment[4]; //0-1: weapon id and weapon handle, 2-3: shield id & handle
Then, lets say "0" is "weapon", and "1" is "shield". What to do with the last one, "2", is left to you. Save something important to it. Now, its getting more complicated. We have to create 2 event functions for the models, one for the little knight and one for the weapon/shield model. knights event: EVENT_DETECT -> my.enable_detect = on; weapons event: EVENT_SCAN -> my.enable_scan = on; The player has to scan for weapons every frame, so we've to call "c_scan" every frame, e.g. in the main loop. If the Detected-event of the player is called, we have to check if it is a weapon/shield, and we have to equip the player with the found one (if any). Code:
EVENT_DETECT called { if( you == a weapon ) { you.skill100 = 1; //to remove the weapon, check this in the weapons main loop equipment[ _weapon ] = you.skill1; //the id of the weapon/shield //thats it. you could check if there is already a weapon in the players hand, and add more info } }
Yeah, the weapon got removed from the level and "equipment" has the relevant infos about it. The next thing now: We have to check (in the player's function) if equipment[0] and [2] are set, and if they are, whether the [1] and [3] contain the entity handles. If they do not, as in our example here, we have to create a weapon/shield and set them. Code:
you = ent_create(weapon/shield); //we have to create the items by the ID given in 'equipment' equipment[ _weapon ] = handle( you ); //or equipment[ _shield ] = handle( you );
Okay, the handles exist. We can get the pointers by "ptr_for_handle( equipment [ shield ] )" We go on with the movement: if the handle exist, lets receive the pointer and move it by the players side! Code:
you = ptr_for_handle( equipment [ _weapon ] );
vec_set(temp.x, vector(0, 100, 0));//vector(0, -100, 0) for the shield vec_rotate(temp.x, player.pan); vec_add(temp.x, player.x);
vec_set(you.x, temp); vec_set(you.pan, player.pan);
Thats it. I hope the code works and my explanation was not that hard to understand Regards Sinthoras
|
|
|
Re: Aquiring/Equipting Items
[Re: Sinthoras]
#81805
07/16/06 09:18
07/16/06 09:18
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
While Sinthoras gave you a good example how to equip things, I'll give ya a function which plays your .mid file Code:
var music_handle;
string para_music;
function play_music(para_music,_loop,_volume) { if(!music_handle) { media_stop(music_handle); } if(!_loop) { music_handle = media_play(para_music,null,_volume); } else { music_handle = media_loop(para_music,null,_volume); } }
//Just call the function like this: play_music("SA2Death.mid",0,100); //Music will not be looped play_music("SA2Death.mid",1,100); //Music will be looped
NOTE: The code is not tested! Use it on your own risk
Last edited by Thunder; 07/16/06 09:19.
|
|
|
Re: Aquiring/Equipting Items
[Re: Sinthoras]
#81807
07/16/06 12:21
07/16/06 12:21
|
Joined: Sep 2005
Posts: 38
Krammit
OP
Newbie
|
OP
Newbie
Joined: Sep 2005
Posts: 38
|
Sinthoras: I'm sure the script would work; had I the knowledge to understand it. Unfortunatly, try as I might, I didn't understand the vast majority of the script, but its to be expected, seeing as I've never done anything like this, my characters always had weapons to begin with (animating was more annoying, file size was larger, etc) so thats why I went this way. I doubt it, but is there a tutorial that demonstrates weapon attachment? it might just be because reading raw code can jumble the mind, but for some reason I'm not getting the brunt of the info from it, it just seems to go over my head (I should apologize, you probably worked hard on the description :/ ) I'm still trying to get this, but a raw description doesnt seem to work, I apologize for that =/ I guess its different for the music thing, I'm already fairly familier with it, so I can test it, but this I cant even seem to get going with. If it makes a difference, all the files are input with the Code:
include <nameoffile.wdl>; inside my 'start.wdl' file
Last edited by Krammit; 07/16/06 12:39.
|
|
|
Re: Aquiring/Equipting Items
[Re: Krammit]
#81808
07/16/06 16:11
07/16/06 16:11
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
oh yeah I made a slight mistake, try this Code:
var music_handle;
string para_music;
function play_music(para_music,_loop,_volume) { if(music_handle) { media_stop(music_handle); } if(!_loop) { music_handle = media_play(para_music,null,_volume); } else { music_handle = media_loop(para_music,null,_volume); } }
|
|
|
Re: Aquiring/Equipting Items
[Re: Xarthor]
#81809
07/16/06 16:39
07/16/06 16:39
|
Joined: Mar 2005
Posts: 309 Germany, Bavaria
Sinthoras
Senior Member
|
Senior Member
Joined: Mar 2005
Posts: 309
Germany, Bavaria
|
The description didn't take that long, dont care The AUM's have an attachment script for sure, unfortunately I never read them and can't tell you where But if you don't find one there: Where is the point you're getting confused? I have explained the whole procedure, maybe it is just a little obstacle to get rid of and you understand it E.g. the event part, if you just dont think of that, it's getting less than the half way to think. We'll solve that, I'm sure. Sinthoras
|
|
|
Re: Aquiring/Equipting Items
[Re: Sinthoras]
#81810
07/16/06 17:23
07/16/06 17:23
|
Joined: Sep 2005
Posts: 38
Krammit
OP
Newbie
|
OP
Newbie
Joined: Sep 2005
Posts: 38
|
Well thats the thing, I dont even know where to start =E I'm used to the basic things, these, to me, are no where near the basic stuff. Right off the bat, I decided id save the script you made, and look it over. Kinda found myself staring at the screen This is different from any other time I've done something. When I first started, i had the basic tutorial that came with 3DGS, and for more advance things, i used AU Resources to find a tutorial.
I didnt find any tutorials on this specific subject, so I decided to ask, unfortunatly, this manner of learning a code is proving a bit more confusing =/
So to answer "Where is the point you're getting confused?" The beginning? I generally for some reason see the concept skipping over my head currently, just due to lacking of experiance I suppose.
Thunder: I used the fixed script. It loads fine, no errors show up when booting, but for some reason, still no music plays. There is a small delay at the beginning of the game that was never there, but no music played. So I know its not your script, it must just be me.
Last edited by Krammit; 07/16/06 17:25.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|