Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,306 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Aquiring/Equipting Items #81803
07/16/06 03:39
07/16/06 03:39
Joined: Sep 2005
Posts: 38
K
Krammit Offline OP
Newbie
Krammit  Offline OP
Newbie
K

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 Offline
Senior Member
Sinthoras  Offline
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 Offline
Expert
Xarthor  Offline
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: Xarthor] #81806
07/16/06 11:39
07/16/06 11:39
Joined: Sep 2005
Posts: 38
K
Krammit Offline OP
Newbie
Krammit  Offline OP
Newbie
K

Joined: Sep 2005
Posts: 38
Thunder: the music script is just going null and void, same as mine o_O
Except this time I get errors such as "unkown parameter _loop" and such
I might be using it wrong, which is a high possability, because I've never used music before.
=E

Sinthoras: thanks, I'll see if I understand what you've written, and I'll try and add it to the script, thanks.

Re: Aquiring/Equipting Items [Re: Sinthoras] #81807
07/16/06 12:21
07/16/06 12:21
Joined: Sep 2005
Posts: 38
K
Krammit Offline OP
Newbie
Krammit  Offline OP
Newbie
K

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 Offline
Expert
Xarthor  Offline
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 Offline
Senior Member
Sinthoras  Offline
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
K
Krammit Offline OP
Newbie
Krammit  Offline OP
Newbie
K

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.
Re: Aquiring/Equipting Items [Re: Krammit] #81811
07/16/06 17:38
07/16/06 17:38
Joined: Mar 2005
Posts: 309
Germany, Bavaria
Sinthoras Offline
Senior Member
Sinthoras  Offline
Senior Member

Joined: Mar 2005
Posts: 309
Germany, Bavaria
Ah, huh.. thats the point.. I made my 'tutorial' expecting you to have at least a little bit of coding experience, because you wrote
Quote:


.. advanced scripting is almost needed. I've worked out all the kinks in the main engine, so the basics are done ..




The absolute beginners here cannot do even these things, means YOU are no

What do you think - is using another tutorial better than continuing here, or should we talk a bit in ICQ? (I have a lot of work to do, so this might not be the best solution..)
Sinthoras

Re: Aquiring/Equipting Items [Re: Krammit] #81812
07/16/06 17:43
07/16/06 17:43
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
I just tested it and it doesn't work for me aswell, but I reduced it to the media_play instruction and maybe found the mistake you and I made:
Here is the quote from the manual which might lead to the root of all evil
Quote:


Name of the multimedia file. The file must exist in the game folder, it won't be found in the path or in a resource .





Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1