SA-MP Forums Archive
Little coding questions - For general minor queries 5 - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Little coding questions - For general minor queries 5 (/showthread.php?tid=30938)



Re: Little coding questions - For general minor queries 5 - Hiddos - 24.06.2010

pawn Code:
SeekName(name[])
{
new pName[MAX_PLAYER_NAME];
for(new i; i < MAX_PLAYERS; i++)
{
GetPlayerName(i,pName,sizeof(pName));
if(strfind(name,pName,true) != -1) return i;
}
return INVALID_PLAYER_ID;
}
Didn't test it, but I think it'll work.


Re: Little coding questions - For general minor queries 5 - zeli - 24.06.2010

Thank you for writing it.I have tried it, it works with full name, but it doesnt with part of name.

I have found a solution, which works, its form extreme admin:

stock ReturnPlayerID(PlayerName[]) {
for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) { new name[24]; GetPlayerName(i,name,24); if(strfind(name,PlayerName,true)!=-1) return i; }
return INVALID_PLAYER_ID;
}

How can i make that, if there are multiple users with the same "part of the name" (for example clan symbols), it returns an error message ?


Re: Little coding questions - For general minor queries 5 - zeli - 24.06.2010

Thank you, it works. I modified a bit, because it said unreachable code, so the last 2 lines are: else if(TotalPlayerByName == 1)return FinalID; return INVALID_PLAYER_ID;


Re: Little coding questions - For general minor queries 5 - Kar - 09.07.2010

public OnPlayerRequestSpawn(playerid)
{
new str[128];
format(pfile, sizeof(pfile), pfile_path, Playername(playerid));
if(dini_Exists(pfile))
{
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "--------------------------------------------");
SendMsg(playerid, BRIGHTRED, "*SERVER: THIS NAME IS REGISTERD PLEASE LOGIN /LOGIN [PASSWORD]");
format(str, sizeof(str),"", Playername(playerid));
SendMsg(playerid, YELLOW, "*SERVER: Registered Username:%s ");
SendClientMessage(playerid, BRIGHTRED, "--------------------------------------------");
}
else
{
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "--------------------------------------------");
format(str, sizeof(str),"", Playername(playerid));
SendMsg(playerid, BRIGHTRED, "*SERVER: You Are Not Registered Please Register Using /Register [PASSWORD]!");
SendClientMessage(playerid, BRIGHTRED, "--------------------------------------------");
return 0;
}

i just want it to be if the person isnt registered

no function like dini_doesnot_exist<.<?


Re: Little coding questions - For general minor queries 5 - bigcomfycouch - 09.07.2010

pawn Code:
public OnPlayerRequestSpawn(playerid)
{
    new str[128];
    format(pfile, sizeof(pfile), pfile_path, Playername(playerid));
    if(!dini_Exists(pfile))
    {
        SendClientMessage(playerid, BRIGHTRED, "");
        SendClientMessage(playerid, BRIGHTRED, "");
        SendClientMessage(playerid, BRIGHTRED, "");
        SendClientMessage(playerid, BRIGHTRED, "--------------------------------------------");
        format(str, sizeof(str),"", Playername(playerid));
        SendMsg(playerid, BRIGHTRED, "*SERVER: You Are Not Registered Please Register Using /Register [PASSWORD]!");
        SendClientMessage(playerid, BRIGHTRED, "--------------------------------------------");
        return 0;
    }
    return 1;
}



Re: Little coding questions - For general minor queries 5 - Kar - 09.07.2010

this crashes the server when i try to spawn.

btw how did you get your thing into a pawn code? idk how with the new forum

public OnPlayerRequestSpawn(playerid)
{
new str[128];
format(pfile, sizeof(pfile), pfile_path, Playername(playerid));
if(!dini_Exists(pfile))
{
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "--------------------------------------------");
format(str, sizeof(str),"", Playername(playerid));
SendMsg(playerid, BRIGHTRED, "*SERVER: You Are Not Registered Please Register Using /Register [PASSWORD]!");
SendClientMessage(playerid, BRIGHTRED, "--------------------------------------------");
return 0;
}
if(IsLogged[playerid] == 0)
{
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "");
SendClientMessage(playerid, BRIGHTRED, "--------------------------------------------");
SendMsg(playerid, BRIGHTRED, "*SERVER: THIS NAME IS REGISTERD PLEASE LOGIN /LOGIN [PASSWORD]");
format(str, sizeof(str),"", Playername(playerid));
SendMsg(playerid, YELLOW, "*SERVER: Registered Username:%s ");
SendClientMessage(playerid, BRIGHTRED, "--------------------------------------------");
return 0;
}
return 1;
}


Re: Little coding questions - For general minor queries 5 - KingHual - 12.07.2010

Hey how can I put a limit so that in one team only one player can spawn but in the other teams more than 1 people can spawn ?


Re: Little coding questions - For general minor queries 5 - Finn - 12.07.2010

Quote:
Originally Posted by [XST]O_x
View Post
I have a question.
If I'd do:
pawn Code:
new Float:ax,Float:ay,Float:az,id; GetPlayerPos(id,ax,ay,az);
    //arrest command continues from here..

    if(IsPlayerInRangeOfPoint(playerid,10,ax,ay,az);
Or:
pawn Code:
if(GetDistanceBetweenPlayers(playerid,id) == 10)
Will it affect the same?
No it won't. The first code checks if the player is within 10.0 float radius to another player (well, to a point, but the point is set to another player's coordinates) and the second one checks if the player is EXACTLY 10.0 floats away from another player.

These are the same:
pawn Code:
if(IsPlayerInRangeOfPoint(playerid, 10.0, x, y, z))
if(GetDistanceBetweenPlayers(playerid, id) <= 10.0)
If you had typo in your code, sorry for being a smart ass.


Re: Little coding questions - For general minor queries 5 - spedico - 13.07.2010

nevermind


Re: Little coding questions - For general minor queries 5 - [XST]O_x - 13.07.2010

Quote:
Originally Posted by Finn
View Post
Bla
Oh okay =P

The responses were kind of late so I used GetDistanceBetweenPlayers anyway ^_^

Thanks though,it's always good to know new things.


Re: Little coding questions - For general minor queries 5 - KingHual - 13.07.2010

Hey how can I put a limit so that in one team only one player can spawn but in the other teams more than 1 people can spawn ?


Re: Little coding questions - For general minor queries 5 - zeli - 13.07.2010

I am looking for a code, which converts a number like this:

12000 -> 12 000 or 12.000
(if the number is bigger, then like this: 123456789 -> 123.456.789)


Re: Little coding questions - For general minor queries 5 - Zezombia - 13.07.2010

Zeli; there is probably a more efficient way of doing this but this is what I came up with:

pawn Code:
ConvertNumber(number)
{
    new num[16], count;
    valstr(num, number);
   
    for(new i = strlen(num); i > 0; i--)
    {
        if(count == 3)
        {
            count = 0;
            strins(num, ".",  i);
        }

        count++;
    }
   
    return num;
}



Re: Little coding questions - For general minor queries 5 - zeli - 14.07.2010

I tried it, it works fine.
Thank you very much for your help!! Very useful stuff for me.


Re: Little coding questions - For general minor queries 5 - Vince - 16.07.2010

I have a slight problem here.

pawn Code:
SetPlayerWantedLevel(playerid, floatround(level/2, floatround_ceil));
When I input 'level' as being 5, it rounds to 2 and not to 3 which is supposed to be.
Or am I missing something here?


Re: Little coding questions - For general minor queries 5 - michael2572 - 17.07.2010

Quote:
Originally Posted by Vince
View Post
I have a slight problem here.

pawn Code:
SetPlayerWantedLevel(playerid, floatround(level/2, floatround_ceil));
When I input 'level' as being 5, it rounds to 2 and not to 3 which is supposed to be.
Or am I missing something here?
Int/Int = Int

So,
5/2 = 2
Ceiling of 2 = 2.

You need to perform the division using floats, try this:
SetPlayerWantedLevel(playerid, floatround(floatval(level)/2.0, floatround_ceil));

(Make sure floatval's the right function, I can't remember the exact name but I'm pretty sure that's the one that returns a float from an int)


Re: Little coding questions - For general minor queries 5 - »Wоllstah™« - 28.10.2010

you stole it from here right? ^

you cant make code knowing you dont have the includes..

anyway,

download dutils from dracoblue.net

and put it in pawno>includes folder, then recompile


Re: Little coding questions - For general minor queries 5 - karakana7 - 28.10.2010

Quote:
Originally Posted by »Wоllstah™«
View Post
you stole it from here right? ^

you cant make code knowing you dont have the includes..

anyway,

download dutils from dracoblue.net

and put it in pawno>includes folder, then recompile
So I downloaded it from dracoblue.net and now I have error:
Code:
C:\Documents and Settings\Justas\Desktop\samp\pawno\include\dudb.inc(26) : fatal error 100: cannot read from file: "dini"

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.



Re: Little coding questions - For general minor queries 5 - »Wоllstah™« - 28.10.2010

download dini too, from the same website


Re: Little coding questions - For general minor queries 5 - Luis- - 28.10.2010

You need to include dutils or get the dutils.inc