Restrict /skin when player on groud

Started by Nihongo^, Jul 26, 2023, 06:37 PM

Previous topic - Next topic

Nihongo^

How do i restrict /skin when player fall down (player on ground after getting hit with weapon ) ?

Most of players in my server do evade with /skin <id>. It immediately change the skin and player get up on exact moment

i made this one but it works only for 1 second and after that player can use skin ( it take around 4/5 seconds for the player to get up properly and run )
if (cmd == "skin") {
        if (player.Action == 42) {
            MessagePlayer("You cannot use /skin while on the ground.", player);
            return;
        }
}

habi

#1
function onPlayerActionChange(player, oldaction, newaction){
If(newaction == 42){
player.IsFallen=true;
NewTimer("SetAlright", 5000,1,player.ID);
}
}

function SetAlright(playerId){
local player=FindPlayer(playerId);
if(player)

  if(GetTickCount() - player.TimeFallen > 4900000)//in milliseconds and taking account of precision error possible in timer.
  player.IsFallen = false;
}else
  FallenPlayers[playerId] = false;
}

function onScriptLoad(){
CPlayer.__getTable.IsFallen<-function (){ return ::FallenPlayers[this.ID] }
CPlayer.__getTable.TimeFallen<-function (){ return ::TimeFallen[this.ID] }
CPlayer.__setTable.IsFallen<-function (state){ ::FallenPlayers[this.ID]= state;
if(state)::TimeFallen[this.ID]=::GetTickCount();
}
FallenPlayers<-array(GetMaxPlayers(),  false);
TimeFallen<- array(GetTickCount(), 0 );
}

if (cmd == "skin") {
        if (player.IsFallen == true) {
          //Your message
           MessagePlayer("You cannot use /skin while on the ground.", player);
            return;
        }
}

Nihongo^

#2
Thanks habi, but i have question

why do we put all this funnctions in onScriptLoad?. When we can simple put the timer when player fall

function onScriptLoad(){
CPlayer.__getTable.IsFallen<-function (){ return ::FallenPlayers[this.ID] }
CPlayer.__getTable.TimeFallen<-function (){ return ::TimeFallen[this.ID] }
CPlayer.__setTable.IsFallen<-function (state){ ::FallenPlayers[this.ID]= state;
if(state)::TimeFallen[this.ID]=::GetTickCount();
}
FallenPlayers<-array(GetMaxPlayers(),  false);
TimeFallen<- array(GetTickCount(), 0 );
}
and isn't we can use

FallenPlayers = false; In Playerclass instead of 
FallenPlayers<-array(GetMaxPlayers(),  false);

and i am confused with this
if(GetTickCount() - player.TimeFallen > 4900000)Why do we need gettick count etc when there's a timer


habi

#3
We use tickcount because of 5 second timer.
What does timer do?
Sets player.IsFallen = false

Why use tickcount?
I don't know if it is possible, but for whatever reasons player fall and rise in 4 seconds and again fall.

If you think this situation, then there will be a loophole in the code. To avoid that, i used tickcount to determine when exactly does he fall down before setting his state to it

I think it is okay to place the code outside onScriptLoad. One problem was that slots cannot be added to CPlayer class once it is initialized, but slots are added to __getTable member of CPlayer class and not to CPlayer class. So that problem is solved.

Also,
Quote from: Nihongo^ on Jul 27, 2023, 06:49 AMand isn't we can use

FallenPlayers = false; In Playerclass instead of 
FallenPlayers<-array(GetMaxPlayers(),  false)
No, because it is an sqrat class.

Nihongo^

Thanks for reply, just one thing server run fine in windows but at Linux server not load its not gives any error
but it stop loading after adding this


CPlayer.__getTable.IsFallen<-function (){ return ::FallenPlayers[this.ID] }
CPlayer.__getTable.TimeFallen<-function (){ return ::TimeFallen[this.ID] }
CPlayer.__setTable.IsFallen<-function (state){ ::FallenPlayers[this.ID]= state;
if(state)::TimeFallen[this.ID]=::GetTickCount();
}

habi

#5
function SetAlright(playerId){
local player=FindPlayer(playerId);
if(player)
{
  if(GetTickCount() - player.TimeFallen > 4900000)//in milliseconds and taking account of precision error possible in timer.
  player.IsFallen = false;
}else
 FallenPlayers[playerId] = false;
}
}
Sorry i missed a brace '}'

Nihongo^

#6
No no its not about the bracket

server not load when i put this line
CPlayer.__getTable.IsFallen<-function (){ return ::FallenPlayers[this.ID] }
CPlayer.__getTable.TimeFallen<-function (){ return ::TimeFallen[this.ID] }
CPlayer.__setTable.IsFallen<-function (state){ ::FallenPlayers[this.ID]= state;
if(state)::TimeFallen[this.ID]=::GetTickCount();
}



P.S i even tried with the bracket but still the same problem

habi

Forget the bracket, it was correct.
But change
If(newaction == 42){to
if(newaction == 42){the 'I' was capital letter.

It is tested and working for me.

Diego^

Quote from: Nihongo^ on Jul 26, 2023, 06:37 PMHow do i restrict /skin when player fall down (player on ground after getting hit with weapon ) ?

Most of players in my server do evade with /skin <id>. It immediately change the skin and player get up on exact moment

i made this one but it works only for 1 second and after that player can use skin ( it take around 4/5 seconds for the player to get up properly and run )
if (cmd == "skin") {
        if (player.Action == 42) {
            MessagePlayer("You cannot use /skin while on the ground.", player);
            return;
        }
}


if (cmd == "skin") {
        if (player.Action == 42 || player.Action == 43) {
            MessagePlayer("You cannot use /skin while on the ground.", player);
            return;
        }
}

Simple ;)
BRL's Developer.

habi

Quote from: Diego^ on Aug 06, 2023, 02:12 AMif (cmd == "skin") {
        if (player.Action == 42 || player.Action == 43) {
            MessagePlayer("You cannot use /skin while on the ground.", player);
            return;
        }
}

Simple ;)
hmm that is correct

2b2ttianxiu

if(GetTickCount() - player.TimeFallen > 4900000)//in milliseconds and taking account of precision error possible in timer.
4900000 -> 81 minutes??? r u kidd me?

habi

4900000 = lol, my mistake it must be 4900.