Page 1 of 1

player scripting, adding a 'crawl' onto to script

PostPosted: Fri Apr 25, 2008 3:01 am
by PooAs
well..
this is my main player script
which makes him walk, and jump.

Code: Select all
char*key=GetKeyState();
int spd = 5;
lay = 0;
yvelocity += gravity;
if(damage > 100)DestroyActor("Event Actor");
if(wt > 0)wt--;
else
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
    if(j == 0 && xvelocity > -spd)xvelocity--;
    if(j == 1)x -= spd;
    if(ld == 1)
    {
        ld = 0;
        af = 1;
    }
    if(af == 1)
    {
        ChangeAnimation("Event Actor", "RANDAL- pistols left walk 1", FORWARD);
        af = 0;
    }
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 1)
{
    if(j == 0 && xvelocity < spd)xvelocity++;
    if(j == 1)x += spd;
    if(ld == 0)
    {
        ld = 1;
        af = 1;
    }
    if(af == 1)
    {
        ChangeAnimation("Event Actor", "RANDAL- pistols right walk 1", FORWARD);
        af = 0;
    }
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 0)
{
    af = 1;
    if(ld == 0)ChangeAnimation("Event Actor", "RANDAL pistol left", FORWARD);
    else ChangeAnimation("Event Actor", "RANDAL pistol right", FORWARD);
}
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 1)
{
    af = 1;
    if(ld == 0)ChangeAnimation("Event Actor", "RANDAL pistol left", FORWARD);
    else ChangeAnimation("Event Actor", "RANDAL pistol right", FORWARD);
}
if(j == 1 && key[KEY_z] == 1)
{
    if(key[KEY_LEFT] == 1)xvelocity = -spd;
    if(key[KEY_RIGHT] == 1)xvelocity = spd;
    yvelocity = -(gravity * 13);
    j = 0;
 
}


..

as you can see i added a varibale "lay = 0;"
im trying to add when down is held down my actor crawls
but im having a whole heap of trouble adding it into my code.
i have already added in

keydown- down = lay = 1
keyup - down = lay = 0

any ideas?

Re: player scripting, adding a 'crawl' onto to script

PostPosted: Fri Apr 25, 2008 3:25 am
by Caaz Games
well all that script is above me but what i do is put it like this
Code: Select all
if(lay==0)
{
         //Put the walk code here
}
if(lay==1)
{
         //Put the crawl code here
}

Re: player scripting, adding a 'crawl' onto to script

PostPosted: Fri Apr 25, 2008 4:34 am
by PooAs
Thanks man
i put my script in like you said
..
Code: Select all
char*key=GetKeyState();
int spd = 5;
lay = 0;
yvelocity += gravity;
if(damage > 100)DestroyActor("Event Actor");
if(wt > 0)wt--;
else


if(lay==0)
{
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
    if(j == 0 && xvelocity > -spd)xvelocity--;
    if(j == 1)x -= spd;
    if(ld == 1)
    {
        ld = 0;
        af = 1;
    }
    if(af == 1)
    {
        ChangeAnimation("Event Actor", "RANDAL- pistols left walk 1", FORWARD);
        af = 0;
    }
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 1)
{
    if(j == 0 && xvelocity < spd)xvelocity++;
    if(j == 1)x += spd;
    if(ld == 0)
    {
        ld = 1;
        af = 1;
    }
    if(af == 1)
    {
        ChangeAnimation("Event Actor", "RANDAL- pistols right walk 1", FORWARD);
        af = 0;
    }
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 0)
{
    af = 1;
    if(ld == 0)ChangeAnimation("Event Actor", "RANDAL pistol left", FORWARD);
    else ChangeAnimation("Event Actor", "RANDAL pistol right", FORWARD);
}
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 1)
{
    af = 1;
    if(ld == 0)ChangeAnimation("Event Actor", "RANDAL pistol left", FORWARD);
    else ChangeAnimation("Event Actor", "RANDAL pistol right", FORWARD);
}
}
if(j == 1 && key[KEY_z] == 1)
{
    if(key[KEY_LEFT] == 1)xvelocity = -spd;
    if(key[KEY_RIGHT] == 1)xvelocity = spd;
    yvelocity = -(gravity * 13);
    j = 0;
}
else

if(lay==1)
{
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
    if(j == 0 && xvelocity > -spd)xvelocity--;
    if(j == 1)x -= spd;
    if(ld == 1)
    {
        ld = 0;
        af = 1;
    }
    if(af == 1)
    {
        ChangeAnimation("Event Actor", "RANDAL- pistols left walk 1", FORWARD);
        af = 0;
    }
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 1)
{
    if(j == 0 && xvelocity < spd)xvelocity++;
    if(j == 1)x += spd;
    if(ld == 0)
    {
        ld = 1;
        af = 1;
    }
    if(af == 1)
    {
        ChangeAnimation("Event Actor", "RANDAL- pistols right walk 1", FORWARD);
        af = 0;
    }
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 0)
{
    af = 1;
    if(ld == 0)ChangeAnimation("Event Actor", "RANDAL_crawling_left", FORWARD);
    else ChangeAnimation("Event Actor", "RANDAL_crawling_right", FORWARD);
}
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 1)
{
    af = 1;
    if(ld == 0)ChangeAnimation("Event Actor", "RANDAL_crawling_left", FORWARD);
    else ChangeAnimation("Event Actor", "RANDAL_crawling_right", FORWARD);
}
if(j == 1 && key[KEY_z] == 1)
{
    if(key[KEY_LEFT] == 1)xvelocity = -spd;
    if(key[KEY_RIGHT] == 1)xvelocity = spd;
    yvelocity = -(gravity * 13);
    j = 0;
 
}
}




it all works but
the lay==1 does the same as lay==0
????

Re: player scripting, adding a 'crawl' onto to script

PostPosted: Fri Apr 25, 2008 4:38 am
by Caaz Games
on keydown event it has lay=1 on it right?

== checks the thing and = makes it that way
Like this
key down>DownBttn>Script
Code: Select all
Lay=1

then it should change the action

Re: player scripting, adding a 'crawl' onto to script

PostPosted: Fri Apr 25, 2008 8:57 am
by PooAs
thanks caaz :)

Re: player scripting, adding a 'crawl' onto to script

PostPosted: Fri Apr 25, 2008 7:15 pm
by Caaz Games
no problem Image glad to help no off to my secret game Image