SA-MP Forums Archive
Can somebody help me? - 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: Can somebody help me? (/showthread.php?tid=283407)



Can somebody help me? - Blunt - 14.09.2011

Sorry for the title now containing any useful info but, I couldn't explain it any simpler than this,

Well I was wondering how to make a Command which would SendClientMessageToAll, But would have the players name in the Message who sent it, E.G..

Goverment: Dear Citizens of Los Santos, Los Santos Police Officer [Players name], Is now on Duty!

If you could provide a code for me It'll be hugely appreciated, Thank you


Re: Can somebody help me? - Dokins - 14.09.2011

You have to create a string like so:

pawn Код:
new string[128]; // String size is 128 as I dont know how big it will be.
format(string, sizeof(string), "Government: Dear Citizens of Los Santos Police officer %s is now ON duty.", GetName(playerid));

SendClientMessageToAll(COLOURHERE, string);
return 1;



Re: Can somebody help me? - Kush - 14.09.2011

Quote:
Originally Posted by Dokins
Посмотреть сообщение
You have to create a string like so:

pawn Код:
new string[128]; // String size is 128 as I dont know how big it will be.
format(string, sizeof(string), "Government: Dear Citizens of Los Santos Police officer %s is now ON duty.", GetName(playerid));

SendClientMessageToAll(COLOURHERE, string);
return 1;
This is a bad example. You can't assume those using this code would have 'GetName' implemented.


Re: Can somebody help me? - Blunt - 14.09.2011

Quote:
Originally Posted by Dokins
Посмотреть сообщение
You have to create a string like so:

pawn Код:
new string[128]; // String size is 128 as I dont know how big it will be.
format(string, sizeof(string), "Government: Dear Citizens of Los Santos Police officer %s is now ON duty.", GetName(playerid));

SendClientMessageToAll(COLOURHERE, string);
return 1;
All i got was these

Код:
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(873) : error 010: invalid function or declaration
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(875) : error 010: invalid function or declaration
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(876) : error 010: invalid function or declaration
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(878) : error 010: invalid function or declaration
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(881) : error 021: symbol already defined: "SendClientMessageToAll"
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(882) : error 010: invalid function or declaration
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(884) : error 010: invalid function or declaration
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(886) : error 054: unmatched closing brace ("}")
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(887) : error 010: invalid function or declaration
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(890) : error 010: invalid function or declaration
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(892) : error 054: unmatched closing brace ("}")
C:\Users\Parent\Desktop\Everything\Test Server\gamemodes\ESGDM.pwn(895) : warning 203: symbol is never used: "string"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


11 Errors.



Re: Can somebody help me? - Dokins - 14.09.2011

He didnt say. I will give him the function. Also that doesnt make it a BAD example, it just means its not complete, He needs to learn.

pawn Код:
GetNameEx(playerid) {

    new
        sz_playerName[MAX_PLAYER_NAME],
        i_pos;

    GetPlayerName(playerid, sz_playerName, MAX_PLAYER_NAME);
    while ((i_pos = strfind(sz_playerName, "_", false, i_pos)) != -1) sz_playerName[i_pos] = ' ';
    return sz_playerName;
}



Re: Can somebody help me? - Blunt - 14.09.2011

Quote:
Originally Posted by Dokins
Посмотреть сообщение
He didnt say. I will give him the function. Also that doesnt make it a BAD example, it just means its not complete, He needs to learn.

pawn Код:
GetNameEx(playerid) {

    new
        sz_playerName[MAX_PLAYER_NAME],
        i_pos;

    GetPlayerName(playerid, sz_playerName, MAX_PLAYER_NAME);
    while ((i_pos = strfind(sz_playerName, "_", false, i_pos)) != -1) sz_playerName[i_pos] = ' ';
    return sz_playerName;
}
Sorry i'm a noob with Pawno, So where do i put that code in my script?


Re: Can somebody help me? - Dokins - 14.09.2011

Below a function or command, not under any public.


Re: Can somebody help me? - scottyishere - 14.09.2011

You used GetName(playerid) function in your code and you gave him GetNameEx(playerid) which will output another error.

pawn Код:
GetName(playerid) {

    new sz_playerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, sz_playerName, MAX_PLAYER_NAME);
    return sz_playerName;
}
This code should be posted anywhere in your script outside of any function or callback. (e.g. After all '}' of a function are closed)