Author Topic: Using variables with players  (Read 2213 times)

Didn't really know how to word the subject without it being really long, so.

I am still really new to this stuff, and I wanna start with some simple if's and variables, I want it so that it checks if a player is connected, if they are then it sends an echo to the chat, I would like for it to be anonymous (do this with any player) but first I am gonna start with a specific, based on what I know I think this looks possibly correct:

Code: [Select]
if(%obj.client.Miga){
          echo("HEY MIGA!");
};

Please help me on this.

I dont know the thing for when people joins but echo only shows up in the consol. If you want it to show up in the chat hud messageall('','Blah'); would message everyone and messageclient(%obj.client,",'blah'); would message the client. Aksi it wouldnt be if(%obj.client.Miga); it would be if(%obj.client.name $="Miga"){} because Miga is a string i think.
« Last Edit: June 24, 2007, 08:17:12 AM by MrPickel »

Player connection isn't a variables, it's a function, and that function is:

function GameConnection::OnClientEnterGame(%this)
{
echo("Lol, hai");
Parent::OnClientEnterGame(%this);
}

But, a problem, as that echo is a client command, it will be directed to whoever is running the code, which would be you. The host, you would have to send the command to the client, with commandToClient, although i don't know if you can do that with echo, but echo is boring anyway.

commandToClient(%this,'messageBoxOk',"lol","hai u just spawned lol");

So if you put that instead of the echo("Lol, hai"); bit, you get that message when you join. The parent::blah bit just runs the rest of the function.

I dunno if this'll work as i cant test.

Code: [Select]
function GameConnection::OnClientEnterGame(%this){
if(%this.client.name $='MrPickle'){
messageall('messagesent','Hello MrPickle');
Parent::OnClientEnterGame(%this);
} else {
Parent::OnClientEnterGame(%this);
}
}

I dunno if this'll work as i cant test.

Code: [Select]
function GameConnection::OnClientEnterGame(%this){
if(%this.name $='MrPickle')
messageall('messagesent','Hello MrPickle');
Parent::OnClientEnterGame(%this);
}
}

%this is the same as %client, just a different variable for it, so it's %this.name, not %this.client.name.

The else statement was unnecessary, didn't actually do anything wrong with it, but it wasn't needed. There's only one statement after the if, so you don't need brackets.

I don't know if the messageAll bit is correct, but let's just say it is.


It kept giving me a syntax error until i put messagesent into it.

messageall('',"Hello MrPickle");

Try that. Single quotes are used differently than double quotes, see the PM I sent.

Thats what i had. And it was giving a syntax until i changed to messagesent. Oh wait. i Put " (speech mark) and not ''(single quotes)