can someone explain this?
#1

i made a command the give players money when type but it doesn't add to my cash well sorry for my bad English this image will tell you what my problem is and as for me being a beginner trying to learn how to script i will very thankful whoever can explain why it isn't work and what should i do to make this work without changing much


this is my command i made
Код:
CMD:givemoney(playerid, params[])
{
	new playerb, amount;
	if(sscanf(params,"ui",playerb,amount)) return SendClientMessage(playerid,lblue, "USAGE: /givemoney [playerid][amount]");
    if(!IsPlayerConnected(playerb)) return SendClientMessage(playerid,gray, "Invalid player id.");
	GiveDrichMoney(playerb, amount);
   	return 1;
}
this is my stock code for that
Код:
stock GiveDrichMoney(playerid, amount)
{
	new string[128];
	if(amount < 0) format(string, sizeof(string), "~r~-$%d", amount*-1);
	else if(amount > 0) format(string, sizeof(string), "~g~+$%d", amount);
	GameTextForPlayer(playerid, string, 3000, 1);
	PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
	pdata[playerid][pcash] += amount;
	return 1;
}
as youve noticed i used stock for a command and i know as for beginner it isnt necessary but for me its a great way to learn and know how things work...i only rip this code from other gamemode from that gamemode it works properly but i cant figure out why it isnt working for my script so ive come here to search some help
Reply
#2

Код:
dcmd_givecash(playerid, params[])
{
    new pID, value;
    if(sscanf(params, "ui", pID, value)) return SendClientMessage(playerid, COLOR_GREY, "USAGE : /givecash [playerid/Part of name] [amount]");
	if(pID == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Error : Invalid ID");
    if(value > GetPlayerMoney(playerid)) return SendClientMessage(playerid, -1, "You Dont Have That Much Cash");
    if(pID == playerid) return SendClientMessage(playerid, -1, "That's You, You IDIOT");
    if(value<0) return 0;
    if(GetPlayerScore(playerid) == 0 && value >500) return SendClientMessage(playerid, -1, "No more cash than $500");
    if(GetPlayerScore(playerid) == 1 && value >750) return SendClientMessage(playerid, -1, "No more cash than $750");
	if(GetPlayerScore(playerid) == 2 && value >1500) return SendClientMessage(playerid, -1, "No more cash than $1500");
    if(GetPlayerScore(playerid) == 3 && value >5000) return SendClientMessage(playerid, -1, "No more cash than $5000");
    if(GetPlayerScore(playerid) == 4 && value >7500) return SendClientMessage(playerid, -1, "No more cash than $7500");
    if(GetPlayerScore(playerid) == 5 && value >10000) return SendClientMessage(playerid, -1, "No more cash than $10000");
    if(GetPlayerScore(playerid) == 6 && value >20000) return SendClientMessage(playerid, -1, "No more cash than $20000");
	new pName[MAX_PLAYER_NAME], tName[MAX_PLAYER_NAME], string[128];
 	GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  	GetPlayerName(pID, tName, MAX_PLAYER_NAME);
    format(string, sizeof(string), "You transfered $%i to %s (%i)", value, tName, pID);
    SendClientMessage(playerid, -1, string);
    format(string, sizeof(string), "You got $%i by %s (%i)", value, pName, playerid);
    SendClientMessage(pID, -1, string);
    GivePlayerMoney(pID, value);
    GivePlayerMoney(playerid, - value);
    return 1;
}
Somthing like this maybe?
Reply
#3

pawn Код:
stock GiveDrichMoney(playerid, amount)
{
    new string[128];
    if(amount < 0) format(string, sizeof(string), "~r~-$%d", amount*-1);
    else if(amount > 0) format(string, sizeof(string), "~g~+$%d", amount);
    GameTextForPlayer(playerid, string, 3000, 1);
    PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
    pdata[playerid][pcash] += amount;
    // ??
    return 1;
}
How do you except the system gives your money if you don't use GivePlayerMoney function?
This should work!
pawn Код:
stock GiveDrichMoney(playerid, amount)
{
    new string[128];
    if(amount < 0) format(string, sizeof(string), "~r~-$%d", amount*-1);
    else if(amount > 0) format(string, sizeof(string), "~g~+$%d", amount);
    GameTextForPlayer(playerid, string, 3000, 1);
    PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
    pdata[playerid][pcash] += amount;
    ResetPlayerMoney(playerid);
    GivePlayerMoney(playerid, pdata[playerid][pcash]);
    return 1;
}
Reply
#4

Well the code you posted does work because it shows you the textdraw with the correct information but GiveDrichMoney is in no way connected to GivePlayerMoney which is why the money bar does not update. What Zeus said above will work.
Reply
#5

BTW +rep for all of you

ok ok now i get it ....another question comes in my mind why the gamemode wher i rip that exact code i post works...

does he makes a variables defines or declares? coz that gamemode makes me curious that it works for it so its possible to figure it out

this proves that
Reply
#6

I didn't quite understand you. Are you talking about the date/time textdraw?
Reply
#7

the second images show that the code works on the gamemode where i rip that code
Reply
#8

I do not still understand what exactly you want to do. Are you talking about the message "Administrator Drich Logan has set your money to $amount" and "AdmWarn: Drich Logan has given Drich Logan $amount."? Explain me, please.
Reply
#9

see the first image i type /givemoney and a textdraw appear but it did not add cash....the second image i type /givemoney and a textdraw appear and it add cash... the code the i post at the start is the code use in the second image its from zgaming GM...and i rip that code for my script and it didnt work take note thats the same code i only delete those uncessary things will not affect the code and i change also Playerinfo[playerid][pMoney] to pdata[playerid][pcash] to fit to my enum variables
Reply
#10

Just remake a givecash command format a string

GameTextForPlayer(reciever,string,time,font);


^ ignore that :P i forgot to press send
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)