SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 06/10/2017, 06:49 AM   #31
leon44
Huge Clucker
 
Join Date: Apr 2013
Posts: 239
Reputation: 3
Default Re: Detect player when fell at water off

Quote:
Originally Posted by frouzen View Post
Add this near the top of you script and add every boat.
PHP Code:
new boats[] = {
539446430
}; 
And change the one I gave you to this.
PHP Code:
public OnPlayerUpdate(playerid){
    new 
FloatPosXFloatPosYFloatPosZvehicle;
    
GetPlayerPos(playeridPosXPosYPosZ);
    
vehicle GetPlayerVehicleID(playerid);
    if(
PosZ 0.0){
        for(new 
ii<sizeof(boats); i++)
            if(
GetVehicleModel(vehicle) == boats[i]) return 1;
        
DestroyVehicle(vehicle);
        
SendClientMessage(playerid, -1"You are in the water");
    }
    return 
1;

Oh yeah it worked very well +REP
And ye, the problem is that the message kept spamming all the time, I mean, like an infinite loop it doesn't stop, why does it happen? I want an explication to understand and learn, if someone has a solution for that post it please
leon44 is offline   Reply With Quote
Old 06/10/2017, 07:07 AM   #32
ToiletDuck
Huge Clucker
 
ToiletDuck's Avatar
 
Join Date: Apr 2012
Location: Philippines, Lucena City
Posts: 399
Reputation: 43
Default Re: Detect player when fell at water off

Tempo fix.
PHP Code:
public OnPlayerUpdate(playerid){ 
    new 
FloatPosXFloatPosYFloatPosZvehicle
    
GetPlayerPos(playeridPosXPosYPosZ); 
    
vehicle GetPlayerVehicleID(playerid); 
    if(
PosZ 0.0){ 
        for(new 
ii<sizeof(boats); i++) 
            if(
GetVehicleModel(vehicle) == boats[i]) return 1
        if(!
GetPVarType(playerid"InWater"))
        {
             
DestroyVehicle(vehicle); 
             
SendClientMessage(playerid, -1"You are in the water");
             
SetPVarInt(playerid"InWater"1); 
        }
    } 
    return 
1

then
PHP Code:
SetPVarInt(playerid"InWater"0); // or
DeletePVarInt(playerid"InWater"); 
Use this right after the game has started again.
ToiletDuck is offline   Reply With Quote
Old 06/10/2017, 08:22 AM   #33
leon44
Huge Clucker
 
Join Date: Apr 2013
Posts: 239
Reputation: 3
Default Re: Detect player when fell at water off

Quote:
Originally Posted by ToiletDuck View Post
Tempo fix.
PHP Code:
public OnPlayerUpdate(playerid){ 
    new 
FloatPosXFloatPosYFloatPosZvehicle
    
GetPlayerPos(playeridPosXPosYPosZ); 
    
vehicle GetPlayerVehicleID(playerid); 
    if(
PosZ 0.0){ 
        for(new 
ii<sizeof(boats); i++) 
            if(
GetVehicleModel(vehicle) == boats[i]) return 1
        if(!
GetPVarType(playerid"InWater"))
        {
             
DestroyVehicle(vehicle); 
             
SendClientMessage(playerid, -1"You are in the water");
             
SetPVarInt(playerid"InWater"1); 
        }
    } 
    return 
1

then
PHP Code:
SetPVarInt(playerid"InWater"0); // or
DeletePVarInt(playerid"InWater"); 
Use this right after the game has started again.
Hi mate, I put this:
PHP Code:
SetPVarInt(playerid"InWater"0); 
in:
PHP Code:
forward StartMap(mapName[]);
public 
StartMap(mapName[])
{
    for(new 
0MAX_PLAYERSi++)
    {
    if(
IsPlayerConnected(i))
    {
    
SetPlayerPos(imapValues[pMX],mapValues[pMY],mapValues[pMZ]+3);
    
TogglePlayerControllable(ifalse);
    }
    }
    new 
string[156], mapN[256],mapN_4[156];
    
format(mapN,256,"DMRace/%s/objects.map",mapName);
    if(
LoadMap(mapN))
    {
    
format(mapN2,156,"DMRace/%s/toptimes.txt",mapName);
    
SetPVarInt(playerid"InWater"0);
    
format(ServerData[Mapname],156,"%s",mapName);
    
StartRace(5000);
    
format(mapN_4,156,"DMRace/%s/meta.xml",mapName);
    new 
XML:xml xml_open(mapN_4);
    if (
xml)
 {
        new 
buf[100];
        
xml_get_string(xml"meta/info"buf);
        
xml_get_string(xml"meta/info/@name"buf);
        
format(stringsizeof string"MAP: ~w~~h~%s"trcar(buf));
        
TextDrawSetString(MapTextstring);
        
format(ServerData[mapXML],156,"%s",buf);
        
xml_close(xml);
    }
    }
    return 
true;

This public function indicates that is starting a new map as you told me to put it right after the game has started again but got this error:
Code:
D:\Escritorio\Carpetas Personales\Server\dmserver\gamemodes\dmrace.pwn(300) : error 017: undefined symbol "playerid"
So to fix it I defined the public and forward like this:
PHP Code:
forward StartMap(playeridmapName[]);
public 
StartMap(playeridmapName[]) 
but then I got this warning:
Code:
warning 202: number of arguments does not match definition
leon44 is offline   Reply With Quote
Old 06/10/2017, 08:40 AM   #34
ToiletDuck
Huge Clucker
 
ToiletDuck's Avatar
 
Join Date: Apr 2012
Location: Philippines, Lucena City
Posts: 399
Reputation: 43
Default Re: Detect player when fell at water off

PHP Code:
forward StartMap(mapName[]); 
public 
StartMap(mapName[]) 

    for(new 
0MAX_PLAYERSi++) 
    { 
look at this one, you don't define playerid here instead you're looping players with using 'i' variable therefore you must change playerid to 'i'
PHP Code:
SetPVarInt(playerid"InWater"0); 
to
PHP Code:
SetPVarInt(i"InWater"0); 
you should put that in this code
PHP Code:
 for(new 0MAX_PLAYERSi++) 
    { 
    if(
IsPlayerConnected(i)) 
    { 
    
SetPlayerPos(imapValues[pMX],mapValues[pMY],mapValues[pMZ]+3); 
    
TogglePlayerControllable(ifalse); 
    
SetPVarInt(i"InWater"0); 
    } 
    } 
ToiletDuck is offline   Reply With Quote
Old 06/10/2017, 11:17 AM   #35
Mohaaaaaaaaaaa
Big Clucker
 
Join Date: Feb 2017
Posts: 58
Reputation: 2
Default Re: Detect player when fell at water off

Code:
stock IsPlayerInWater(playerid)
{
	new anim = GetPlayerAnimationIndex(playerid);
 	if (((anim >=  1538) && (anim <= 1542)) || (anim == 1544) || (anim == 1250) || (anim == 1062)) return 1;
  	return 0;
}
__________________
Happy to help
Mohaaaaaaaaaaa is offline   Reply With Quote
Old 06/10/2017, 02:08 PM   #36
OsmanMalagic
Little Clucker
 
Join Date: Jul 2016
Location: EX-YU
Posts: 34
Reputation: 51
Default Re: Detect player when fell at water off

PHP Code:
stock IsPlayerInWater(playerid)
{
    new 
anim GetPlayerAnimationIndex(playerid);
    if(
anim >= 1538 && anim <= 1542 || anim == 1544 || anim == 1250 || anim == 1062)
    {
        return 
1;
    }
    return 
0;
}

if(
IsPlayerInWater(playerid)) return SCM(playeridCOLOR_WHITE"You are in water!"); 
OsmanMalagic is offline   Reply With Quote
Old 06/10/2017, 09:17 PM   #37
leon44
Huge Clucker
 
Join Date: Apr 2013
Posts: 239
Reputation: 3
Default Re: Detect player when fell at water off

Quote:
Originally Posted by ToiletDuck View Post
PHP Code:
forward StartMap(mapName[]); 
public 
StartMap(mapName[]) 

    for(new 
0MAX_PLAYERSi++) 
    { 
look at this one, you don't define playerid here instead you're looping players with using 'i' variable therefore you must change playerid to 'i'
PHP Code:
SetPVarInt(playerid"InWater"0); 
to
PHP Code:
SetPVarInt(i"InWater"0); 
you should put that in this code
PHP Code:
 for(new 0MAX_PLAYERSi++) 
    { 
    if(
IsPlayerConnected(i)) 
    { 
    
SetPlayerPos(imapValues[pMX],mapValues[pMY],mapValues[pMZ]+3); 
    
TogglePlayerControllable(ifalse); 
    
SetPVarInt(i"InWater"0); 
    } 
    } 
Alright fixed that but nothing happens when I fell at water off.
leon44 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
detect vehicle is in water COL Scripting Help 5 24/01/2014 05:37 PM
Is there a way to detect if the player is in water? K9IsGodly Scripting Help 5 10/01/2014 04:21 PM
Detect if player is in under water? Admigo Scripting Help 3 14/04/2012 03:10 PM
How to detect if player's car is in water? Outcast Help Archive 2 16/01/2011 04:21 PM
Detect if player is in water? Biscottinis Help Archive 2 20/06/2010 10:47 AM


All times are GMT. The time now is 12:15 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.