Author Topic: Buying and selling.  (Read 1679 times)

Code: [Select]
function servercmdSell(%this, %name, %item, %amount){
if(!isObject(%this.player))
return;
%tool = 0;
while(%tool <= 4){
if(firstWord(%this.player.tool[%tool].uiName) $= %item){
for(%i=0;%i<ClientGroup.getCount();%i++){
%cl = ClientGroup.getObject(%i);
if(strstr(strlwr(%cl.name),strlwr(%name)) != -1){
%Customer = %cl;
messageclient(%Customer,"", "\c0" @ %this.name @ " \c6wants to sell you their \c0" @ %item @ "\c6 for " @ $currency @ "\c0" @ %amount @ "\c6.");
messageclient(%Customer,"","\c6Please type /buy yes " @ %this.name @ %item @ "if you'd like to buy it.");
%client.saleItem = %item;
%client.saleItemPrice = %amount;
}
}
}
%tool++;
}
}

function serverCmdBuy(%client, %yesNo, %name, %item){
if(%yesNo $= "yes"){
for(%i=0;%i<ClientGroup.getCount();%i++){
%cl = ClientGroup.getObject(%i);
if(strstr(strlwr(%cl.name),strlwr(%name)) != -1){
if(%cl.saleItem $= %item && %client.cash >= %cl.saleItem.price){
for(%tool=0; %tool<5; %tool++){
if(firstWord(%cl.player.tool[%tool].uiName) $= %item){
%client.cash = %client.cash-%cl.saleItemPrice;
%cl.cash = %cl.cash+%cl.saleItemPrice;
%cl.player.tool[%tool] = nametoID(firstWord(%item));
messageClient(%client, 'MsgItemPickup', '', %tool, nametoID(firstWord(%item)));
%cl.player.tool[%tool] = nametoID();
messageClient(%cl, 'MsgItemPickup', '', %tool, nametoID());
%cl.saleItem = " ";
%cl.saleItemPrice = " ";
}
}
}
}
}
}
}

Yeah, it's not working and i dunno why.

Can you give a more detailed account of where and how it's failing?

/sell works but then nothing's happening with /buy.

My guess is that %yesNo !$= "yes".

Why would that be causing the problem?

Code: [Select]
if(strlwr(%yesNo) $= "yes")Just in case they go like "YES" or "Yes" or something.
« Last Edit: September 04, 2007, 06:21:26 AM by The Prophet »

I've used that method many-a times.


It doesn't matter, copy and paste this into the console:

Code: [Select]
%yesNo = "yes"; if(%yesNo $= "YES"){ echo("YES YES YES YES"); }

that's not the point, I was suggesting you weren't typing in "yes" at all.

ANYWAY, the easiest way to see what happens is to stick echo("1"); echo("2"); etc. before and after all significant sections of the code in question. When you see it echo 1-4 but not 5, you know the problem is between echoes 4 and 5.

Yep, that's sorta like what I do, but I try to make it more like a random thing some other command couldn't f up...I dunno why, but I also sometimes do like:
Code: [Select]
function something(%whatever) {
%d = -1;
echo(%d++);
if(strlwr(%whatever) $= "something") {
echo(d++);
$whatever = %whatever;
return;
}
echo(%d++);
}
:D

Ok i think I've fixed it I just need a second person to join my server so I can test it properly, the problem was:

Code: [Select]
%cl.saleItem $= %item
Ok now it's saying  ::nametoId wrong number of arguments:

It's now getting stuck here

Code: [Select]
if(firstWord(%cl.player.tool[%tool].uiName) $= %cl.saleItem){
and i dunno why.
« Last Edit: September 07, 2007, 11:55:27 AM by MrPickel »

In aloshi's rpg, you had to add a line of code in every weapon and item.

I don't need to it's running of there item name.